Skip to content

Commit 0c4f0f3

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

14 files changed

+348
-319
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
import test.support.script_helper
2828
from test import support
2929
from test.support import hashlib_helper
30+
from test.support import import_helper
3031
from test.support import socket_helper
3132
from test.support import threading_helper
3233

3334

3435
# Skip tests if _multiprocessing wasn't built.
35-
_multiprocessing = test.support.import_module('_multiprocessing')
36+
_multiprocessing = import_helper.import_module('_multiprocessing')
3637
# Skip tests if sem_open implementation is broken.
3738
support.skip_if_broken_multiprocessing_synchronize()
3839
import threading

Lib/test/test_base64.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import unittest
2-
from test import support
32
import base64
43
import binascii
54
import os
65
from array import array
6+
from test.support import os_helper
77
from test.support import script_helper
88

99

@@ -647,8 +647,8 @@ def test_ErrorHeritage(self):
647647

648648
class TestMain(unittest.TestCase):
649649
def tearDown(self):
650-
if os.path.exists(support.TESTFN):
651-
os.unlink(support.TESTFN)
650+
if os.path.exists(os_helper.TESTFN):
651+
os.unlink(os_helper.TESTFN)
652652

653653
def get_output(self, *args):
654654
return script_helper.assert_python_ok('-m', 'base64', *args).out
@@ -662,9 +662,9 @@ def test_encode_decode(self):
662662
))
663663

664664
def test_encode_file(self):
665-
with open(support.TESTFN, 'wb') as fp:
665+
with open(os_helper.TESTFN, 'wb') as fp:
666666
fp.write(b'a\xffb\n')
667-
output = self.get_output('-e', support.TESTFN)
667+
output = self.get_output('-e', os_helper.TESTFN)
668668
self.assertEqual(output.rstrip(), b'Yf9iCg==')
669669

670670
def test_encode_from_stdin(self):
@@ -674,9 +674,9 @@ def test_encode_from_stdin(self):
674674
self.assertIsNone(err)
675675

676676
def test_decode(self):
677-
with open(support.TESTFN, 'wb') as fp:
677+
with open(os_helper.TESTFN, 'wb') as fp:
678678
fp.write(b'Yf9iCg==')
679-
output = self.get_output('-d', support.TESTFN)
679+
output = self.get_output('-d', os_helper.TESTFN)
680680
self.assertEqual(output.rstrip(), b'a\xffb')
681681

682682
if __name__ == '__main__':

Lib/test/test_bool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import unittest
44
from test import support
5+
from test.support import os_helper
56

67
import os
78

@@ -234,11 +235,11 @@ def test_boolean(self):
234235

235236
def test_fileclosed(self):
236237
try:
237-
with open(support.TESTFN, "w") as f:
238+
with open(os_helper.TESTFN, "w") as f:
238239
self.assertIs(f.closed, False)
239240
self.assertIs(f.closed, True)
240241
finally:
241-
os.remove(support.TESTFN)
242+
os.remove(os_helper.TESTFN)
242243

243244
def test_types(self):
244245
# types are always true.

Lib/test/test_dict_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
Test implementation of the PEP 509: dictionary versionning.
33
"""
44
import unittest
5-
from test import support
5+
from test.support import import_helper
66

77
# PEP 509 is implemented in CPython but other Python implementations
88
# don't require to implement it
9-
_testcapi = support.import_module('_testcapi')
9+
_testcapi = import_helper.import_module('_testcapi')
1010

1111

1212
class DictVersionTests(unittest.TestCase):

Lib/test/test_grammar.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Python test set -- part 1, grammar.
22
# This just tests whether the parser accepts them all.
33

4-
from test.support import check_syntax_error, check_syntax_warning
4+
from test.support import check_syntax_error
5+
from test.support.warnings_helper import check_syntax_warning
56
import inspect
67
import unittest
78
import sys
@@ -276,7 +277,8 @@ def __getitem__(self, item):
276277

277278
class GrammarTests(unittest.TestCase):
278279

279-
from test.support import check_syntax_error, check_syntax_warning
280+
from test.support import check_syntax_error
281+
from test.support.warnings_helper import check_syntax_warning
280282

281283
# single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
282284
# XXX can't test in a script -- this rule is only used when interactive

Lib/test/test_iter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import sys
44
import unittest
5-
from test.support import run_unittest, TESTFN, unlink, cpython_only
5+
from test.support import run_unittest, cpython_only
6+
from test.support.os_helper import TESTFN, unlink
67
from test.support import check_free_after_iterating, ALWAYS_EQ, NEVER_EQ
78
import pickle
89
import collections.abc

Lib/test/test_lzma.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import unittest
1010

1111
from test.support import (
12-
_4G, TESTFN, import_module, bigmemtest, run_unittest, unlink
12+
_4G, bigmemtest, run_unittest
13+
)
14+
from test.support.import_helper import import_module
15+
from test.support.os_helper import (
16+
TESTFN, unlink
1317
)
1418

1519
lzma = import_module("lzma")

Lib/test/test_mailcap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import copy
44
import test.support
5+
from test.support import os_helper
56
import unittest
67

78
# Location of mailcap file
@@ -74,7 +75,7 @@ def test_listmailcapfiles(self):
7475
self.assertIsInstance(mcfiles, list)
7576
for m in mcfiles:
7677
self.assertIsInstance(m, str)
77-
with test.support.EnvironmentVarGuard() as env:
78+
with os_helper.EnvironmentVarGuard() as env:
7879
# According to RFC 1524, if MAILCAPS env variable exists, use that
7980
# and only that.
8081
if "MAILCAPS" in env:
@@ -136,7 +137,7 @@ def test_mock_getcaps(self):
136137
# Test mailcap.getcaps() using mock mailcap file in this dir.
137138
# Temporarily override any existing system mailcap file by pointing the
138139
# MAILCAPS environment variable to our mock file.
139-
with test.support.EnvironmentVarGuard() as env:
140+
with os_helper.EnvironmentVarGuard() as env:
140141
env["MAILCAPS"] = MAILCAPFILE
141142
caps = mailcap.getcaps()
142143
self.assertDictEqual(caps, MAILCAPDICT)

Lib/test/test_memoryview.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import copy
1515
import pickle
1616

17+
from test.support import import_helper
18+
1719

1820
class AbstractMemoryTests:
1921
source_bytes = b"abcdef"
@@ -508,7 +510,7 @@ class ArrayMemorySliceSliceTest(unittest.TestCase,
508510
class OtherTest(unittest.TestCase):
509511
def test_ctypes_cast(self):
510512
# Issue 15944: Allow all source formats when casting to bytes.
511-
ctypes = test.support.import_module("ctypes")
513+
ctypes = import_helper.import_module("ctypes")
512514
p6 = bytes(ctypes.c_double(0.6))
513515

514516
d = ctypes.c_double()

0 commit comments

Comments
 (0)