Skip to content

Commit d4f0586

Browse files
committed
Use new test.support helper submodules in tests
1 parent c7decc2 commit d4f0586

20 files changed

+73
-56
lines changed

Lib/test/test_dbm_gnu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
gdbm = import_helper.import_module("dbm.gnu") #skip if not supported
44
import unittest
55
import os
6-
from test.support import TESTFN, TESTFN_NONASCII, unlink
6+
from test.support.os_helper import TESTFN, TESTFN_NONASCII, unlink
77

88

99
filename = TESTFN

Lib/test/test_faulthandler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import sysconfig
99
from test import support
10+
from test.support import os_helper
1011
from test.support import script_helper, is_android
1112
import tempfile
1213
import unittest
@@ -51,7 +52,7 @@ def temporary_filename():
5152
try:
5253
yield filename
5354
finally:
54-
support.unlink(filename)
55+
os_helper.unlink(filename)
5556

5657
class FaultHandlerTests(unittest.TestCase):
5758
def get_output(self, code, filename=None, fd=None):

Lib/test/test_grp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Test script for the grp module."""
22

33
import unittest
4-
from test import support
4+
from test.support import import_helper
55

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

89
class GroupDatabaseTestCase(unittest.TestCase):
910

Lib/test/test_http_cookiejar.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import re
55
import test.support
6+
from test.support import os_helper
7+
from test.support import warnings_helper
68
import time
79
import unittest
810
import urllib.request
@@ -328,12 +330,12 @@ def _interact(cookiejar, url, set_cookie_hdrs, hdr_name):
328330

329331
class FileCookieJarTests(unittest.TestCase):
330332
def test_constructor_with_str(self):
331-
filename = test.support.TESTFN
333+
filename = os_helper.TESTFN
332334
c = LWPCookieJar(filename)
333335
self.assertEqual(c.filename, filename)
334336

335337
def test_constructor_with_path_like(self):
336-
filename = pathlib.Path(test.support.TESTFN)
338+
filename = pathlib.Path(os_helper.TESTFN)
337339
c = LWPCookieJar(filename)
338340
self.assertEqual(c.filename, os.fspath(filename))
339341

@@ -353,7 +355,7 @@ class A:
353355

354356
def test_lwp_valueless_cookie(self):
355357
# cookies with no value should be saved and loaded consistently
356-
filename = test.support.TESTFN
358+
filename = os_helper.TESTFN
357359
c = LWPCookieJar()
358360
interact_netscape(c, "http://www.acme.com/", 'boo')
359361
self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
@@ -368,7 +370,7 @@ def test_lwp_valueless_cookie(self):
368370

369371
def test_bad_magic(self):
370372
# OSErrors (eg. file doesn't exist) are allowed to propagate
371-
filename = test.support.TESTFN
373+
filename = os_helper.TESTFN
372374
for cookiejar_class in LWPCookieJar, MozillaCookieJar:
373375
c = cookiejar_class()
374376
try:
@@ -475,7 +477,7 @@ def test_domain_return_ok(self):
475477
def test_missing_value(self):
476478
# missing = sign in Cookie: header is regarded by Mozilla as a missing
477479
# name, and by http.cookiejar as a missing value
478-
filename = test.support.TESTFN
480+
filename = os_helper.TESTFN
479481
c = MozillaCookieJar(filename)
480482
interact_netscape(c, "http://www.acme.com/", 'eggs')
481483
interact_netscape(c, "http://www.acme.com/", '"spam"; path=/foo/')
@@ -599,7 +601,7 @@ def test_expires(self):
599601
c = CookieJar()
600602
future = time2netscape(time.time()+3600)
601603

602-
with test.support.check_no_warnings(self):
604+
with warnings_helper.check_no_warnings(self):
603605
headers = [f"Set-Cookie: FOO=BAR; path=/; expires={future}"]
604606
req = urllib.request.Request("http://www.coyote.com/")
605607
res = FakeResponse(headers, "http://www.coyote.com/")
@@ -1713,7 +1715,7 @@ def test_rejection(self):
17131715
self.assertEqual(len(c), 6)
17141716

17151717
# save and restore
1716-
filename = test.support.TESTFN
1718+
filename = os_helper.TESTFN
17171719

17181720
try:
17191721
c.save(filename, ignore_discard=True)
@@ -1753,7 +1755,7 @@ def test_mozilla(self):
17531755
# Save / load Mozilla/Netscape cookie file format.
17541756
year_plus_one = time.localtime()[0] + 1
17551757

1756-
filename = test.support.TESTFN
1758+
filename = os_helper.TESTFN
17571759

17581760
c = MozillaCookieJar(filename,
17591761
policy=DefaultCookiePolicy(rfc2965=True))

Lib/test/test_httpservers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def stop(self):
6767
class BaseTestCase(unittest.TestCase):
6868
def setUp(self):
6969
self._threads = threading_helper.threading_setup()
70-
os.environ = support.EnvironmentVarGuard()
70+
os.environ = os_helper.EnvironmentVarGuard()
7171
self.server_started = threading.Event()
7272
self.thread = TestServerThread(self, self.request_handler)
7373
self.thread.start()
@@ -621,7 +621,7 @@ def setUp(self):
621621
# The shebang line should be pure ASCII: use symlink if possible.
622622
# See issue #7668.
623623
self._pythonexe_symlink = None
624-
if support.can_symlink():
624+
if os_helper.can_symlink():
625625
self.pythonexe = os.path.join(self.parent_dir, 'python')
626626
self._pythonexe_symlink = support.PythonSymlink(self.pythonexe).__enter__()
627627
else:

Lib/test/test_import/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import unittest
1919
from unittest import mock
2020

21-
import test.support
2221
from test.support import os_helper
2322
from test.support import (is_jython, swap_attr, swap_item, cpython_only)
2423
from test.support.import_helper import (
@@ -480,7 +479,7 @@ def test_dll_dependency_import(self):
480479
os.path.dirname(pydname),
481480
"sqlite3{}.dll".format("_d" if "_d" in pydname else ""))
482481

483-
with test.support.temp_dir() as tmp:
482+
with os_helper.temp_dir() as tmp:
484483
tmp2 = os.path.join(tmp, "DLLs")
485484
os.mkdir(tmp2)
486485

Lib/test/test_ntpath.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def test_realpath_relative(self):
285285
def test_realpath_broken_symlinks(self):
286286
ABSTFN = ntpath.abspath(os_helper.TESTFN)
287287
os.mkdir(ABSTFN)
288-
self.addCleanup(support.rmtree, ABSTFN)
288+
self.addCleanup(os_helper.rmtree, ABSTFN)
289289

290290
with support.change_cwd(ABSTFN):
291291
os.mkdir("subdir")
@@ -427,9 +427,9 @@ def test_realpath_cwd(self):
427427
ABSTFN = ntpath.abspath(os_helper.TESTFN)
428428

429429
os_helper.unlink(ABSTFN)
430-
support.rmtree(ABSTFN)
430+
os_helper.rmtree(ABSTFN)
431431
os.mkdir(ABSTFN)
432-
self.addCleanup(support.rmtree, ABSTFN)
432+
self.addCleanup(os_helper.rmtree, ABSTFN)
433433

434434
test_dir_long = ntpath.join(ABSTFN, "MyVeryLongDirectoryName")
435435
os.mkdir(test_dir_long)

Lib/test/test_site.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import unittest
88
import test.support
99
from test import support
10+
from test.support import os_helper
1011
from test.support import socket_helper
1112
from test.support import captured_stderr
1213
from test.support.os_helper import TESTFN, EnvironmentVarGuard, change_cwd
@@ -601,7 +602,7 @@ class _pthFileTests(unittest.TestCase):
601602
def _create_underpth_exe(self, lines, exe_pth=True):
602603
import _winapi
603604
temp_dir = tempfile.mkdtemp()
604-
self.addCleanup(test.support.rmtree, temp_dir)
605+
self.addCleanup(os_helper.rmtree, temp_dir)
605606
exe_file = os.path.join(temp_dir, os.path.split(sys.executable)[1])
606607
dll_src_file = _winapi.GetModuleFileName(sys.dllhandle)
607608
dll_file = os.path.join(temp_dir, os.path.split(dll_src_file)[1])

Lib/test/test_socketserver.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import test.support
1717
from test.support import reap_children, verbose
18+
from test.support import os_helper
1819
from test.support import socket_helper
1920
from test.support import threading_helper
2021

@@ -299,7 +300,7 @@ class ErrorHandlerTest(unittest.TestCase):
299300
KeyboardInterrupt are not passed."""
300301

301302
def tearDown(self):
302-
test.support.unlink(test.support.TESTFN)
303+
os_helper.unlink(os_helper.TESTFN)
303304

304305
def test_sync_handled(self):
305306
BaseErrorTestServer(ValueError)
@@ -329,7 +330,7 @@ def test_forking_not_handled(self):
329330
self.check_result(handled=False)
330331

331332
def check_result(self, handled):
332-
with open(test.support.TESTFN) as log:
333+
with open(os_helper.TESTFN) as log:
333334
expected = 'Handler called\n' + 'Error handled\n' * handled
334335
self.assertEqual(log.read(), expected)
335336

@@ -347,7 +348,7 @@ def __init__(self, exception):
347348
self.wait_done()
348349

349350
def handle_error(self, request, client_address):
350-
with open(test.support.TESTFN, 'a') as log:
351+
with open(os_helper.TESTFN, 'a') as log:
351352
log.write('Error handled\n')
352353

353354
def wait_done(self):
@@ -356,7 +357,7 @@ def wait_done(self):
356357

357358
class BadHandler(socketserver.BaseRequestHandler):
358359
def handle(self):
359-
with open(test.support.TESTFN, 'a') as log:
360+
with open(os_helper.TESTFN, 'a') as log:
360361
log.write('Handler called\n')
361362
raise self.server.exception('Test error')
362363

Lib/test/test_statistics.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import sys
1616
import unittest
1717
from test import support
18+
from test.support import import_helper
1819

1920
from decimal import Decimal
2021
from fractions import Fraction
21-
from test import support
2222

2323

2424
# Module to be tested.
@@ -179,8 +179,10 @@ class _DoNothing:
179179
# We prefer this for testing numeric values that may not be exactly equal,
180180
# and avoid using TestCase.assertAlmostEqual, because it sucks :-)
181181

182-
py_statistics = support.import_fresh_module('statistics', blocked=['_statistics'])
183-
c_statistics = support.import_fresh_module('statistics', fresh=['_statistics'])
182+
py_statistics = import_helper.import_fresh_module('statistics',
183+
blocked=['_statistics'])
184+
c_statistics = import_helper.import_fresh_module('statistics',
185+
fresh=['_statistics'])
184186

185187

186188
class TestModules(unittest.TestCase):

Lib/test/test_tabnanny.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import tempfile
1313
import textwrap
1414
from test.support import (captured_stderr, captured_stdout, script_helper,
15-
findfile, unlink)
15+
findfile)
16+
from test.support.os_helper import unlink
1617

1718

1819
SOURCE_CODES = {

Lib/test/test_tcl.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import warnings
77
from test import support
88
from test.support import import_helper
9+
from test.support import os_helper
910

1011
# Skip this test if the _tkinter module wasn't built.
1112
_tkinter = import_helper.import_module('_tkinter')
@@ -192,26 +193,26 @@ def test_getboolean(self):
192193

193194
def testEvalFile(self):
194195
tcl = self.interp
195-
with open(support.TESTFN, 'w') as f:
196-
self.addCleanup(support.unlink, support.TESTFN)
196+
with open(os_helper.TESTFN, 'w') as f:
197+
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
197198
f.write("""set a 1
198199
set b 2
199200
set c [ expr $a + $b ]
200201
""")
201-
tcl.evalfile(support.TESTFN)
202+
tcl.evalfile(os_helper.TESTFN)
202203
self.assertEqual(tcl.eval('set a'),'1')
203204
self.assertEqual(tcl.eval('set b'),'2')
204205
self.assertEqual(tcl.eval('set c'),'3')
205206

206207
def test_evalfile_null_in_result(self):
207208
tcl = self.interp
208-
with open(support.TESTFN, 'w') as f:
209-
self.addCleanup(support.unlink, support.TESTFN)
209+
with open(os_helper.TESTFN, 'w') as f:
210+
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
210211
f.write("""
211212
set a "a\0b"
212213
set b "a\\0b"
213214
""")
214-
tcl.evalfile(support.TESTFN)
215+
tcl.evalfile(os_helper.TESTFN)
215216
self.assertEqual(tcl.eval('set a'), 'a\x00b')
216217
self.assertEqual(tcl.eval('set b'), 'a\x00b')
217218

@@ -243,7 +244,7 @@ def testLoadWithUNC(self):
243244
if not os.path.exists(unc_name):
244245
raise unittest.SkipTest('Cannot connect to UNC Path')
245246

246-
with support.EnvironmentVarGuard() as env:
247+
with os_helper.EnvironmentVarGuard() as env:
247248
env.unset("TCL_LIBRARY")
248249
stdout = subprocess.check_output(
249250
[unc_name, '-c', 'import tkinter; print(tkinter)'])

Lib/test/test_tools/test_md5sum.py

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

33
import os
44
import unittest
5-
from test import support
5+
from test.support import os_helper
66
from test.support import hashlib_helper
77
from test.support.script_helper import assert_python_ok, assert_python_failure
88

@@ -15,16 +15,16 @@ class MD5SumTests(unittest.TestCase):
1515
@classmethod
1616
def setUpClass(cls):
1717
cls.script = os.path.join(scriptsdir, 'md5sum.py')
18-
os.mkdir(support.TESTFN)
19-
cls.fodder = os.path.join(support.TESTFN, 'md5sum.fodder')
18+
os.mkdir(os_helper.TESTFN)
19+
cls.fodder = os.path.join(os_helper.TESTFN, 'md5sum.fodder')
2020
with open(cls.fodder, 'wb') as f:
2121
f.write(b'md5sum\r\ntest file\r\n')
2222
cls.fodder_md5 = b'd38dae2eb1ab346a292ef6850f9e1a0d'
2323
cls.fodder_textmode_md5 = b'a8b07894e2ca3f2a4c3094065fa6e0a5'
2424

2525
@classmethod
2626
def tearDownClass(cls):
27-
support.rmtree(support.TESTFN)
27+
os_helper.rmtree(os_helper.TESTFN)
2828

2929
def test_noargs(self):
3030
rc, out, err = assert_python_ok(self.script)

Lib/test/test_turtle.py

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

67

78
turtle = import_helper.import_module('turtle')
@@ -52,10 +53,10 @@
5253
class TurtleConfigTest(unittest.TestCase):
5354

5455
def get_cfg_file(self, cfg_str):
55-
self.addCleanup(support.unlink, support.TESTFN)
56-
with open(support.TESTFN, 'w') as f:
56+
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
57+
with open(os_helper.TESTFN, 'w') as f:
5758
f.write(cfg_str)
58-
return support.TESTFN
59+
return os_helper.TESTFN
5960

6061
def test_config_dict(self):
6162

Lib/test/test_urllib2net.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import errno
22
import unittest
33
from test import support
4+
from test.support import os_helper
45
from test.support import socket_helper
56
from test.test_urllib2 import sanepathname2url
67

@@ -148,7 +149,7 @@ def test_ftp(self):
148149
self._test_urls(urls, self._extra_handlers())
149150

150151
def test_file(self):
151-
TESTFN = support.TESTFN
152+
TESTFN = os_helper.TESTFN
152153
f = open(TESTFN, 'w')
153154
try:
154155
f.write('hi there\n')

0 commit comments

Comments
 (0)