Skip to content

Commit 3ddc634

Browse files
authored
bpo-40275: Use new test.support helper submodules in tests (GH-21219)
1 parent 3fa4799 commit 3ddc634

16 files changed

+116
-94
lines changed

Lib/test/audiotests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from test.support import findfile, TESTFN, unlink
1+
from test.support import findfile
2+
from test.support.os_helper import TESTFN, unlink
23
import array
34
import io
45
import pickle

Lib/test/libregrtest/cmdline.py

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

67

78
USAGE = """\
@@ -291,7 +292,7 @@ def _create_parser():
291292
def relative_filename(string):
292293
# CWD is replaced with a temporary dir before calling main(), so we
293294
# join it with the saved CWD so it ends up where the user expects.
294-
return os.path.join(support.SAVEDCWD, string)
295+
return os.path.join(os_helper.SAVEDCWD, string)
295296

296297

297298
def huntrleaks(string):

Lib/test/libregrtest/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def find_tests(self, tests):
216216
# regex to match 'test_builtin' in line:
217217
# '0:00:00 [ 4/400] test_builtin -- test_dict took 1 sec'
218218
regex = re.compile(r'\btest_[a-zA-Z0-9_]+\b')
219-
with open(os.path.join(support.SAVEDCWD, self.ns.fromfile)) as fp:
219+
with open(os.path.join(os_helper.SAVEDCWD, self.ns.fromfile)) as fp:
220220
for line in fp:
221221
line = line.split('#', 1)[0]
222222
line = line.strip()
@@ -559,7 +559,7 @@ def save_xml_result(self):
559559
for k, v in totals.items():
560560
root.set(k, str(v))
561561

562-
xmlpath = os.path.join(support.SAVEDCWD, self.ns.xmlpath)
562+
xmlpath = os.path.join(os_helper.SAVEDCWD, self.ns.xmlpath)
563563
with open(xmlpath, 'wb') as f:
564564
for s in ET.tostringlist(root):
565565
f.write(s)
@@ -597,7 +597,7 @@ def create_temp_dir(self):
597597
test_cwd = 'test_python_worker_{}'.format(pid)
598598
else:
599599
test_cwd = 'test_python_{}'.format(pid)
600-
test_cwd += support.FS_NONASCII
600+
test_cwd += os_helper.FS_NONASCII
601601
test_cwd = os.path.join(self.tmp_dir, test_cwd)
602602
return test_cwd
603603

@@ -609,10 +609,10 @@ def cleanup(self):
609609
for name in glob.glob(path):
610610
if os.path.isdir(name):
611611
print("Remove directory: %s" % name)
612-
support.rmtree(name)
612+
os_helper.rmtree(name)
613613
else:
614614
print("Remove file: %s" % name)
615-
support.unlink(name)
615+
os_helper.unlink(name)
616616

617617
def main(self, tests=None, **kwargs):
618618
self.parse_args(kwargs)
@@ -629,7 +629,7 @@ def main(self, tests=None, **kwargs):
629629
# Run the tests in a context manager that temporarily changes the CWD
630630
# to a temporary and writable directory. If it's not possible to
631631
# create or change the CWD, the original CWD will be used.
632-
# The original CWD is available from support.SAVEDCWD.
632+
# The original CWD is available from os_helper.SAVEDCWD.
633633
with os_helper.temp_cwd(test_cwd, quiet=True):
634634
# When using multiprocessing, worker processes will use test_cwd
635635
# as their parent temporary directory. So when the main process

Lib/test/libregrtest/runtest_mp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import traceback
1212
import types
1313
from test import support
14+
from test.support import os_helper
1415

1516
from test.libregrtest.runtest import (
1617
runtest, INTERRUPTED, CHILD_ERROR, PROGRESS_MIN_TIME,
@@ -70,7 +71,7 @@ def run_test_in_subprocess(testname, ns):
7071
stderr=subprocess.PIPE,
7172
universal_newlines=True,
7273
close_fds=(os.name != 'nt'),
73-
cwd=support.SAVEDCWD,
74+
cwd=os_helper.SAVEDCWD,
7475
**kw)
7576

7677

Lib/test/test_aifc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from test.support import check_no_resource_warning, findfile, TESTFN, unlink
1+
from test.support import findfile
2+
from test.support.os_helper import TESTFN, unlink
3+
from test.support.warnings_helper import check_no_resource_warning
24
import unittest
35
from unittest import mock
46
from test import audiotests

Lib/test/test_bz2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
import shutil
1313
import subprocess
1414
import threading
15+
from test.support import import_helper
1516
from test.support import threading_helper
16-
from test.support import unlink
17+
from test.support.os_helper import unlink
1718
import _compression
1819
import sys
1920

2021

2122
# Skip tests if the bz2 module doesn't exist.
22-
bz2 = support.import_module('bz2')
23+
bz2 = import_helper.import_module('bz2')
2324
from bz2 import BZ2File, BZ2Compressor, BZ2Decompressor
2425

2526
has_cmdline_bunzip2 = None

Lib/test/test_functools.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919
from weakref import proxy
2020
import contextlib
2121

22+
from test.support import import_helper
2223
from test.support import threading_helper
2324
from test.support.script_helper import assert_python_ok
2425

2526
import functools
2627

27-
py_functools = support.import_fresh_module('functools', blocked=['_functools'])
28-
c_functools = support.import_fresh_module('functools', fresh=['_functools'])
28+
py_functools = import_helper.import_fresh_module('functools',
29+
blocked=['_functools'])
30+
c_functools = import_helper.import_fresh_module('functools',
31+
fresh=['_functools'])
2932

30-
decimal = support.import_fresh_module('decimal', fresh=['_decimal'])
33+
decimal = import_helper.import_fresh_module('decimal', fresh=['_decimal'])
3134

3235
@contextlib.contextmanager
3336
def replaced_module(name, replacement):

Lib/test/test_future.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ast
55
import unittest
66
from test import support
7+
from test.support import import_helper
78
from textwrap import dedent
89
import os
910
import re
@@ -24,17 +25,17 @@ def check_syntax_error(self, err, basename, lineno, offset=1):
2425
self.assertEqual(err.offset, offset)
2526

2627
def test_future1(self):
27-
with support.CleanImport('future_test1'):
28+
with import_helper.CleanImport('future_test1'):
2829
from test import future_test1
2930
self.assertEqual(future_test1.result, 6)
3031

3132
def test_future2(self):
32-
with support.CleanImport('future_test2'):
33+
with import_helper.CleanImport('future_test2'):
3334
from test import future_test2
3435
self.assertEqual(future_test2.result, 6)
3536

3637
def test_future3(self):
37-
with support.CleanImport('test_future3'):
38+
with import_helper.CleanImport('test_future3'):
3839
from test import test_future3
3940

4041
def test_badfuture3(self):
@@ -113,7 +114,7 @@ def test_parserhack(self):
113114
self.fail("syntax error didn't occur")
114115

115116
def test_multiple_features(self):
116-
with support.CleanImport("test.test_future5"):
117+
with import_helper.CleanImport("test.test_future5"):
117118
from test import test_future5
118119

119120
def test_unicode_literals_exec(self):

Lib/test/test_logging.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
import tempfile
4343
from test.support.script_helper import assert_python_ok, assert_python_failure
4444
from test import support
45+
from test.support import os_helper
4546
from test.support import socket_helper
4647
from test.support import threading_helper
48+
from test.support import warnings_helper
4749
from test.support.logging_helper import TestHandler
4850
import textwrap
4951
import threading
@@ -1169,7 +1171,7 @@ class ConfigFileTest(BaseTest):
11691171

11701172
"""Reading logging config from a .ini-style config file."""
11711173

1172-
check_no_resource_warning = support.check_no_resource_warning
1174+
check_no_resource_warning = warnings_helper.check_no_resource_warning
11731175
expected_log_pat = r"^(\w+) \+\+ (\w+)$"
11741176

11751177
# config0 is a standard configuration.
@@ -1756,7 +1758,7 @@ def setUp(self):
17561758

17571759
def tearDown(self):
17581760
SocketHandlerTest.tearDown(self)
1759-
support.unlink(self.address)
1761+
os_helper.unlink(self.address)
17601762

17611763
class DatagramHandlerTest(BaseTest):
17621764

@@ -1837,7 +1839,7 @@ def setUp(self):
18371839

18381840
def tearDown(self):
18391841
DatagramHandlerTest.tearDown(self)
1840-
support.unlink(self.address)
1842+
os_helper.unlink(self.address)
18411843

18421844
class SysLogHandlerTest(BaseTest):
18431845

@@ -1921,7 +1923,7 @@ def setUp(self):
19211923

19221924
def tearDown(self):
19231925
SysLogHandlerTest.tearDown(self)
1924-
support.unlink(self.address)
1926+
os_helper.unlink(self.address)
19251927

19261928
@unittest.skipUnless(socket_helper.IPV6_ENABLED,
19271929
'IPv6 support required for this test.')
@@ -2175,7 +2177,7 @@ class ConfigDictTest(BaseTest):
21752177

21762178
"""Reading logging config from a dictionary."""
21772179

2178-
check_no_resource_warning = support.check_no_resource_warning
2180+
check_no_resource_warning = warnings_helper.check_no_resource_warning
21792181
expected_log_pat = r"^(\w+) \+\+ (\w+)$"
21802182

21812183
# config0 is a standard configuration.

Lib/test/test_poll.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import threading
88
import time
99
import unittest
10-
from test.support import TESTFN, run_unittest, cpython_only
10+
from test.support import run_unittest, cpython_only
1111
from test.support import threading_helper
12+
from test.support.os_helper import TESTFN
13+
1214

1315
try:
1416
select.poll

0 commit comments

Comments
 (0)