Skip to content

Commit 604bba1

Browse files
authored
bpo-40275: Use new test.support helper submodules in tests (GH-21452)
1 parent da4e09f commit 604bba1

File tree

6 files changed

+62
-54
lines changed

6 files changed

+62
-54
lines changed

Lib/test/eintrdata/eintr_tester.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import unittest
2323

2424
from test import support
25+
from test.support import os_helper
2526
from test.support import socket_helper
2627

2728
@contextlib.contextmanager
@@ -314,16 +315,16 @@ def test_accept(self):
314315
@support.requires_freebsd_version(10, 3)
315316
@unittest.skipUnless(hasattr(os, 'mkfifo'), 'needs mkfifo()')
316317
def _test_open(self, do_open_close_reader, do_open_close_writer):
317-
filename = support.TESTFN
318+
filename = os_helper.TESTFN
318319

319320
# Use a fifo: until the child opens it for reading, the parent will
320321
# block when trying to open it for writing.
321-
support.unlink(filename)
322+
os_helper.unlink(filename)
322323
try:
323324
os.mkfifo(filename)
324325
except PermissionError as e:
325326
self.skipTest('os.mkfifo(): %s' % e)
326-
self.addCleanup(support.unlink, filename)
327+
self.addCleanup(os_helper.unlink, filename)
327328

328329
code = '\n'.join((
329330
'import os, time',
@@ -486,16 +487,16 @@ def test_devpoll(self):
486487

487488
class FNTLEINTRTest(EINTRBaseTest):
488489
def _lock(self, lock_func, lock_name):
489-
self.addCleanup(support.unlink, support.TESTFN)
490+
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
490491
code = '\n'.join((
491492
"import fcntl, time",
492-
"with open('%s', 'wb') as f:" % support.TESTFN,
493+
"with open('%s', 'wb') as f:" % os_helper.TESTFN,
493494
" fcntl.%s(f, fcntl.LOCK_EX)" % lock_name,
494495
" time.sleep(%s)" % self.sleep_time))
495496
start_time = time.monotonic()
496497
proc = self.subprocess(code)
497498
with kill_on_error(proc):
498-
with open(support.TESTFN, 'wb') as f:
499+
with open(os_helper.TESTFN, 'wb') as f:
499500
while True: # synchronize the subprocess
500501
dt = time.monotonic() - start_time
501502
if dt > 60.0:

Lib/test/test_email/test_email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from email import quoprimime
3939

4040
from test.support import threading_helper
41-
from test.support import unlink
41+
from test.support.os_helper import unlink
4242
from test.test_email import openfile, TestEmailBase
4343

4444
# These imports are documented to work, but we are testing them using a

Lib/test/test_multibytecodec.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#
55

66
from test import support
7-
from test.support import TESTFN
7+
from test.support import os_helper
8+
from test.support.os_helper import TESTFN
89
import unittest, io, codecs, sys
910
import _multibytecodec
1011

@@ -57,7 +58,7 @@ def test_codingspec(self):
5758
code = '# coding: {}\n'.format(enc)
5859
exec(code)
5960
finally:
60-
support.unlink(TESTFN)
61+
os_helper.unlink(TESTFN)
6162

6263
def test_init_segfault(self):
6364
# bug #3305: this used to segfault
@@ -296,7 +297,7 @@ def test_bug1728403(self):
296297
finally:
297298
f.close()
298299
finally:
299-
support.unlink(TESTFN)
300+
os_helper.unlink(TESTFN)
300301

301302
class Test_StreamWriter(unittest.TestCase):
302303
def test_gb18030(self):

Lib/test/test_pdb.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from contextlib import ExitStack
1414
from io import StringIO
15-
from test import support
15+
from test.support import os_helper
1616
# This little helper class is essential for testing pdb under doctest.
1717
from test.test_doctest import _FakeInput
1818
from unittest.mock import patch
@@ -1188,10 +1188,10 @@ def test_pdb_issue_20766():
11881188

11891189
class PdbTestCase(unittest.TestCase):
11901190
def tearDown(self):
1191-
support.unlink(support.TESTFN)
1191+
os_helper.unlink(os_helper.TESTFN)
11921192

11931193
def _run_pdb(self, pdb_args, commands):
1194-
self.addCleanup(support.rmtree, '__pycache__')
1194+
self.addCleanup(os_helper.rmtree, '__pycache__')
11951195
cmd = [sys.executable, '-m', 'pdb'] + pdb_args
11961196
with subprocess.Popen(
11971197
cmd,
@@ -1210,31 +1210,31 @@ def run_pdb_script(self, script, commands):
12101210
filename = 'main.py'
12111211
with open(filename, 'w') as f:
12121212
f.write(textwrap.dedent(script))
1213-
self.addCleanup(support.unlink, filename)
1213+
self.addCleanup(os_helper.unlink, filename)
12141214
return self._run_pdb([filename], commands)
12151215

12161216
def run_pdb_module(self, script, commands):
12171217
"""Runs the script code as part of a module"""
12181218
self.module_name = 't_main'
1219-
support.rmtree(self.module_name)
1219+
os_helper.rmtree(self.module_name)
12201220
main_file = self.module_name + '/__main__.py'
12211221
init_file = self.module_name + '/__init__.py'
12221222
os.mkdir(self.module_name)
12231223
with open(init_file, 'w') as f:
12241224
pass
12251225
with open(main_file, 'w') as f:
12261226
f.write(textwrap.dedent(script))
1227-
self.addCleanup(support.rmtree, self.module_name)
1227+
self.addCleanup(os_helper.rmtree, self.module_name)
12281228
return self._run_pdb(['-m', self.module_name], commands)
12291229

12301230
def _assert_find_function(self, file_content, func_name, expected):
1231-
with open(support.TESTFN, 'wb') as f:
1231+
with open(os_helper.TESTFN, 'wb') as f:
12321232
f.write(file_content)
12331233

12341234
expected = None if not expected else (
1235-
expected[0], support.TESTFN, expected[1])
1235+
expected[0], os_helper.TESTFN, expected[1])
12361236
self.assertEqual(
1237-
expected, pdb.find_function(func_name, support.TESTFN))
1237+
expected, pdb.find_function(func_name, os_helper.TESTFN))
12381238

12391239
def test_find_function_empty_file(self):
12401240
self._assert_find_function(b'', 'foo', None)
@@ -1284,9 +1284,9 @@ def bœr():
12841284

12851285
def test_issue7964(self):
12861286
# open the file as binary so we can force \r\n newline
1287-
with open(support.TESTFN, 'wb') as f:
1287+
with open(os_helper.TESTFN, 'wb') as f:
12881288
f.write(b'print("testing my pdb")\r\n')
1289-
cmd = [sys.executable, '-m', 'pdb', support.TESTFN]
1289+
cmd = [sys.executable, '-m', 'pdb', os_helper.TESTFN]
12901290
proc = subprocess.Popen(cmd,
12911291
stdout=subprocess.PIPE,
12921292
stdin=subprocess.PIPE,
@@ -1327,7 +1327,7 @@ def bar():
13271327
"""
13281328
with open('bar.py', 'w') as f:
13291329
f.write(textwrap.dedent(bar))
1330-
self.addCleanup(support.unlink, 'bar.py')
1330+
self.addCleanup(os_helper.unlink, 'bar.py')
13311331
stdout, stderr = self.run_pdb_script(script, commands)
13321332
self.assertTrue(
13331333
any('main.py(5)foo()->None' in l for l in stdout.splitlines()),
@@ -1337,7 +1337,7 @@ def test_issue13120(self):
13371337
# Invoking "continue" on a non-main thread triggered an exception
13381338
# inside signal.signal.
13391339

1340-
with open(support.TESTFN, 'wb') as f:
1340+
with open(os_helper.TESTFN, 'wb') as f:
13411341
f.write(textwrap.dedent("""
13421342
import threading
13431343
import pdb
@@ -1349,7 +1349,7 @@ def start_pdb():
13491349
13501350
t = threading.Thread(target=start_pdb)
13511351
t.start()""").encode('ascii'))
1352-
cmd = [sys.executable, '-u', support.TESTFN]
1352+
cmd = [sys.executable, '-u', os_helper.TESTFN]
13531353
proc = subprocess.Popen(cmd,
13541354
stdout=subprocess.PIPE,
13551355
stdin=subprocess.PIPE,
@@ -1363,7 +1363,7 @@ def start_pdb():
13631363

13641364
def test_issue36250(self):
13651365

1366-
with open(support.TESTFN, 'wb') as f:
1366+
with open(os_helper.TESTFN, 'wb') as f:
13671367
f.write(textwrap.dedent("""
13681368
import threading
13691369
import pdb
@@ -1379,7 +1379,7 @@ def start_pdb():
13791379
pdb.Pdb(readrc=False).set_trace()
13801380
evt.set()
13811381
t.join()""").encode('ascii'))
1382-
cmd = [sys.executable, '-u', support.TESTFN]
1382+
cmd = [sys.executable, '-u', os_helper.TESTFN]
13831383
proc = subprocess.Popen(cmd,
13841384
stdout=subprocess.PIPE,
13851385
stdin=subprocess.PIPE,
@@ -1412,7 +1412,7 @@ def test_readrc_kwarg(self):
14121412

14131413
save_home = os.environ.pop('HOME', None)
14141414
try:
1415-
with support.temp_cwd():
1415+
with os_helper.temp_cwd():
14161416
with open('.pdbrc', 'w') as f:
14171417
f.write("invalid\n")
14181418

@@ -1437,7 +1437,7 @@ def test_readrc_kwarg(self):
14371437

14381438
def test_readrc_homedir(self):
14391439
save_home = os.environ.pop("HOME", None)
1440-
with support.temp_dir() as temp_dir, patch("os.path.expanduser"):
1440+
with os_helper.temp_dir() as temp_dir, patch("os.path.expanduser"):
14411441
rc_path = os.path.join(temp_dir, ".pdbrc")
14421442
os.path.expanduser.return_value = rc_path
14431443
try:
@@ -1506,12 +1506,12 @@ def test_run_pdb_with_pdb(self):
15061506

15071507
def test_module_without_a_main(self):
15081508
module_name = 't_main'
1509-
support.rmtree(module_name)
1509+
os_helper.rmtree(module_name)
15101510
init_file = module_name + '/__init__.py'
15111511
os.mkdir(module_name)
15121512
with open(init_file, 'w') as f:
15131513
pass
1514-
self.addCleanup(support.rmtree, module_name)
1514+
self.addCleanup(os_helper.rmtree, module_name)
15151515
stdout, stderr = self._run_pdb(['-m', module_name], "")
15161516
self.assertIn("ImportError: No module named t_main.__main__",
15171517
stdout.splitlines())
@@ -1531,11 +1531,11 @@ def test_blocks_at_first_code_line(self):
15311531

15321532
def test_relative_imports(self):
15331533
self.module_name = 't_main'
1534-
support.rmtree(self.module_name)
1534+
os_helper.rmtree(self.module_name)
15351535
main_file = self.module_name + '/__main__.py'
15361536
init_file = self.module_name + '/__init__.py'
15371537
module_file = self.module_name + '/module.py'
1538-
self.addCleanup(support.rmtree, self.module_name)
1538+
self.addCleanup(os_helper.rmtree, self.module_name)
15391539
os.mkdir(self.module_name)
15401540
with open(init_file, 'w') as f:
15411541
f.write(textwrap.dedent("""
@@ -1569,11 +1569,11 @@ def test_relative_imports(self):
15691569
def test_relative_imports_on_plain_module(self):
15701570
# Validates running a plain module. See bpo32691
15711571
self.module_name = 't_main'
1572-
support.rmtree(self.module_name)
1572+
os_helper.rmtree(self.module_name)
15731573
main_file = self.module_name + '/runme.py'
15741574
init_file = self.module_name + '/__init__.py'
15751575
module_file = self.module_name + '/module.py'
1576-
self.addCleanup(support.rmtree, self.module_name)
1576+
self.addCleanup(os_helper.rmtree, self.module_name)
15771577
os.mkdir(self.module_name)
15781578
with open(init_file, 'w') as f:
15791579
f.write(textwrap.dedent("""

Lib/test/test_urllib2_localnet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import unittest
99
import hashlib
1010

11-
from test import support
1211
from test.support import hashlib_helper
1312
from test.support import threading_helper
13+
from test.support import warnings_helper
1414

1515
try:
1616
import ssl
@@ -567,7 +567,7 @@ def test_https(self):
567567

568568
def test_https_with_cafile(self):
569569
handler = self.start_https_server(certfile=CERT_localhost)
570-
with support.check_warnings(('', DeprecationWarning)):
570+
with warnings_helper.check_warnings(('', DeprecationWarning)):
571571
# Good cert
572572
data = self.urlopen("https://localhost:%s/bizarre" % handler.port,
573573
cafile=CERT_localhost)
@@ -585,7 +585,7 @@ def test_https_with_cafile(self):
585585
def test_https_with_cadefault(self):
586586
handler = self.start_https_server(certfile=CERT_localhost)
587587
# Self-signed cert should fail verification with system certificate store
588-
with support.check_warnings(('', DeprecationWarning)):
588+
with warnings_helper.check_warnings(('', DeprecationWarning)):
589589
with self.assertRaises(urllib.error.URLError) as cm:
590590
self.urlopen("https://localhost:%s/bizarre" % handler.port,
591591
cadefault=True)

0 commit comments

Comments
 (0)