Skip to content

Commit c7decc2

Browse files
authored
bpo-40275: Use new test.support helper submodules in tests (GH-21727)
1 parent 604bba1 commit c7decc2

19 files changed

+58
-46
lines changed

Lib/test/test_importlib/fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ def build_files(file_defs, prefix=pathlib.Path()):
213213
class FileBuilder:
214214
def unicode_filename(self):
215215
try:
216-
import test.support
216+
from test.support import os_helper
217217
except ImportError:
218218
# outside CPython, hard-code a unicode snowman
219219
return '☃'
220-
return test.support.FS_NONASCII or \
220+
return os_helper.FS_NONASCII or \
221221
self.skip("File system does not support non-ascii.")
222222

223223

Lib/test/test_importlib/import_/test_packages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import unittest
44
from test import support
5+
from test.support import import_helper
56

67

78
class ParentModuleTests:
@@ -98,7 +99,7 @@ def module_injection():
9899
try:
99100
submodule = self.__import__(subname)
100101
finally:
101-
support.unload(subname)
102+
import_helper.unload(subname)
102103

103104

104105
(Frozen_ParentTests,

Lib/test/test_importlib/source/test_file_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import unittest
1818
import warnings
1919

20-
from test.support import make_legacy_pyc, unload
20+
from test.support.import_helper import make_legacy_pyc, unload
2121

2222
from test.test_py_compile import without_source_date_epoch
2323
from test.test_py_compile import SourceDateEpochTestMeta

Lib/test/test_importlib/source/test_finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import stat
1010
import sys
1111
import tempfile
12-
from test.support import make_legacy_pyc
12+
from test.support.import_helper import make_legacy_pyc
1313
import unittest
1414
import warnings
1515

Lib/test/test_importlib/test_abc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import sys
55
from test import support
6+
from test.support import import_helper
67
import types
78
import unittest
89
from unittest import mock
@@ -579,8 +580,8 @@ class InspectLoaderLoadModuleTests:
579580
module_name = 'blah'
580581

581582
def setUp(self):
582-
support.unload(self.module_name)
583-
self.addCleanup(support.unload, self.module_name)
583+
import_helper.unload(self.module_name)
584+
self.addCleanup(import_helper.unload, self.module_name)
584585

585586
def load(self, loader):
586587
spec = self.util.spec_from_loader(self.module_name, loader)

Lib/test/test_importlib/test_api.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import os.path
88
import sys
99
from test import support
10+
from test.support import import_helper
11+
from test.support import os_helper
1012
import types
1113
import unittest
1214
import warnings
@@ -200,7 +202,7 @@ class ReloadTests:
200202
def test_reload_modules(self):
201203
for mod in ('tokenize', 'time', 'marshal'):
202204
with self.subTest(module=mod):
203-
with support.CleanImport(mod):
205+
with import_helper.CleanImport(mod):
204206
module = self.init.import_module(mod)
205207
self.init.reload(module)
206208

@@ -221,7 +223,7 @@ def code():
221223
self.assertEqual(reloaded.spam, 3)
222224

223225
def test_reload_missing_loader(self):
224-
with support.CleanImport('types'):
226+
with import_helper.CleanImport('types'):
225227
import types
226228
loader = types.__loader__
227229
del types.__loader__
@@ -232,7 +234,7 @@ def test_reload_missing_loader(self):
232234
self.assertEqual(reloaded.__loader__.path, loader.path)
233235

234236
def test_reload_loader_replaced(self):
235-
with support.CleanImport('types'):
237+
with import_helper.CleanImport('types'):
236238
import types
237239
types.__loader__ = None
238240
self.init.invalidate_caches()
@@ -244,9 +246,9 @@ def test_reload_loader_replaced(self):
244246

245247
def test_reload_location_changed(self):
246248
name = 'spam'
247-
with support.temp_cwd(None) as cwd:
249+
with os_helper.temp_cwd(None) as cwd:
248250
with test_util.uncache('spam'):
249-
with support.DirsOnSysPath(cwd):
251+
with import_helper.DirsOnSysPath(cwd):
250252
# Start as a plain module.
251253
self.init.invalidate_caches()
252254
path = os.path.join(cwd, name + '.py')
@@ -257,7 +259,7 @@ def test_reload_location_changed(self):
257259
'__cached__': cached,
258260
'__doc__': None,
259261
}
260-
support.create_empty_file(path)
262+
os_helper.create_empty_file(path)
261263
module = self.init.import_module(name)
262264
ns = vars(module).copy()
263265
loader = ns.pop('__loader__')
@@ -295,9 +297,9 @@ def test_reload_location_changed(self):
295297

296298
def test_reload_namespace_changed(self):
297299
name = 'spam'
298-
with support.temp_cwd(None) as cwd:
300+
with os_helper.temp_cwd(None) as cwd:
299301
with test_util.uncache('spam'):
300-
with support.DirsOnSysPath(cwd):
302+
with import_helper.DirsOnSysPath(cwd):
301303
# Start as a namespace package.
302304
self.init.invalidate_caches()
303305
bad_path = os.path.join(cwd, name, '__init.py')

Lib/test/test_importlib/test_pkg_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import unittest
88

99
from importlib.util import cache_from_source
10-
from test.support import create_empty_file
10+
from test.support.os_helper import create_empty_file
1111

1212
class TestImport(unittest.TestCase):
1313

Lib/test/test_importlib/test_spec.py

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

77
import os.path
88
import pathlib
9-
from test.support import CleanImport
9+
from test.support.import_helper import CleanImport
1010
import unittest
1111
import sys
1212
import warnings

Lib/test/test_importlib/test_threaded_import.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import threading
1515
import unittest
1616
from unittest import mock
17-
from test.support import (
18-
verbose, run_unittest, TESTFN,
19-
forget, unlink, rmtree)
17+
from test.support import (verbose, run_unittest)
18+
from test.support.import_helper import forget
19+
from test.support.os_helper import (TESTFN, unlink, rmtree)
2020
from test.support import threading_helper
2121

2222
def task(N, done, done_tasks, errors):

Lib/test/test_importlib/test_windows.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
import sys
77
import unittest
88
from test import support
9+
from test.support import import_helper
910
from distutils.util import get_platform
1011
from contextlib import contextmanager
1112
from .util import temp_module
1213

13-
support.import_module('winreg', required_on=['win'])
14+
import_helper.import_module('winreg', required_on=['win'])
1415
from winreg import (
1516
CreateKey, HKEY_CURRENT_USER,
1617
SetValue, REG_SZ, KEY_ALL_ACCESS,

Lib/test/test_importlib/util.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pathlib import Path, PurePath
1414
from test import support
1515
from test.support import import_helper
16+
from test.support import os_helper
1617
import unittest
1718
import sys
1819
import tempfile
@@ -159,9 +160,9 @@ def uncache(*names):
159160
@contextlib.contextmanager
160161
def temp_module(name, content='', *, pkg=False):
161162
conflicts = [n for n in sys.modules if n.partition('.')[0] == name]
162-
with support.temp_cwd(None) as cwd:
163+
with os_helper.temp_cwd(None) as cwd:
163164
with uncache(name, *conflicts):
164-
with support.DirsOnSysPath(cwd):
165+
with import_helper.DirsOnSysPath(cwd):
165166
invalidate_caches()
166167

167168
location = os.path.join(cwd, name)
@@ -397,7 +398,7 @@ def create_modules(*names):
397398
state_manager.__exit__(None, None, None)
398399
if uncache_manager is not None:
399400
uncache_manager.__exit__(None, None, None)
400-
support.rmtree(temp_dir)
401+
os_helper.rmtree(temp_dir)
401402

402403

403404
def mock_path_hook(*entries, importer):
@@ -573,8 +574,8 @@ def tearDownClass(cls):
573574
pass
574575

575576
def setUp(self):
576-
modules = support.modules_setup()
577-
self.addCleanup(support.modules_cleanup, *modules)
577+
modules = import_helper.modules_setup()
578+
self.addCleanup(import_helper.modules_cleanup, *modules)
578579

579580

580581
class ZipSetup(ZipSetupBase):

Lib/test/test_inspect.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
except ImportError:
2525
ThreadPoolExecutor = None
2626

27-
from test.support import run_unittest, TESTFN, DirsOnSysPath, cpython_only
27+
from test.support import run_unittest, cpython_only
2828
from test.support import MISSING_C_DOCSTRINGS, ALWAYS_EQ
29+
from test.support.import_helper import DirsOnSysPath
30+
from test.support.os_helper import TESTFN
2931
from test.support.script_helper import assert_python_ok, assert_python_failure
3032
from test import inspect_fodder as mod
3133
from test import inspect_fodder2 as mod2

Lib/test/test_site.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import test.support
99
from test import support
1010
from test.support import socket_helper
11-
from test.support import (captured_stderr, TESTFN, EnvironmentVarGuard,
12-
change_cwd)
11+
from test.support import captured_stderr
12+
from test.support.os_helper import TESTFN, EnvironmentVarGuard, change_cwd
1313
import builtins
1414
import encodings
1515
import glob

Lib/test/test_tools/test_fixcid.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import runpy
66
import sys
77
from test import support
8+
from test.support import os_helper
89
from test.test_tools import skip_if_missing, scriptsdir
910
import unittest
1011

@@ -57,15 +58,15 @@ def test_alter_comments(self):
5758
)
5859

5960
def test_directory(self):
60-
os.mkdir(support.TESTFN)
61-
self.addCleanup(support.rmtree, support.TESTFN)
62-
c_filename = os.path.join(support.TESTFN, "file.c")
61+
os.mkdir(os_helper.TESTFN)
62+
self.addCleanup(os_helper.rmtree, os_helper.TESTFN)
63+
c_filename = os.path.join(os_helper.TESTFN, "file.c")
6364
with open(c_filename, "w") as file:
6465
file.write("int xx;\n")
65-
with open(os.path.join(support.TESTFN, "file.py"), "w") as file:
66+
with open(os.path.join(os_helper.TESTFN, "file.py"), "w") as file:
6667
file.write("xx = 'unaltered'\n")
6768
script = os.path.join(scriptsdir, "fixcid.py")
68-
output = self.run_script(args=(support.TESTFN,))
69+
output = self.run_script(args=(os_helper.TESTFN,))
6970
self.assertMultiLineEqual(output,
7071
"{}:\n"
7172
"1\n"
@@ -74,10 +75,10 @@ def test_directory(self):
7475
)
7576

7677
def run_script(self, input="", *, args=("-",), substfile="xx yy\n"):
77-
substfilename = support.TESTFN + ".subst"
78+
substfilename = os_helper.TESTFN + ".subst"
7879
with open(substfilename, "w") as file:
7980
file.write(substfile)
80-
self.addCleanup(support.unlink, substfilename)
81+
self.addCleanup(os_helper.unlink, substfilename)
8182

8283
argv = ["fixcid.py", "-s", substfilename] + list(args)
8384
script = os.path.join(scriptsdir, "fixcid.py")

Lib/test/test_tools/test_i18n.py

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

88
from test.support.script_helper import assert_python_ok
99
from test.test_tools import skip_if_missing, toolsdir
10-
from test.support import temp_cwd, temp_dir
10+
from test.support.os_helper import temp_cwd, temp_dir
1111

1212

1313
skip_if_missing()

Lib/test/test_tools/test_lll.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import tempfile
55
from test import support
6+
from test.support import os_helper
67
from test.test_tools import skip_if_missing, import_tool
78
import unittest
89

@@ -14,7 +15,7 @@ class lllTests(unittest.TestCase):
1415
def setUp(self):
1516
self.lll = import_tool('lll')
1617

17-
@support.skip_unless_symlink
18+
@os_helper.skip_unless_symlink
1819
def test_lll_multiple_dirs(self):
1920
with tempfile.TemporaryDirectory() as dir1, \
2021
tempfile.TemporaryDirectory() as dir2:

Lib/test/test_tools/test_pathfix.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import unittest
55
from test import support
6+
from test.support import os_helper
67
from test.test_tools import scriptsdir, skip_if_missing
78

89

@@ -14,7 +15,7 @@ class TestPathfixFunctional(unittest.TestCase):
1415
script = os.path.join(scriptsdir, 'pathfix.py')
1516

1617
def setUp(self):
17-
self.addCleanup(support.unlink, support.TESTFN)
18+
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
1819

1920
def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='',
2021
directory=''):
@@ -24,7 +25,7 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='',
2425
filename = os.path.join(directory, 'script-A_1.py')
2526
pathfix_arg = directory
2627
else:
27-
filename = support.TESTFN
28+
filename = os_helper.TESTFN
2829
pathfix_arg = filename
2930

3031
with open(filename, 'w', encoding='utf8') as f:
@@ -56,8 +57,8 @@ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='',
5657
return new_shebang
5758

5859
def test_recursive(self):
59-
tmpdir = support.TESTFN + '.d'
60-
self.addCleanup(support.rmtree, tmpdir)
60+
tmpdir = os_helper.TESTFN + '.d'
61+
self.addCleanup(os_helper.rmtree, tmpdir)
6162
os.mkdir(tmpdir)
6263
expected_stderr = f"recursedown('{os.path.basename(tmpdir)}')\n"
6364
self.assertEqual(

Lib/test/test_tools/test_pindent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import subprocess
77
import textwrap
88
from test import support
9+
from test.support import os_helper
910
from test.support.script_helper import assert_python_ok
1011

1112
from test.test_tools import scriptsdir, skip_if_missing
@@ -34,7 +35,7 @@ def lstriplines(self, data):
3435

3536
def test_selftest(self):
3637
self.maxDiff = None
37-
with support.temp_dir() as directory:
38+
with os_helper.temp_dir() as directory:
3839
data_path = os.path.join(directory, '_test.py')
3940
with open(self.script) as f:
4041
closed = f.read()

Lib/test/test_tools/test_sundry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import sys
1010
import unittest
11-
from test import support
11+
from test.support import import_helper
1212

1313
from test.test_tools import scriptsdir, import_tool, skip_if_missing
1414

@@ -30,7 +30,7 @@ class TestSundryScripts(unittest.TestCase):
3030
skiplist = blacklist + whitelist + windows_only + other
3131

3232
def test_sundry(self):
33-
old_modules = support.modules_setup()
33+
old_modules = import_helper.modules_setup()
3434
try:
3535
for fn in os.listdir(scriptsdir):
3636
if not fn.endswith('.py'):
@@ -43,7 +43,7 @@ def test_sundry(self):
4343
import_tool(name)
4444
finally:
4545
# Unload all modules loaded in this test
46-
support.modules_cleanup(*old_modules)
46+
import_helper.modules_cleanup(*old_modules)
4747

4848
@unittest.skipIf(sys.platform != "win32", "Windows-only test")
4949
def test_sundry_windows(self):

0 commit comments

Comments
 (0)