bpo-40275: Use new test.support helper submodules in tests (GH-21727)

This commit is contained in:
Hai Shi 2020-08-04 23:53:12 +08:00 committed by GitHub
parent 604bba1f8f
commit c7decc27d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 58 additions and 46 deletions

View file

@ -7,6 +7,8 @@ machinery = test_util.import_importlib('importlib.machinery')
import os.path
import sys
from test import support
from test.support import import_helper
from test.support import os_helper
import types
import unittest
import warnings
@ -200,7 +202,7 @@ class ReloadTests:
def test_reload_modules(self):
for mod in ('tokenize', 'time', 'marshal'):
with self.subTest(module=mod):
with support.CleanImport(mod):
with import_helper.CleanImport(mod):
module = self.init.import_module(mod)
self.init.reload(module)
@ -221,7 +223,7 @@ class ReloadTests:
self.assertEqual(reloaded.spam, 3)
def test_reload_missing_loader(self):
with support.CleanImport('types'):
with import_helper.CleanImport('types'):
import types
loader = types.__loader__
del types.__loader__
@ -232,7 +234,7 @@ class ReloadTests:
self.assertEqual(reloaded.__loader__.path, loader.path)
def test_reload_loader_replaced(self):
with support.CleanImport('types'):
with import_helper.CleanImport('types'):
import types
types.__loader__ = None
self.init.invalidate_caches()
@ -244,9 +246,9 @@ class ReloadTests:
def test_reload_location_changed(self):
name = 'spam'
with support.temp_cwd(None) as cwd:
with os_helper.temp_cwd(None) as cwd:
with test_util.uncache('spam'):
with support.DirsOnSysPath(cwd):
with import_helper.DirsOnSysPath(cwd):
# Start as a plain module.
self.init.invalidate_caches()
path = os.path.join(cwd, name + '.py')
@ -257,7 +259,7 @@ class ReloadTests:
'__cached__': cached,
'__doc__': None,
}
support.create_empty_file(path)
os_helper.create_empty_file(path)
module = self.init.import_module(name)
ns = vars(module).copy()
loader = ns.pop('__loader__')
@ -295,9 +297,9 @@ class ReloadTests:
def test_reload_namespace_changed(self):
name = 'spam'
with support.temp_cwd(None) as cwd:
with os_helper.temp_cwd(None) as cwd:
with test_util.uncache('spam'):
with support.DirsOnSysPath(cwd):
with import_helper.DirsOnSysPath(cwd):
# Start as a namespace package.
self.init.invalidate_caches()
bad_path = os.path.join(cwd, name, '__init.py')