bpo-40275: Use new test.support helper submodules in tests (GH-20824)
This commit is contained in:
parent
91698d8caa
commit
06a40d7359
|
@ -146,7 +146,7 @@ def skip_unless_bind_unix_socket(test):
|
||||||
return unittest.skip('No UNIX Sockets')(test)
|
return unittest.skip('No UNIX Sockets')(test)
|
||||||
global _bind_nix_socket_error
|
global _bind_nix_socket_error
|
||||||
if _bind_nix_socket_error is None:
|
if _bind_nix_socket_error is None:
|
||||||
from test.support import TESTFN, unlink
|
from .os_helper import TESTFN, unlink
|
||||||
path = TESTFN + "can_bind_unix_socket"
|
path = TESTFN + "can_bind_unix_socket"
|
||||||
with socket.socket(socket.AF_UNIX) as sock:
|
with socket.socket(socket.AF_UNIX) as sock:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import os
|
import os
|
||||||
from test.support import load_package_tests, import_module
|
from test.support import load_package_tests
|
||||||
|
from test.support import import_helper
|
||||||
|
|
||||||
|
|
||||||
# Skip tests if we don't have concurrent.futures.
|
# Skip tests if we don't have concurrent.futures.
|
||||||
import_module('concurrent.futures')
|
import_helper.import_module('concurrent.futures')
|
||||||
|
|
||||||
def load_tests(*args):
|
def load_tests(*args):
|
||||||
return load_package_tests(os.path.dirname(__file__), *args)
|
return load_package_tests(os.path.dirname(__file__), *args)
|
||||||
|
|
|
@ -16,6 +16,7 @@ from asyncio import constants
|
||||||
from test.test_asyncio import utils as test_utils
|
from test.test_asyncio import utils as test_utils
|
||||||
from test import support
|
from test import support
|
||||||
from test.support.script_helper import assert_python_ok
|
from test.support.script_helper import assert_python_ok
|
||||||
|
from test.support import os_helper
|
||||||
from test.support import socket_helper
|
from test.support import socket_helper
|
||||||
|
|
||||||
|
|
||||||
|
@ -1983,14 +1984,14 @@ class BaseLoopSockSendfileTests(test_utils.TestCase):
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
cls.__old_bufsize = constants.SENDFILE_FALLBACK_READBUFFER_SIZE
|
cls.__old_bufsize = constants.SENDFILE_FALLBACK_READBUFFER_SIZE
|
||||||
constants.SENDFILE_FALLBACK_READBUFFER_SIZE = 1024 * 16
|
constants.SENDFILE_FALLBACK_READBUFFER_SIZE = 1024 * 16
|
||||||
with open(support.TESTFN, 'wb') as fp:
|
with open(os_helper.TESTFN, 'wb') as fp:
|
||||||
fp.write(cls.DATA)
|
fp.write(cls.DATA)
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
constants.SENDFILE_FALLBACK_READBUFFER_SIZE = cls.__old_bufsize
|
constants.SENDFILE_FALLBACK_READBUFFER_SIZE = cls.__old_bufsize
|
||||||
support.unlink(support.TESTFN)
|
os_helper.unlink(os_helper.TESTFN)
|
||||||
super().tearDownClass()
|
super().tearDownClass()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -1998,7 +1999,7 @@ class BaseLoopSockSendfileTests(test_utils.TestCase):
|
||||||
# BaseSelectorEventLoop() has no native implementation
|
# BaseSelectorEventLoop() has no native implementation
|
||||||
self.loop = BaseSelectorEventLoop()
|
self.loop = BaseSelectorEventLoop()
|
||||||
self.set_event_loop(self.loop)
|
self.set_event_loop(self.loop)
|
||||||
self.file = open(support.TESTFN, 'rb')
|
self.file = open(os_helper.TESTFN, 'rb')
|
||||||
self.addCleanup(self.file.close)
|
self.addCleanup(self.file.close)
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
|
@ -2095,7 +2096,7 @@ class BaseLoopSockSendfileTests(test_utils.TestCase):
|
||||||
|
|
||||||
def test_nonbinary_file(self):
|
def test_nonbinary_file(self):
|
||||||
sock = self.make_socket()
|
sock = self.make_socket()
|
||||||
with open(support.TESTFN, 'r') as f:
|
with open(os_helper.TESTFN, 'r') as f:
|
||||||
with self.assertRaisesRegex(ValueError, "binary mode"):
|
with self.assertRaisesRegex(ValueError, "binary mode"):
|
||||||
self.run_loop(self.loop.sock_sendfile(sock, f))
|
self.run_loop(self.loop.sock_sendfile(sock, f))
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ from asyncio import base_events
|
||||||
from asyncio import constants
|
from asyncio import constants
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import os_helper
|
||||||
from test.support import socket_helper
|
from test.support import socket_helper
|
||||||
from test.test_asyncio import utils as test_utils
|
from test.test_asyncio import utils as test_utils
|
||||||
|
|
||||||
|
@ -98,17 +99,17 @@ class SendfileBase:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
with open(support.TESTFN, 'wb') as fp:
|
with open(os_helper.TESTFN, 'wb') as fp:
|
||||||
fp.write(cls.DATA)
|
fp.write(cls.DATA)
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
support.unlink(support.TESTFN)
|
os_helper.unlink(os_helper.TESTFN)
|
||||||
super().tearDownClass()
|
super().tearDownClass()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.file = open(support.TESTFN, 'rb')
|
self.file = open(os_helper.TESTFN, 'rb')
|
||||||
self.addCleanup(self.file.close)
|
self.addCleanup(self.file.close)
|
||||||
self.loop = self.create_event_loop()
|
self.loop = self.create_event_loop()
|
||||||
self.set_event_loop(self.loop)
|
self.set_event_loop(self.loop)
|
||||||
|
|
|
@ -10,6 +10,7 @@ from asyncio import base_subprocess
|
||||||
from asyncio import subprocess
|
from asyncio import subprocess
|
||||||
from test.test_asyncio import utils as test_utils
|
from test.test_asyncio import utils as test_utils
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import os_helper
|
||||||
|
|
||||||
if sys.platform != 'win32':
|
if sys.platform != 'win32':
|
||||||
from asyncio import unix_events
|
from asyncio import unix_events
|
||||||
|
@ -626,10 +627,10 @@ class SubprocessMixin:
|
||||||
def test_create_subprocess_exec_with_path(self):
|
def test_create_subprocess_exec_with_path(self):
|
||||||
async def execute():
|
async def execute():
|
||||||
p = await subprocess.create_subprocess_exec(
|
p = await subprocess.create_subprocess_exec(
|
||||||
support.FakePath(sys.executable), '-c', 'pass')
|
os_helper.FakePath(sys.executable), '-c', 'pass')
|
||||||
await p.wait()
|
await p.wait()
|
||||||
p = await subprocess.create_subprocess_exec(
|
p = await subprocess.create_subprocess_exec(
|
||||||
sys.executable, '-c', 'pass', support.FakePath('.'))
|
sys.executable, '-c', 'pass', os_helper.FakePath('.'))
|
||||||
await p.wait()
|
await p.wait()
|
||||||
|
|
||||||
self.assertIsNone(self.loop.run_until_complete(execute()))
|
self.assertIsNone(self.loop.run_until_complete(execute()))
|
||||||
|
@ -737,7 +738,7 @@ class GenericWatcherTests:
|
||||||
|
|
||||||
with self.assertRaises(RuntimeError):
|
with self.assertRaises(RuntimeError):
|
||||||
await subprocess.create_subprocess_exec(
|
await subprocess.create_subprocess_exec(
|
||||||
support.FakePath(sys.executable), '-c', 'pass')
|
os_helper.FakePath(sys.executable), '-c', 'pass')
|
||||||
|
|
||||||
watcher.add_child_handler.assert_not_called()
|
watcher.add_child_handler.assert_not_called()
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import tempfile
|
||||||
import threading
|
import threading
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from test import support
|
from test.support import os_helper
|
||||||
from test.support import socket_helper
|
from test.support import socket_helper
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
|
@ -467,19 +467,19 @@ class SelectorEventLoopUnixSockSendfileTests(test_utils.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
with open(support.TESTFN, 'wb') as fp:
|
with open(os_helper.TESTFN, 'wb') as fp:
|
||||||
fp.write(cls.DATA)
|
fp.write(cls.DATA)
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
support.unlink(support.TESTFN)
|
os_helper.unlink(os_helper.TESTFN)
|
||||||
super().tearDownClass()
|
super().tearDownClass()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.loop = asyncio.new_event_loop()
|
self.loop = asyncio.new_event_loop()
|
||||||
self.set_event_loop(self.loop)
|
self.set_event_loop(self.loop)
|
||||||
self.file = open(support.TESTFN, 'rb')
|
self.file = open(os_helper.TESTFN, 'rb')
|
||||||
self.addCleanup(self.file.close)
|
self.addCleanup(self.file.close)
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
# test_getopt.py
|
# test_getopt.py
|
||||||
# David Goodger <dgoodger@bigfoot.com> 2000-08-19
|
# David Goodger <dgoodger@bigfoot.com> 2000-08-19
|
||||||
|
|
||||||
from test.support import verbose, run_doctest, EnvironmentVarGuard
|
from test.support import verbose, run_doctest
|
||||||
|
from test.support.os_helper import EnvironmentVarGuard
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import getopt
|
import getopt
|
||||||
|
|
|
@ -5,9 +5,10 @@ import sys
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import import_helper
|
||||||
|
|
||||||
# Skip this test if the _tkinter module wasn't built.
|
# Skip this test if the _tkinter module wasn't built.
|
||||||
_tkinter = support.import_module('_tkinter')
|
_tkinter = import_helper.import_module('_tkinter')
|
||||||
|
|
||||||
import tkinter
|
import tkinter
|
||||||
from tkinter import Tcl
|
from tkinter import Tcl
|
||||||
|
|
|
@ -15,6 +15,7 @@ import re
|
||||||
import io
|
import io
|
||||||
import contextlib
|
import contextlib
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support import os_helper
|
||||||
from test.support import socket_helper
|
from test.support import socket_helper
|
||||||
from test.support import threading_helper
|
from test.support import threading_helper
|
||||||
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
|
from test.support import ALWAYS_EQ, LARGEST, SMALLEST
|
||||||
|
@ -1372,7 +1373,7 @@ class CGIHandlerTestCase(unittest.TestCase):
|
||||||
self.cgi = None
|
self.cgi = None
|
||||||
|
|
||||||
def test_cgi_get(self):
|
def test_cgi_get(self):
|
||||||
with support.EnvironmentVarGuard() as env:
|
with os_helper.EnvironmentVarGuard() as env:
|
||||||
env['REQUEST_METHOD'] = 'GET'
|
env['REQUEST_METHOD'] = 'GET'
|
||||||
# if the method is GET and no request_text is given, it runs handle_get
|
# if the method is GET and no request_text is given, it runs handle_get
|
||||||
# get sysout output
|
# get sysout output
|
||||||
|
@ -1404,7 +1405,7 @@ class CGIHandlerTestCase(unittest.TestCase):
|
||||||
</methodCall>
|
</methodCall>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with support.EnvironmentVarGuard() as env, \
|
with os_helper.EnvironmentVarGuard() as env, \
|
||||||
captured_stdout(encoding=self.cgi.encoding) as data_out, \
|
captured_stdout(encoding=self.cgi.encoding) as data_out, \
|
||||||
support.captured_stdin() as data_in:
|
support.captured_stdin() as data_in:
|
||||||
data_in.write(data)
|
data_in.write(data)
|
||||||
|
|
Loading…
Reference in New Issue