Skip to content

Commit 06a40d7

Browse files
authored
bpo-40275: Use new test.support helper submodules in tests (GH-20824)
1 parent 91698d8 commit 06a40d7

File tree

9 files changed

+29
-21
lines changed

9 files changed

+29
-21
lines changed

Lib/test/support/socket_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def skip_unless_bind_unix_socket(test):
146146
return unittest.skip('No UNIX Sockets')(test)
147147
global _bind_nix_socket_error
148148
if _bind_nix_socket_error is None:
149-
from test.support import TESTFN, unlink
149+
from .os_helper import TESTFN, unlink
150150
path = TESTFN + "can_bind_unix_socket"
151151
with socket.socket(socket.AF_UNIX) as sock:
152152
try:

Lib/test/test_asyncio/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
2-
from test.support import load_package_tests, import_module
2+
from test.support import load_package_tests
3+
from test.support import import_helper
4+
35

46
# Skip tests if we don't have concurrent.futures.
5-
import_module('concurrent.futures')
7+
import_helper.import_module('concurrent.futures')
68

79
def load_tests(*args):
810
return load_package_tests(os.path.dirname(__file__), *args)

Lib/test/test_asyncio/test_base_events.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from test.test_asyncio import utils as test_utils
1717
from test import support
1818
from test.support.script_helper import assert_python_ok
19+
from test.support import os_helper
1920
from test.support import socket_helper
2021

2122

@@ -1983,22 +1984,22 @@ async def wait_closed(self):
19831984
def setUpClass(cls):
19841985
cls.__old_bufsize = constants.SENDFILE_FALLBACK_READBUFFER_SIZE
19851986
constants.SENDFILE_FALLBACK_READBUFFER_SIZE = 1024 * 16
1986-
with open(support.TESTFN, 'wb') as fp:
1987+
with open(os_helper.TESTFN, 'wb') as fp:
19871988
fp.write(cls.DATA)
19881989
super().setUpClass()
19891990

19901991
@classmethod
19911992
def tearDownClass(cls):
19921993
constants.SENDFILE_FALLBACK_READBUFFER_SIZE = cls.__old_bufsize
1993-
support.unlink(support.TESTFN)
1994+
os_helper.unlink(os_helper.TESTFN)
19941995
super().tearDownClass()
19951996

19961997
def setUp(self):
19971998
from asyncio.selector_events import BaseSelectorEventLoop
19981999
# BaseSelectorEventLoop() has no native implementation
19992000
self.loop = BaseSelectorEventLoop()
20002001
self.set_event_loop(self.loop)
2001-
self.file = open(support.TESTFN, 'rb')
2002+
self.file = open(os_helper.TESTFN, 'rb')
20022003
self.addCleanup(self.file.close)
20032004
super().setUp()
20042005

@@ -2095,7 +2096,7 @@ def test_blocking_socket(self):
20952096

20962097
def test_nonbinary_file(self):
20972098
sock = self.make_socket()
2098-
with open(support.TESTFN, 'r') as f:
2099+
with open(os_helper.TESTFN, 'r') as f:
20992100
with self.assertRaisesRegex(ValueError, "binary mode"):
21002101
self.run_loop(self.loop.sock_sendfile(sock, f))
21012102

Lib/test/test_asyncio/test_sendfile.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from asyncio import constants
1111
from unittest import mock
1212
from test import support
13+
from test.support import os_helper
1314
from test.support import socket_helper
1415
from test.test_asyncio import utils as test_utils
1516

@@ -98,17 +99,17 @@ def create_event_loop(self):
9899

99100
@classmethod
100101
def setUpClass(cls):
101-
with open(support.TESTFN, 'wb') as fp:
102+
with open(os_helper.TESTFN, 'wb') as fp:
102103
fp.write(cls.DATA)
103104
super().setUpClass()
104105

105106
@classmethod
106107
def tearDownClass(cls):
107-
support.unlink(support.TESTFN)
108+
os_helper.unlink(os_helper.TESTFN)
108109
super().tearDownClass()
109110

110111
def setUp(self):
111-
self.file = open(support.TESTFN, 'rb')
112+
self.file = open(os_helper.TESTFN, 'rb')
112113
self.addCleanup(self.file.close)
113114
self.loop = self.create_event_loop()
114115
self.set_event_loop(self.loop)

Lib/test/test_asyncio/test_subprocess.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from asyncio import subprocess
1111
from test.test_asyncio import utils as test_utils
1212
from test import support
13+
from test.support import os_helper
1314

1415
if sys.platform != 'win32':
1516
from asyncio import unix_events
@@ -626,10 +627,10 @@ async def execute():
626627
def test_create_subprocess_exec_with_path(self):
627628
async def execute():
628629
p = await subprocess.create_subprocess_exec(
629-
support.FakePath(sys.executable), '-c', 'pass')
630+
os_helper.FakePath(sys.executable), '-c', 'pass')
630631
await p.wait()
631632
p = await subprocess.create_subprocess_exec(
632-
sys.executable, '-c', 'pass', support.FakePath('.'))
633+
sys.executable, '-c', 'pass', os_helper.FakePath('.'))
633634
await p.wait()
634635

635636
self.assertIsNone(self.loop.run_until_complete(execute()))
@@ -737,7 +738,7 @@ async def execute():
737738

738739
with self.assertRaises(RuntimeError):
739740
await subprocess.create_subprocess_exec(
740-
support.FakePath(sys.executable), '-c', 'pass')
741+
os_helper.FakePath(sys.executable), '-c', 'pass')
741742

742743
watcher.add_child_handler.assert_not_called()
743744

Lib/test/test_asyncio/test_unix_events.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import threading
1515
import unittest
1616
from unittest import mock
17-
from test import support
17+
from test.support import os_helper
1818
from test.support import socket_helper
1919

2020
if sys.platform == 'win32':
@@ -467,19 +467,19 @@ async def wait_closed(self):
467467

468468
@classmethod
469469
def setUpClass(cls):
470-
with open(support.TESTFN, 'wb') as fp:
470+
with open(os_helper.TESTFN, 'wb') as fp:
471471
fp.write(cls.DATA)
472472
super().setUpClass()
473473

474474
@classmethod
475475
def tearDownClass(cls):
476-
support.unlink(support.TESTFN)
476+
os_helper.unlink(os_helper.TESTFN)
477477
super().tearDownClass()
478478

479479
def setUp(self):
480480
self.loop = asyncio.new_event_loop()
481481
self.set_event_loop(self.loop)
482-
self.file = open(support.TESTFN, 'rb')
482+
self.file = open(os_helper.TESTFN, 'rb')
483483
self.addCleanup(self.file.close)
484484
super().setUp()
485485

Lib/test/test_getopt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# test_getopt.py
22
# David Goodger <dgoodger@bigfoot.com> 2000-08-19
33

4-
from test.support import verbose, run_doctest, EnvironmentVarGuard
4+
from test.support import verbose, run_doctest
5+
from test.support.os_helper import EnvironmentVarGuard
56
import unittest
67

78
import getopt

Lib/test/test_tcl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import os
66
import warnings
77
from test import support
8+
from test.support import import_helper
89

910
# Skip this test if the _tkinter module wasn't built.
10-
_tkinter = support.import_module('_tkinter')
11+
_tkinter = import_helper.import_module('_tkinter')
1112

1213
import tkinter
1314
from tkinter import Tcl

Lib/test/test_xmlrpc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io
1616
import contextlib
1717
from test import support
18+
from test.support import os_helper
1819
from test.support import socket_helper
1920
from test.support import threading_helper
2021
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
@@ -1372,7 +1373,7 @@ def tearDown(self):
13721373
self.cgi = None
13731374

13741375
def test_cgi_get(self):
1375-
with support.EnvironmentVarGuard() as env:
1376+
with os_helper.EnvironmentVarGuard() as env:
13761377
env['REQUEST_METHOD'] = 'GET'
13771378
# if the method is GET and no request_text is given, it runs handle_get
13781379
# get sysout output
@@ -1404,7 +1405,7 @@ def test_cgi_xmlrpc_response(self):
14041405
</methodCall>
14051406
"""
14061407

1407-
with support.EnvironmentVarGuard() as env, \
1408+
with os_helper.EnvironmentVarGuard() as env, \
14081409
captured_stdout(encoding=self.cgi.encoding) as data_out, \
14091410
support.captured_stdin() as data_in:
14101411
data_in.write(data)

0 commit comments

Comments
 (0)