Skip to content

Commit f592ee3

Browse files
committed
Use new test.support helper submodules in tests
1 parent 79bb2c9 commit f592ee3

15 files changed

+96
-84
lines changed

Lib/ctypes/test/test_loading.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import unittest
77
import test.support
8+
from test.support import import_helper
89
from ctypes.util import find_library
910

1011
libc_name = None
@@ -117,7 +118,7 @@ def test_1703286_B(self):
117118
@unittest.skipUnless(os.name == "nt",
118119
'test specific to Windows')
119120
def test_load_dll_with_flags(self):
120-
_sqlite3 = test.support.import_module("_sqlite3")
121+
_sqlite3 = import_helper.import_module("_sqlite3")
121122
src = _sqlite3.__file__
122123
if src.lower().endswith("_d.pyd"):
123124
ext = "_d.dll"

Lib/sqlite3/test/hooks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import unittest
2525
import sqlite3 as sqlite
2626

27-
from test.support import TESTFN, unlink
27+
from test.support.os_helper import TESTFN, unlink
28+
2829

2930
class CollationTests(unittest.TestCase):
3031
def CheckCreateCollationNotString(self):

Lib/test/_test_multiprocessing.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
from test import support
2929
from test.support import hashlib_helper
3030
from test.support import import_helper
31+
from test.support import os_helper
3132
from test.support import socket_helper
3233
from test.support import threading_helper
34+
from test.support import warnings_helper
3335

3436

3537
# Skip tests if _multiprocessing wasn't built.
@@ -615,7 +617,7 @@ def test_lose_target_ref(self):
615617

616618
@classmethod
617619
def _test_child_fd_inflation(self, evt, q):
618-
q.put(test.support.fd_count())
620+
q.put(os_helper.fd_count())
619621
evt.wait()
620622

621623
def test_child_fd_inflation(self):
@@ -819,8 +821,8 @@ def test_stderr_flush(self):
819821
if self.TYPE == "threads":
820822
self.skipTest('test not appropriate for {}'.format(self.TYPE))
821823

822-
testfn = test.support.TESTFN
823-
self.addCleanup(test.support.unlink, testfn)
824+
testfn = os_helper.TESTFN
825+
self.addCleanup(os_helper.unlink, testfn)
824826
proc = self.Process(target=self._test_stderr_flush, args=(testfn,))
825827
proc.start()
826828
proc.join()
@@ -849,8 +851,8 @@ def test_sys_exit(self):
849851
if self.TYPE == 'threads':
850852
self.skipTest('test not appropriate for {}'.format(self.TYPE))
851853

852-
testfn = test.support.TESTFN
853-
self.addCleanup(test.support.unlink, testfn)
854+
testfn = os_helper.TESTFN
855+
self.addCleanup(os_helper.unlink, testfn)
854856

855857
for reason in (
856858
[1, 2, 3],
@@ -1114,7 +1116,7 @@ def test_task_done(self):
11141116
close_queue(queue)
11151117

11161118
def test_no_import_lock_contention(self):
1117-
with test.support.temp_cwd():
1119+
with os_helper.temp_cwd():
11181120
module_name = 'imported_by_an_imported_module'
11191121
with open(module_name + '.py', 'w') as f:
11201122
f.write("""if 1:
@@ -1127,7 +1129,7 @@ def test_no_import_lock_contention(self):
11271129
del q
11281130
""")
11291131

1130-
with test.support.DirsOnSysPath(os.getcwd()):
1132+
with os_helper.DirsOnSysPath(os.getcwd()):
11311133
try:
11321134
__import__(module_name)
11331135
except pyqueue.Empty:
@@ -2688,8 +2690,8 @@ def test_resource_warning(self):
26882690
# force state to RUN to emit ResourceWarning in __del__()
26892691
pool._state = multiprocessing.pool.RUN
26902692

2691-
with support.check_warnings(('unclosed running multiprocessing pool',
2692-
ResourceWarning)):
2693+
with warnings_helper.check_warnings(
2694+
('unclosed running multiprocessing pool', ResourceWarning)):
26932695
pool = None
26942696
support.gc_collect()
26952697

@@ -3199,14 +3201,14 @@ def test_fd_transfer(self):
31993201
p = self.Process(target=self._writefd, args=(child_conn, b"foo"))
32003202
p.daemon = True
32013203
p.start()
3202-
self.addCleanup(test.support.unlink, test.support.TESTFN)
3203-
with open(test.support.TESTFN, "wb") as f:
3204+
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
3205+
with open(os_helper.TESTFN, "wb") as f:
32043206
fd = f.fileno()
32053207
if msvcrt:
32063208
fd = msvcrt.get_osfhandle(fd)
32073209
reduction.send_handle(conn, fd, p.pid)
32083210
p.join()
3209-
with open(test.support.TESTFN, "rb") as f:
3211+
with open(os_helper.TESTFN, "rb") as f:
32103212
self.assertEqual(f.read(), b"foo")
32113213

32123214
@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
@@ -3225,8 +3227,8 @@ def test_large_fd_transfer(self):
32253227
p = self.Process(target=self._writefd, args=(child_conn, b"bar", True))
32263228
p.daemon = True
32273229
p.start()
3228-
self.addCleanup(test.support.unlink, test.support.TESTFN)
3229-
with open(test.support.TESTFN, "wb") as f:
3230+
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
3231+
with open(os_helper.TESTFN, "wb") as f:
32303232
fd = f.fileno()
32313233
for newfd in range(256, MAXFD):
32323234
if not self._is_fd_assigned(newfd):
@@ -3239,7 +3241,7 @@ def test_large_fd_transfer(self):
32393241
finally:
32403242
os.close(newfd)
32413243
p.join()
3242-
with open(test.support.TESTFN, "rb") as f:
3244+
with open(os_helper.TESTFN, "rb") as f:
32433245
self.assertEqual(f.read(), b"bar")
32443246

32453247
@classmethod

Lib/test/test___all__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22
from test import support
3+
from test.support import warnings_helper
34
import os
45
import sys
56

@@ -15,7 +16,7 @@ class AllTest(unittest.TestCase):
1516

1617
def check_all(self, modname):
1718
names = {}
18-
with support.check_warnings(
19+
with warnings_helper.check_warnings(
1920
(".* (module|package)", DeprecationWarning),
2021
(".* (module|package)", PendingDeprecationWarning),
2122
("", ResourceWarning),
@@ -31,7 +32,7 @@ def check_all(self, modname):
3132
raise NoAll(modname)
3233
names = {}
3334
with self.subTest(module=modname):
34-
with support.check_warnings(
35+
with warnings_helper.check_warnings(
3536
("", DeprecationWarning),
3637
("", ResourceWarning),
3738
quiet=True):

Lib/test/test_asyncio/test_proactor_events.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from asyncio.proactor_events import _ProactorWritePipeTransport
1313
from asyncio.proactor_events import _ProactorDuplexPipeTransport
1414
from asyncio.proactor_events import _ProactorDatagramTransport
15-
from test import support
1615
from test.support import socket_helper
1716
from test.test_asyncio import utils as test_utils
1817

@@ -935,20 +934,20 @@ async def wait_closed(self):
935934

936935
@classmethod
937936
def setUpClass(cls):
938-
with open(support.TESTFN, 'wb') as fp:
937+
with open(os_helper.TESTFN, 'wb') as fp:
939938
fp.write(cls.DATA)
940939
super().setUpClass()
941940

942941
@classmethod
943942
def tearDownClass(cls):
944-
support.unlink(support.TESTFN)
943+
os_helper.unlink(os_helper.TESTFN)
945944
super().tearDownClass()
946945

947946
def setUp(self):
948947
self.loop = asyncio.ProactorEventLoop()
949948
self.set_event_loop(self.loop)
950949
self.addCleanup(self.loop.close)
951-
self.file = open(support.TESTFN, 'rb')
950+
self.file = open(os_helper.TESTFN, 'rb')
952951
self.addCleanup(self.file.close)
953952
super().setUp()
954953

Lib/test/test_ntpath.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from test.support import os_helper
77
from test.support import TestFailed
88
from test.support.os_helper import FakePath
9-
from test import support, test_genericpath
9+
from test import test_genericpath
1010
from tempfile import TemporaryFile
1111

1212

@@ -287,7 +287,7 @@ def test_realpath_broken_symlinks(self):
287287
os.mkdir(ABSTFN)
288288
self.addCleanup(os_helper.rmtree, ABSTFN)
289289

290-
with support.change_cwd(ABSTFN):
290+
with os_helper.change_cwd(ABSTFN):
291291
os.mkdir("subdir")
292292
os.chdir("subdir")
293293
os.symlink(".", "recursive")
@@ -443,11 +443,11 @@ def test_realpath_cwd(self):
443443

444444
self.assertPathEqual(test_file_long, ntpath.realpath(test_file_short))
445445

446-
with support.change_cwd(test_dir_long):
446+
with os_helper.change_cwd(test_dir_long):
447447
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
448-
with support.change_cwd(test_dir_long.lower()):
448+
with os_helper.change_cwd(test_dir_long.lower()):
449449
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
450-
with support.change_cwd(test_dir_short):
450+
with os_helper.change_cwd(test_dir_short):
451451
self.assertPathEqual(test_file_long, ntpath.realpath("file.txt"))
452452

453453
def test_expandvars(self):
@@ -673,7 +673,7 @@ def test_ismount(self):
673673
# locations below cannot then refer to mount points
674674
#
675675
drive, path = ntpath.splitdrive(sys.executable)
676-
with support.change_cwd(ntpath.dirname(sys.executable)):
676+
with os_helper.change_cwd(ntpath.dirname(sys.executable)):
677677
self.assertFalse(ntpath.ismount(drive.lower()))
678678
self.assertFalse(ntpath.ismount(drive.upper()))
679679

Lib/test/test_ossaudiodev.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from test import support
2+
from test.support import import_helper
23
support.requires('audio')
34

45
from test.support import findfile
56

6-
ossaudiodev = support.import_module('ossaudiodev')
7+
ossaudiodev = import_helper.import_module('ossaudiodev')
78

89
import errno
910
import sys

Lib/test/test_platform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_uname_win32_ARCHITEW6432(self):
196196
# using it, per
197197
# http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx
198198
try:
199-
with support.EnvironmentVarGuard() as environ:
199+
with os_helper.EnvironmentVarGuard() as environ:
200200
if 'PROCESSOR_ARCHITEW6432' in environ:
201201
del environ['PROCESSOR_ARCHITEW6432']
202202
environ['PROCESSOR_ARCHITECTURE'] = 'foo'

0 commit comments

Comments
 (0)