Skip to content

Commit 4e872d0

Browse files
committed
bpo-40275: Use new test.support helper submodules in tests (pythonGH-21727)
1 parent 37fb8f8 commit 4e872d0

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,

0 commit comments

Comments
 (0)