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
21import sys
32import copy
43import json
54import shutil
65import pathlib
7- import tempfile
86import textwrap
97import functools
108import contextlib
2725
2826
2927@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 )
5334
5435
5536@contextlib .contextmanager
@@ -70,7 +51,7 @@ def setUp(self):
7051class SiteDir (Fixtures ):
7152 def setUp (self ):
7253 super ().setUp ()
73- self .site_dir = self .fixtures .enter_context (tempdir ())
54+ self .site_dir = self .fixtures .enter_context (tmp_path ())
7455
7556
7657class OnSysPath (Fixtures ):
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ def test_entry_points_unique_packages_normalized(self):
109109 Entry points should only be exposed for the first package
110110 on sys.path with a given name (even when normalized).
111111 """
112- alt_site_dir = self .fixtures .enter_context (fixtures .tempdir ())
112+ alt_site_dir = self .fixtures .enter_context (fixtures .tmp_path ())
113113 self .fixtures .enter_context (self .add_sys_path (alt_site_dir ))
114114 alt_pkg = {
115115 "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):
138138 fixtures .build_files (self .make_pkg ('abc' ), self .site_dir )
139139 before = list (_unique (distributions ()))
140140
141- alt_site_dir = self .fixtures .enter_context (fixtures .tempdir ())
141+ alt_site_dir = self .fixtures .enter_context (fixtures .tmp_path ())
142142 self .fixtures .enter_context (self .add_sys_path (alt_site_dir ))
143143 fixtures .build_files (self .make_pkg ('ABC' ), alt_site_dir )
144144 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