Skip to content

Commit fcce8c6

Browse files
authored
bpo-40275: Use new test.support helper submodules in tests (GH-21772)
1 parent e27a51c commit fcce8c6

File tree

8 files changed

+27
-18
lines changed

8 files changed

+27
-18
lines changed

Lib/sqlite3/test/dbapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import unittest
2626
import sqlite3 as sqlite
2727

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

3030

3131
class ModuleTests(unittest.TestCase):

Lib/test/libregrtest/refleak.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import warnings
55
from inspect import isabstract
66
from test import support
7+
from test.support import os_helper
8+
79
try:
810
from _abc import _get_dump
911
except ImportError:
@@ -61,7 +63,7 @@ def get_pooled_int(value):
6163
return int_pool.setdefault(value, value)
6264

6365
nwarmup, ntracked, fname = ns.huntrleaks
64-
fname = os.path.join(support.SAVEDCWD, fname)
66+
fname = os.path.join(os_helper.SAVEDCWD, fname)
6567
repcount = nwarmup + ntracked
6668

6769
# Pre-allocate to ensure that the loop doesn't allocate anything new
@@ -71,7 +73,7 @@ def get_pooled_int(value):
7173
fd_deltas = [0] * repcount
7274
getallocatedblocks = sys.getallocatedblocks
7375
gettotalrefcount = sys.gettotalrefcount
74-
fd_count = support.fd_count
76+
fd_count = os_helper.fd_count
7577

7678
# initialize variables to make pyflakes quiet
7779
rc_before = alloc_before = fd_before = 0

Lib/test/libregrtest/win_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import subprocess
66
import uuid
77
import winreg
8-
from test import support
8+
from test.support import os_helper
99
from test.libregrtest.utils import print_warning
1010

1111

@@ -69,7 +69,9 @@ def start(self):
6969
# Spawn off the load monitor
7070
counter_name = self._get_counter_name()
7171
command = ['typeperf', counter_name, '-si', str(SAMPLING_INTERVAL)]
72-
self._popen = subprocess.Popen(' '.join(command), stdout=command_stdout, cwd=support.SAVEDCWD)
72+
self._popen = subprocess.Popen(' '.join(command),
73+
stdout=command_stdout,
74+
cwd=os_helper.SAVEDCWD)
7375

7476
# Close our copy of the write end of the pipe
7577
os.close(command_stdout)

Lib/test/test_audit.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import sys
66
import unittest
77
from test import support
8+
from test.support import import_helper
9+
from test.support import os_helper
10+
811

912
if not hasattr(sys, "addaudithook") or not hasattr(sys, "audit"):
1013
raise unittest.SkipTest("test only relevant when sys.audit is available")
@@ -52,15 +55,15 @@ def test_block_add_hook_baseexception(self):
5255
self.do_test("test_block_add_hook_baseexception")
5356

5457
def test_pickle(self):
55-
support.import_module("pickle")
58+
import_helper.import_module("pickle")
5659

5760
self.do_test("test_pickle")
5861

5962
def test_monkeypatch(self):
6063
self.do_test("test_monkeypatch")
6164

6265
def test_open(self):
63-
self.do_test("test_open", support.TESTFN)
66+
self.do_test("test_open", os_helper.TESTFN)
6467

6568
def test_cantrace(self):
6669
self.do_test("test_cantrace")
@@ -89,7 +92,7 @@ def test_unraisablehook(self):
8992
)
9093

9194
def test_winreg(self):
92-
support.import_module("winreg")
95+
import_helper.import_module("winreg")
9396
returncode, events, stderr = self.run_python("test_winreg")
9497
if returncode:
9598
self.fail(stderr)
@@ -103,7 +106,7 @@ def test_winreg(self):
103106
self.assertSequenceEqual(["winreg.PyHKEY.Detach", " ", expected], events[4])
104107

105108
def test_socket(self):
106-
support.import_module("socket")
109+
import_helper.import_module("socket")
107110
returncode, events, stderr = self.run_python("test_socket")
108111
if returncode:
109112
self.fail(stderr)

Lib/test/test_bytes.py

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

1818
import test.support
1919
from test.support import import_helper
20+
from test.support import warnings_helper
2021
import test.string_tests
2122
import test.list_tests
2223
from test.support import bigaddrspacetest, MAX_Py_ssize_t
@@ -27,7 +28,7 @@
2728
def check_bytes_warnings(func):
2829
@functools.wraps(func)
2930
def wrapper(*args, **kw):
30-
with test.support.check_warnings(('', BytesWarning)):
31+
with warnings_helper.check_warnings(('', BytesWarning)):
3132
return func(*args, **kw)
3233
return wrapper
3334
else:
@@ -1769,7 +1770,7 @@ def test_return_self(self):
17691770
"BytesWarning is needed for this test: use -bb option")
17701771
def test_compare(self):
17711772
def bytes_warning():
1772-
return test.support.check_warnings(('', BytesWarning))
1773+
return warnings_helper.check_warnings(('', BytesWarning))
17731774
with bytes_warning():
17741775
b'' == ''
17751776
with bytes_warning():

Lib/test/test_dbm_ndbm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from test import support
22
from test.support import import_helper
3+
from test.support import os_helper
34
import_helper.import_module("dbm.ndbm") #skip if not supported
45
import os
56
import unittest
@@ -9,7 +10,7 @@
910
class DbmTestCase(unittest.TestCase):
1011

1112
def setUp(self):
12-
self.filename = support.TESTFN
13+
self.filename = os_helper.TESTFN
1314
self.d = dbm.ndbm.open(self.filename, 'c')
1415
self.d.close()
1516

@@ -102,10 +103,10 @@ def test_write_readonly_file(self):
102103
with self.assertRaises(error):
103104
db[b'not exist key'] = b'not exist value'
104105

105-
@unittest.skipUnless(support.TESTFN_NONASCII,
106+
@unittest.skipUnless(os_helper.TESTFN_NONASCII,
106107
'requires OS support of non-ASCII encodings')
107108
def test_nonascii_filename(self):
108-
filename = support.TESTFN_NONASCII
109+
filename = os_helper.TESTFN_NONASCII
109110
for suffix in ['', '.pag', '.dir', '.db']:
110111
self.addCleanup(support.unlink, filename + suffix)
111112
with dbm.ndbm.open(filename, 'c') as db:

Lib/test/test_descr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,12 +2975,12 @@ class sublist(list):
29752975
## self.ateof = 1
29762976
## return s
29772977
##
2978-
## f = file(name=support.TESTFN, mode='w')
2978+
## f = file(name=os_helper.TESTFN, mode='w')
29792979
## lines = ['a\n', 'b\n', 'c\n']
29802980
## try:
29812981
## f.writelines(lines)
29822982
## f.close()
2983-
## f = CountedInput(support.TESTFN)
2983+
## f = CountedInput(os_helper.TESTFN)
29842984
## for (i, expected) in zip(range(1, 5) + [4], lines + 2 * [""]):
29852985
## got = f.readline()
29862986
## self.assertEqual(expected, got)
@@ -2992,7 +2992,7 @@ class sublist(list):
29922992
## f.close()
29932993
## except:
29942994
## pass
2995-
## support.unlink(support.TESTFN)
2995+
## os_helper.unlink(os_helper.TESTFN)
29962996

29972997
def test_keywords(self):
29982998
# Testing keyword args to basic type constructors ...

Lib/test/test_xml_etree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
def checkwarnings(*filters, quiet=False):
112112
def decorator(test):
113113
def newtest(*args, **kwargs):
114-
with support.check_warnings(*filters, quiet=quiet):
114+
with warnings_helper.check_warnings(*filters, quiet=quiet):
115115
test(*args, **kwargs)
116116
functools.update_wrapper(newtest, test)
117117
return newtest

0 commit comments

Comments
 (0)