Skip to content

Commit a7f5d93

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

20 files changed

+154
-132
lines changed

Lib/test/test__opcode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dis
2-
from test.support import import_module
2+
from test.support.import_helper import import_module
33
import unittest
44

55
_opcode = import_module("_opcode")

Lib/test/test_asyncore.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import threading
1111

1212
from test import support
13+
from test.support import os_helper
1314
from test.support import socket_helper
1415
from test.support import threading_helper
16+
from test.support import warnings_helper
1517
from io import BytesIO
1618

1719
if support.PGO:
@@ -92,7 +94,7 @@ def bind_af_aware(sock, addr):
9294
"""Helper function to bind a socket according to its family."""
9395
if HAS_UNIX_SOCKETS and sock.family == socket.AF_UNIX:
9496
# Make sure the path doesn't exist.
95-
support.unlink(addr)
97+
os_helper.unlink(addr)
9698
socket_helper.bind_unix_socket(sock, addr)
9799
else:
98100
sock.bind(addr)
@@ -369,14 +371,14 @@ def test_send(self):
369371
class FileWrapperTest(unittest.TestCase):
370372
def setUp(self):
371373
self.d = b"It's not dead, it's sleeping!"
372-
with open(support.TESTFN, 'wb') as file:
374+
with open(os_helper.TESTFN, 'wb') as file:
373375
file.write(self.d)
374376

375377
def tearDown(self):
376-
support.unlink(support.TESTFN)
378+
os_helper.unlink(os_helper.TESTFN)
377379

378380
def test_recv(self):
379-
fd = os.open(support.TESTFN, os.O_RDONLY)
381+
fd = os.open(os_helper.TESTFN, os.O_RDONLY)
380382
w = asyncore.file_wrapper(fd)
381383
os.close(fd)
382384

@@ -390,20 +392,20 @@ def test_recv(self):
390392
def test_send(self):
391393
d1 = b"Come again?"
392394
d2 = b"I want to buy some cheese."
393-
fd = os.open(support.TESTFN, os.O_WRONLY | os.O_APPEND)
395+
fd = os.open(os_helper.TESTFN, os.O_WRONLY | os.O_APPEND)
394396
w = asyncore.file_wrapper(fd)
395397
os.close(fd)
396398

397399
w.write(d1)
398400
w.send(d2)
399401
w.close()
400-
with open(support.TESTFN, 'rb') as file:
402+
with open(os_helper.TESTFN, 'rb') as file:
401403
self.assertEqual(file.read(), self.d + d1 + d2)
402404

403405
@unittest.skipUnless(hasattr(asyncore, 'file_dispatcher'),
404406
'asyncore.file_dispatcher required')
405407
def test_dispatcher(self):
406-
fd = os.open(support.TESTFN, os.O_RDONLY)
408+
fd = os.open(os_helper.TESTFN, os.O_RDONLY)
407409
data = []
408410
class FileDispatcher(asyncore.file_dispatcher):
409411
def handle_read(self):
@@ -415,16 +417,16 @@ def handle_read(self):
415417

416418
def test_resource_warning(self):
417419
# Issue #11453
418-
fd = os.open(support.TESTFN, os.O_RDONLY)
420+
fd = os.open(os_helper.TESTFN, os.O_RDONLY)
419421
f = asyncore.file_wrapper(fd)
420422

421423
os.close(fd)
422-
with support.check_warnings(('', ResourceWarning)):
424+
with warnings_helper.check_warnings(('', ResourceWarning)):
423425
f = None
424426
support.gc_collect()
425427

426428
def test_close_twice(self):
427-
fd = os.open(support.TESTFN, os.O_RDONLY)
429+
fd = os.open(os_helper.TESTFN, os.O_RDONLY)
428430
f = asyncore.file_wrapper(fd)
429431
os.close(fd)
430432

@@ -804,10 +806,10 @@ class TestAPI_UseIPv6Sockets(BaseTestAPI):
804806
class TestAPI_UseUnixSockets(BaseTestAPI):
805807
if HAS_UNIX_SOCKETS:
806808
family = socket.AF_UNIX
807-
addr = support.TESTFN
809+
addr = os_helper.TESTFN
808810

809811
def tearDown(self):
810-
support.unlink(self.addr)
812+
os_helper.unlink(self.addr)
811813
BaseTestAPI.tearDown(self)
812814

813815
class TestAPI_UseIPv4Select(TestAPI_UseIPv4Sockets, unittest.TestCase):

Lib/test/test_binascii.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import binascii
55
import array
66
import re
7-
from test import support
7+
from test.support import warnings_helper
8+
89

910
# Note: "*_hex" functions are aliases for "(un)hexlify"
1011
b2a_functions = ['b2a_base64', 'b2a_hex', 'b2a_hqx', 'b2a_qp', 'b2a_uu',
@@ -37,7 +38,7 @@ def test_functions(self):
3738
self.assertTrue(hasattr(getattr(binascii, name), '__call__'))
3839
self.assertRaises(TypeError, getattr(binascii, name))
3940

40-
@support.ignore_warnings(category=DeprecationWarning)
41+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
4142
def test_returned_value(self):
4243
# Limit to the minimum of all limits (b2a_uu)
4344
MAX_ALL = 45
@@ -181,7 +182,7 @@ def test_uu(self):
181182
with self.assertRaises(TypeError):
182183
binascii.b2a_uu(b"", True)
183184

184-
@support.ignore_warnings(category=DeprecationWarning)
185+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
185186
def test_crc_hqx(self):
186187
crc = binascii.crc_hqx(self.type2test(b"Test the CRC-32 of"), 0)
187188
crc = binascii.crc_hqx(self.type2test(b" this string."), crc)
@@ -201,7 +202,7 @@ def test_crc32(self):
201202

202203
self.assertRaises(TypeError, binascii.crc32)
203204

204-
@support.ignore_warnings(category=DeprecationWarning)
205+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
205206
def test_hqx(self):
206207
# Perform binhex4 style RLE-compression
207208
# Then calculate the hexbin4 binary-to-ASCII translation
@@ -212,7 +213,7 @@ def test_hqx(self):
212213
res = binascii.rledecode_hqx(b)
213214
self.assertEqual(res, self.rawdata)
214215

215-
@support.ignore_warnings(category=DeprecationWarning)
216+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
216217
def test_rle(self):
217218
# test repetition with a repetition longer than the limit of 255
218219
data = (b'a' * 100 + b'b' + b'c' * 300)
@@ -359,7 +360,7 @@ def test_qp(self):
359360
self.assertEqual(b2a_qp(type2test(b'a.\n')), b'a.\n')
360361
self.assertEqual(b2a_qp(type2test(b'.a')[:-1]), b'=2E')
361362

362-
@support.ignore_warnings(category=DeprecationWarning)
363+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
363364
def test_empty_string(self):
364365
# A test for SF bug #1022953. Make sure SystemError is not raised.
365366
empty = self.type2test(b'')
@@ -384,7 +385,7 @@ def test_unicode_b2a(self):
384385
# crc_hqx needs 2 arguments
385386
self.assertRaises(TypeError, binascii.crc_hqx, "test", 0)
386387

387-
@support.ignore_warnings(category=DeprecationWarning)
388+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
388389
def test_unicode_a2b(self):
389390
# Unicode strings are accepted by a2b_* functions.
390391
MAX_ALL = 45

Lib/test/test_bisect.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import sys
22
import unittest
3-
from test import support
3+
from test.support import import_helper
44
from collections import UserList
55

6-
py_bisect = support.import_fresh_module('bisect', blocked=['_bisect'])
7-
c_bisect = support.import_fresh_module('bisect', fresh=['_bisect'])
6+
7+
py_bisect = import_helper.import_fresh_module('bisect', blocked=['_bisect'])
8+
c_bisect = import_helper.import_fresh_module('bisect', fresh=['_bisect'])
89

910
class Range(object):
1011
"""A trivial range()-like object that has an insert() method."""

Lib/test/test_builtin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
from types import AsyncGeneratorType, FunctionType
2727
from operator import neg
2828
from test import support
29-
from test.support import (
30-
EnvironmentVarGuard, TESTFN, check_warnings, swap_attr, unlink,
31-
maybe_get_event_loop_policy)
29+
from test.support import (swap_attr, maybe_get_event_loop_policy)
30+
from test.support.os_helper import (EnvironmentVarGuard, TESTFN, unlink)
3231
from test.support.script_helper import assert_python_ok
32+
from test.support.warnings_helper import check_warnings
3333
from unittest.mock import MagicMock, patch
3434
try:
3535
import pty, signal

Lib/test/test_concurrent_futures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from test import support
2+
from test.support import import_helper
23
from test.support import threading_helper
34

45
# Skip tests if _multiprocessing wasn't built.
5-
support.import_module('_multiprocessing')
6+
import_helper.import_module('_multiprocessing')
67
# Skip tests if sem_open implementation is broken.
78
support.skip_if_broken_multiprocessing_synchronize()
89

Lib/test/test_configparser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import warnings
99

1010
from test import support
11+
from test.support import os_helper
1112

1213

1314
class SortedDict(collections.UserDict):
@@ -1063,17 +1064,17 @@ def setUp(self):
10631064
cf.add_section(s)
10641065
for j in range(10):
10651066
cf.set(s, 'lovely_spam{}'.format(j), self.wonderful_spam)
1066-
with open(support.TESTFN, 'w') as f:
1067+
with open(os_helper.TESTFN, 'w') as f:
10671068
cf.write(f)
10681069

10691070
def tearDown(self):
1070-
os.unlink(support.TESTFN)
1071+
os.unlink(os_helper.TESTFN)
10711072

10721073
def test_dominating_multiline_values(self):
10731074
# We're reading from file because this is where the code changed
10741075
# during performance updates in Python 3.2
10751076
cf_from_file = self.newconfig()
1076-
with open(support.TESTFN) as f:
1077+
with open(os_helper.TESTFN) as f:
10771078
cf_from_file.read_file(f)
10781079
self.assertEqual(cf_from_file.get('section8', 'lovely_spam4'),
10791080
self.wonderful_spam.replace('\t\n', '\n'))

Lib/test/test_coroutines.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import unittest
88
import warnings
99
from test import support
10+
from test.support import import_helper
11+
from test.support import warnings_helper
1012
from test.support.script_helper import assert_python_ok
1113

1214

@@ -2117,7 +2119,7 @@ class CoroAsyncIOCompatTest(unittest.TestCase):
21172119
def test_asyncio_1(self):
21182120
# asyncio cannot be imported when Python is compiled without thread
21192121
# support
2120-
asyncio = support.import_module('asyncio')
2122+
asyncio = import_helper.import_module('asyncio')
21212123

21222124
class MyException(Exception):
21232125
pass
@@ -2258,8 +2260,9 @@ async def corofn():
22582260
try:
22592261
warnings._warn_unawaited_coroutine = lambda coro: 1/0
22602262
with support.catch_unraisable_exception() as cm, \
2261-
support.check_warnings((r'coroutine .* was never awaited',
2262-
RuntimeWarning)):
2263+
warnings_helper.check_warnings(
2264+
(r'coroutine .* was never awaited',
2265+
RuntimeWarning)):
22632266
# only store repr() to avoid keeping the coroutine alive
22642267
coro = corofn()
22652268
coro_repr = repr(coro)
@@ -2272,8 +2275,8 @@ async def corofn():
22722275
self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError)
22732276

22742277
del warnings._warn_unawaited_coroutine
2275-
with support.check_warnings((r'coroutine .* was never awaited',
2276-
RuntimeWarning)):
2278+
with warnings_helper.check_warnings(
2279+
(r'coroutine .* was never awaited', RuntimeWarning)):
22772280
corofn()
22782281
support.gc_collect()
22792282

Lib/test/test_curses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import tempfile
1616
import unittest
1717

18-
from test.support import requires, import_module, verbose, SaveSignals
18+
from test.support import requires, verbose, SaveSignals
19+
from test.support.import_helper import import_module
1920

2021
# Optionally test curses module. This currently requires that the
2122
# 'curses' resource be given on the regrtest command line using the -u

Lib/test/test_datetime.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import unittest
22
import sys
33

4-
from test.support import import_fresh_module, run_unittest
4+
from test.support import run_unittest
5+
from test.support.import_helper import import_fresh_module
6+
57

68
TESTS = 'test.datetimetester'
79

Lib/test/test_mmap.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from test.support import (TESTFN, import_module, unlink,
2-
requires, _2G, _4G, gc_collect, cpython_only)
1+
from test.support import (requires, _2G, _4G, gc_collect, cpython_only)
2+
from test.support.import_helper import import_module
3+
from test.support.os_helper import TESTFN, unlink
34
import unittest
45
import os
56
import re

Lib/test/test_signal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import time
1010
import unittest
1111
from test import support
12+
from test.support import os_helper
1213
from test.support.script_helper import assert_python_ok, spawn_python
1314
try:
1415
import _testcapi
@@ -154,7 +155,7 @@ def test_invalid_call(self):
154155
signal.set_wakeup_fd(signal.SIGINT, False)
155156

156157
def test_invalid_fd(self):
157-
fd = support.make_bad_fd()
158+
fd = os_helper.make_bad_fd()
158159
self.assertRaises((ValueError, OSError),
159160
signal.set_wakeup_fd, fd)
160161

0 commit comments

Comments
 (0)