Skip to content

Commit bb0424b

Browse files
authored
bpo-40275: Use new test.support helper submodules in tests (GH-21451)
1 parent a7f5d93 commit bb0424b

20 files changed

+324
-278
lines changed

Lib/test/test_bdb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
from contextlib import contextmanager
5959
from itertools import islice, repeat
6060
import test.support
61+
from test.support import import_helper
62+
from test.support import os_helper
63+
6164

6265
class BdbException(Exception): pass
6366
class BdbError(BdbException): """Error raised by the Bdb instance."""
@@ -531,7 +534,7 @@ def gen(a, b):
531534

532535
@contextmanager
533536
def create_modules(modules):
534-
with test.support.temp_cwd():
537+
with os_helper.temp_cwd():
535538
sys.path.append(os.getcwd())
536539
try:
537540
for m in modules:
@@ -543,7 +546,7 @@ def create_modules(modules):
543546
yield
544547
finally:
545548
for m in modules:
546-
test.support.forget(m)
549+
import_helper.forget(m)
547550
sys.path.pop()
548551

549552
def break_in_func(funcname, fname=__file__, temporary=False, cond=None):

Lib/test/test_code_module.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from textwrap import dedent
55
from contextlib import ExitStack
66
from unittest import mock
7-
from test import support
7+
from test.support import import_helper
88

9-
code = support.import_module('code')
9+
10+
code = import_helper.import_module('code')
1011

1112

1213
class TestInteractiveConsole(unittest.TestCase):

Lib/test/test_embed.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Run the tests in Programs/_testembed.c (tests for the CPython embedding APIs)
22
from test import support
3+
from test.support import import_helper
4+
from test.support import os_helper
35
import unittest
46

57
from collections import namedtuple
@@ -1339,8 +1341,8 @@ def test_global_pathconfig(self):
13391341
#
13401342
# The global path configuration (_Py_path_config) must be a copy
13411343
# of the path configuration of PyInterpreter.config (PyConfig).
1342-
ctypes = support.import_module('ctypes')
1343-
_testinternalcapi = support.import_module('_testinternalcapi')
1344+
ctypes = import_helper.import_module('ctypes')
1345+
_testinternalcapi = import_helper.import_module('_testinternalcapi')
13441346

13451347
def get_func(name):
13461348
func = getattr(ctypes.pythonapi, name)
@@ -1418,7 +1420,7 @@ def test_audit_run_file(self):
14181420
returncode=1)
14191421

14201422
def test_audit_run_interactivehook(self):
1421-
startup = os.path.join(self.oldcwd, support.TESTFN) + ".py"
1423+
startup = os.path.join(self.oldcwd, os_helper.TESTFN) + ".py"
14221424
with open(startup, "w", encoding="utf-8") as f:
14231425
print("import sys", file=f)
14241426
print("sys.__interactivehook__ = lambda: None", file=f)
@@ -1431,7 +1433,7 @@ def test_audit_run_interactivehook(self):
14311433
os.unlink(startup)
14321434

14331435
def test_audit_run_startup(self):
1434-
startup = os.path.join(self.oldcwd, support.TESTFN) + ".py"
1436+
startup = os.path.join(self.oldcwd, os_helper.TESTFN) + ".py"
14351437
with open(startup, "w", encoding="utf-8") as f:
14361438
print("pass", file=f)
14371439
try:

Lib/test/test_gzip.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import unittest
1212
from subprocess import PIPE, Popen
1313
from test import support
14+
from test.support import import_helper
15+
from test.support import os_helper
1416
from test.support import _4G, bigmemtest
1517
from test.support.script_helper import assert_python_ok, assert_python_failure
1618

17-
gzip = support.import_module('gzip')
19+
gzip = import_helper.import_module('gzip')
1820

1921
data1 = b""" int length=DEFAULTALLOC, err = Z_OK;
2022
PyObject *RetVal;
@@ -29,7 +31,7 @@
2931
"""
3032

3133

32-
TEMPDIR = os.path.abspath(support.TESTFN) + '-gzdir'
34+
TEMPDIR = os.path.abspath(os_helper.TESTFN) + '-gzdir'
3335

3436

3537
class UnseekableIO(io.BytesIO):
@@ -44,13 +46,13 @@ def seek(self, *args):
4446

4547

4648
class BaseTest(unittest.TestCase):
47-
filename = support.TESTFN
49+
filename = os_helper.TESTFN
4850

4951
def setUp(self):
50-
support.unlink(self.filename)
52+
os_helper.unlink(self.filename)
5153

5254
def tearDown(self):
53-
support.unlink(self.filename)
55+
os_helper.unlink(self.filename)
5456

5557

5658
class TestGzip(BaseTest):
@@ -286,7 +288,7 @@ def test_mode(self):
286288
self.test_write()
287289
with gzip.GzipFile(self.filename, 'r') as f:
288290
self.assertEqual(f.myfileobj.mode, 'rb')
289-
support.unlink(self.filename)
291+
os_helper.unlink(self.filename)
290292
with gzip.GzipFile(self.filename, 'x') as f:
291293
self.assertEqual(f.myfileobj.mode, 'xb')
292294

@@ -365,7 +367,7 @@ def test_metadata(self):
365367
self.assertEqual(isizeBytes, struct.pack('<i', len(data1)))
366368

367369
def test_metadata_ascii_name(self):
368-
self.filename = support.TESTFN_ASCII
370+
self.filename = os_helper.TESTFN_ASCII
369371
self.test_metadata()
370372

371373
def test_compresslevel_metadata(self):
@@ -497,7 +499,7 @@ def test_fileobj_mode(self):
497499
self.assertEqual(g.mode, gzip.READ)
498500
for mode in "wb", "ab", "xb":
499501
if "x" in mode:
500-
support.unlink(self.filename)
502+
os_helper.unlink(self.filename)
501503
with open(self.filename, mode) as f:
502504
with self.assertWarns(FutureWarning):
503505
g = gzip.GzipFile(fileobj=f)
@@ -611,7 +613,7 @@ def test_binary_modes(self):
611613

612614
with self.assertRaises(FileExistsError):
613615
gzip.open(self.filename, "xb")
614-
support.unlink(self.filename)
616+
os_helper.unlink(self.filename)
615617
with gzip.open(self.filename, "xb") as f:
616618
f.write(uncompressed)
617619
with open(self.filename, "rb") as f:
@@ -648,7 +650,7 @@ def test_implicit_binary_modes(self):
648650

649651
with self.assertRaises(FileExistsError):
650652
gzip.open(self.filename, "x")
651-
support.unlink(self.filename)
653+
os_helper.unlink(self.filename)
652654
with gzip.open(self.filename, "x") as f:
653655
f.write(uncompressed)
654656
with open(self.filename, "rb") as f:
@@ -734,7 +736,7 @@ def wrapper(*args, **kwargs):
734736
try:
735737
return function(*args, **kwargs)
736738
finally:
737-
support.rmtree(directory)
739+
os_helper.rmtree(directory)
738740
return wrapper
739741
return decorator
740742

Lib/test/test_largefile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import socket
99
import shutil
1010
import threading
11-
from test.support import TESTFN, requires, unlink, bigmemtest
11+
from test.support import requires, bigmemtest
1212
from test.support import SHORT_TIMEOUT
1313
from test.support import socket_helper
14+
from test.support.os_helper import TESTFN, unlink
1415
import io # C implementation of io
1516
import _pyio as pyio # Python implementation of io
1617

Lib/test/test_lltrace.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import textwrap
33
import unittest
44

5-
from test import support
5+
from test.support import os_helper
66
from test.support.script_helper import assert_python_ok
77

88

@@ -13,8 +13,8 @@ def test_lltrace_does_not_crash_on_subscript_operator(self):
1313
# bpo-34113. The crash happened at the command line console of
1414
# debug Python builds with __ltrace__ enabled (only possible in console),
1515
# when the interal Python stack was negatively adjusted
16-
with open(support.TESTFN, 'w') as fd:
17-
self.addCleanup(os.unlink, support.TESTFN)
16+
with open(os_helper.TESTFN, 'w') as fd:
17+
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
1818
fd.write(textwrap.dedent("""\
1919
import code
2020
@@ -25,7 +25,7 @@ def test_lltrace_does_not_crash_on_subscript_operator(self):
2525
print('unreachable if bug exists')
2626
"""))
2727

28-
assert_python_ok(support.TESTFN)
28+
assert_python_ok(os_helper.TESTFN)
2929

3030
if __name__ == "__main__":
3131
unittest.main()

Lib/test/test_ordered_dict.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
import weakref
1111
from collections.abc import MutableMapping
1212
from test import mapping_tests, support
13+
from test.support import import_helper
1314

1415

15-
py_coll = support.import_fresh_module('collections', blocked=['_collections'])
16-
c_coll = support.import_fresh_module('collections', fresh=['_collections'])
16+
py_coll = import_helper.import_fresh_module('collections',
17+
blocked=['_collections'])
18+
c_coll = import_helper.import_fresh_module('collections',
19+
fresh=['_collections'])
1720

1821

1922
@contextlib.contextmanager

0 commit comments

Comments
 (0)