Skip to content

Commit 963f643

Browse files
committed
gh-120801: Update fixtures.
Removed unused fixtures relating to cwd. Rely on os_helper.temp_dir where relevant. Renamed to tmp_path to reflect pathlib behavior.
1 parent 5eee2ff commit 963f643

File tree

5 files changed

+11
-29
lines changed

5 files changed

+11
-29
lines changed

newsfragments/+76d2542b.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updated fixtures for python/cpython#120801.

tests/compat/py39.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
os_helper = try_import('os_helper') or from_test_support(
5-
'FS_NONASCII', 'skip_unless_symlink'
5+
'FS_NONASCII', 'skip_unless_symlink', 'temp_dir'
66
)
77
import_helper = try_import('import_helper') or from_test_support(
88
'modules_setup', 'modules_cleanup'

tests/fixtures.py

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import os
21
import sys
32
import copy
43
import json
54
import shutil
65
import pathlib
7-
import tempfile
86
import textwrap
97
import functools
108
import contextlib
@@ -26,29 +24,12 @@
2624

2725

2826
@contextlib.contextmanager
29-
def tempdir():
30-
tmpdir = tempfile.mkdtemp()
31-
try:
32-
yield pathlib.Path(tmpdir)
33-
finally:
34-
shutil.rmtree(tmpdir)
35-
36-
37-
@contextlib.contextmanager
38-
def save_cwd():
39-
orig = os.getcwd()
40-
try:
41-
yield
42-
finally:
43-
os.chdir(orig)
44-
45-
46-
@contextlib.contextmanager
47-
def tempdir_as_cwd():
48-
with tempdir() as tmp:
49-
with save_cwd():
50-
os.chdir(str(tmp))
51-
yield tmp
27+
def tmp_path():
28+
"""
29+
Like os_helper.temp_dir, but yields a pathlib.Path.
30+
"""
31+
with os_helper.temp_dir() as path:
32+
yield pathlib.Path(path)
5233

5334

5435
@contextlib.contextmanager
@@ -69,7 +50,7 @@ def setUp(self):
6950
class SiteDir(Fixtures):
7051
def setUp(self):
7152
super().setUp()
72-
self.site_dir = self.fixtures.enter_context(tempdir())
53+
self.site_dir = self.fixtures.enter_context(tmp_path())
7354

7455

7556
class OnSysPath(Fixtures):

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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": {

tests/test_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_unique_distributions(self):
135135
fixtures.build_files(self.make_pkg('abc'), self.site_dir)
136136
before = list(_unique(distributions()))
137137

138-
alt_site_dir = self.fixtures.enter_context(fixtures.tempdir())
138+
alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path())
139139
self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
140140
fixtures.build_files(self.make_pkg('ABC'), alt_site_dir)
141141
after = list(_unique(distributions()))

0 commit comments

Comments
 (0)