bpo-40275: Use new test.support helper submodules in tests by shihai1991 · Pull Request #20824 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/support/socket_helper.py
6 changes: 4 additions & 2 deletions Lib/test/test_asyncio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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.
import_module('concurrent.futures')
import_helper.import_module('concurrent.futures')

def load_tests(*args):
return load_package_tests(os.path.dirname(__file__), *args)
9 changes: 5 additions & 4 deletions Lib/test/test_asyncio/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from test.test_asyncio import utils as test_utils
from test import support
from test.support.script_helper import assert_python_ok
from test.support import os_helper
from test.support import socket_helper


Expand Down Expand Up @@ -1983,22 +1984,22 @@ async def wait_closed(self):
def setUpClass(cls):
cls.__old_bufsize = constants.SENDFILE_FALLBACK_READBUFFER_SIZE
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)
super().setUpClass()

@classmethod
def tearDownClass(cls):
constants.SENDFILE_FALLBACK_READBUFFER_SIZE = cls.__old_bufsize
support.unlink(support.TESTFN)
os_helper.unlink(os_helper.TESTFN)
super().tearDownClass()

def setUp(self):
from asyncio.selector_events import BaseSelectorEventLoop
# BaseSelectorEventLoop() has no native implementation
self.loop = BaseSelectorEventLoop()
self.set_event_loop(self.loop)
self.file = open(support.TESTFN, 'rb')
self.file = open(os_helper.TESTFN, 'rb')
self.addCleanup(self.file.close)
super().setUp()

Expand Down Expand Up @@ -2095,7 +2096,7 @@ def test_blocking_socket(self):

def test_nonbinary_file(self):
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"):
self.run_loop(self.loop.sock_sendfile(sock, f))

Expand Down
7 changes: 4 additions & 3 deletions Lib/test/test_asyncio/test_sendfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from asyncio import constants
from unittest import mock
from test import support
from test.support import os_helper
from test.support import socket_helper
from test.test_asyncio import utils as test_utils

Expand Down Expand Up @@ -98,17 +99,17 @@ def create_event_loop(self):

@classmethod
def setUpClass(cls):
with open(support.TESTFN, 'wb') as fp:
with open(os_helper.TESTFN, 'wb') as fp:
fp.write(cls.DATA)
super().setUpClass()

@classmethod
def tearDownClass(cls):
support.unlink(support.TESTFN)
os_helper.unlink(os_helper.TESTFN)
super().tearDownClass()

def setUp(self):
self.file = open(support.TESTFN, 'rb')
self.file = open(os_helper.TESTFN, 'rb')
self.addCleanup(self.file.close)
self.loop = self.create_event_loop()
self.set_event_loop(self.loop)
Expand Down
7 changes: 4 additions & 3 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from asyncio import subprocess
from test.test_asyncio import utils as test_utils
from test import support
from test.support import os_helper

if sys.platform != 'win32':
from asyncio import unix_events
Expand Down Expand Up @@ -626,10 +627,10 @@ async def execute():
def test_create_subprocess_exec_with_path(self):
async def execute():
p = await subprocess.create_subprocess_exec(
support.FakePath(sys.executable), '-c', 'pass')
os_helper.FakePath(sys.executable), '-c', 'pass')
await p.wait()
p = await subprocess.create_subprocess_exec(
sys.executable, '-c', 'pass', support.FakePath('.'))
sys.executable, '-c', 'pass', os_helper.FakePath('.'))
await p.wait()

self.assertIsNone(self.loop.run_until_complete(execute()))
Expand Down Expand Up @@ -737,7 +738,7 @@ async def execute():

with self.assertRaises(RuntimeError):
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()

Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_asyncio/test_unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import threading
import unittest
from unittest import mock
from test import support
from test.support import os_helper
from test.support import socket_helper

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

@classmethod
def setUpClass(cls):
with open(support.TESTFN, 'wb') as fp:
with open(os_helper.TESTFN, 'wb') as fp:
fp.write(cls.DATA)
super().setUpClass()

@classmethod
def tearDownClass(cls):
support.unlink(support.TESTFN)
os_helper.unlink(os_helper.TESTFN)
super().tearDownClass()

def setUp(self):
self.loop = asyncio.new_event_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)
super().setUp()

Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_getopt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# test_getopt.py
# 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 getopt
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_tcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import os
import warnings
from test import support
from test.support import import_helper

# Skip this test if the _tkinter module wasn't built.
_tkinter = support.import_module('_tkinter')
_tkinter = import_helper.import_module('_tkinter')

import tkinter
from tkinter import Tcl
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_xmlrpc.py