File tree Expand file tree Collapse file tree 4 files changed +11
-28
lines changed
Lib/test/test_importlib/metadata Expand file tree Collapse file tree 4 files changed +11
-28
lines changed Original file line number Diff line number Diff line change 1
- import os
2
1
import sys
3
2
import copy
4
3
import json
5
4
import shutil
6
5
import pathlib
7
- import tempfile
8
6
import textwrap
9
7
import functools
10
8
import contextlib
27
25
28
26
29
27
@contextlib .contextmanager
30
- def tempdir ():
31
- tmpdir = tempfile .mkdtemp ()
32
- try :
33
- yield pathlib .Path (tmpdir )
34
- finally :
35
- shutil .rmtree (tmpdir )
36
-
37
-
38
- @contextlib .contextmanager
39
- def save_cwd ():
40
- orig = os .getcwd ()
41
- try :
42
- yield
43
- finally :
44
- os .chdir (orig )
45
-
46
-
47
- @contextlib .contextmanager
48
- def tempdir_as_cwd ():
49
- with tempdir () as tmp :
50
- with save_cwd ():
51
- os .chdir (str (tmp ))
52
- yield tmp
28
+ def tmp_path ():
29
+ """
30
+ Like os_helper.temp_dir, but yields a pathlib.Path.
31
+ """
32
+ with os_helper .temp_dir () as path :
33
+ yield pathlib .Path (path )
53
34
54
35
55
36
@contextlib .contextmanager
@@ -70,7 +51,7 @@ def setUp(self):
70
51
class SiteDir (Fixtures ):
71
52
def setUp (self ):
72
53
super ().setUp ()
73
- self .site_dir = self .fixtures .enter_context (tempdir ())
54
+ self .site_dir = self .fixtures .enter_context (tmp_path ())
74
55
75
56
76
57
class OnSysPath (Fixtures ):
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ def test_entry_points_unique_packages_normalized(self):
109
109
Entry points should only be exposed for the first package
110
110
on sys.path with a given name (even when normalized).
111
111
"""
112
- alt_site_dir = self .fixtures .enter_context (fixtures .tempdir ())
112
+ alt_site_dir = self .fixtures .enter_context (fixtures .tmp_path ())
113
113
self .fixtures .enter_context (self .add_sys_path (alt_site_dir ))
114
114
alt_pkg = {
115
115
"DistInfo_pkg-1.1.0.dist-info" : {
Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ def test_unique_distributions(self):
138
138
fixtures .build_files (self .make_pkg ('abc' ), self .site_dir )
139
139
before = list (_unique (distributions ()))
140
140
141
- alt_site_dir = self .fixtures .enter_context (fixtures .tempdir ())
141
+ alt_site_dir = self .fixtures .enter_context (fixtures .tmp_path ())
142
142
self .fixtures .enter_context (self .add_sys_path (alt_site_dir ))
143
143
fixtures .build_files (self .make_pkg ('ABC' ), alt_site_dir )
144
144
after = list (_unique (distributions ()))
Original file line number Diff line number Diff line change
1
+ Cleaned up fixtures for importlib.metadata tests and consolidated behavior
2
+ with 'test.support.os_helper'.
You can’t perform that action at this time.
0 commit comments