From f592ee3cb7d2c9d2e3a4de2cc30f4ce837ed2362 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Fri, 7 Aug 2020 20:02:09 +0800 Subject: [PATCH 1/5] Use new test.support helper submodules in tests --- Lib/ctypes/test/test_loading.py | 3 +- Lib/sqlite3/test/hooks.py | 3 +- Lib/test/_test_multiprocessing.py | 32 ++++--- Lib/test/test___all__.py | 5 +- Lib/test/test_asyncio/test_proactor_events.py | 7 +- Lib/test/test_ntpath.py | 12 +-- Lib/test/test_ossaudiodev.py | 3 +- Lib/test/test_platform.py | 2 +- Lib/test/test_posixpath.py | 92 ++++++++++--------- Lib/test/test_py_compile.py | 2 +- Lib/test/test_source_encoding.py | 4 +- Lib/test/test_startfile.py | 3 +- Lib/test/test_sundry.py | 6 +- Lib/test/test_winconsoleio.py | 4 +- Lib/test/test_zoneinfo/_support.py | 2 +- 15 files changed, 96 insertions(+), 84 deletions(-) diff --git a/Lib/ctypes/test/test_loading.py b/Lib/ctypes/test/test_loading.py index ba655bceb8b215..38b45f95fefae8 100644 --- a/Lib/ctypes/test/test_loading.py +++ b/Lib/ctypes/test/test_loading.py @@ -5,6 +5,7 @@ import sys import unittest import test.support +from test.support import import_helper from ctypes.util import find_library libc_name = None @@ -117,7 +118,7 @@ def test_1703286_B(self): @unittest.skipUnless(os.name == "nt", 'test specific to Windows') def test_load_dll_with_flags(self): - _sqlite3 = test.support.import_module("_sqlite3") + _sqlite3 = import_helper.import_module("_sqlite3") src = _sqlite3.__file__ if src.lower().endswith("_d.pyd"): ext = "_d.dll" diff --git a/Lib/sqlite3/test/hooks.py b/Lib/sqlite3/test/hooks.py index d74e74bf272275..b08adf1d8097b3 100644 --- a/Lib/sqlite3/test/hooks.py +++ b/Lib/sqlite3/test/hooks.py @@ -24,7 +24,8 @@ import unittest import sqlite3 as sqlite -from test.support import TESTFN, unlink +from test.support.os_helper import TESTFN, unlink + class CollationTests(unittest.TestCase): def CheckCreateCollationNotString(self): diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index bde102ae2e0518..93f58b21f735f7 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -28,8 +28,10 @@ from test import support from test.support import hashlib_helper from test.support import import_helper +from test.support import os_helper from test.support import socket_helper from test.support import threading_helper +from test.support import warnings_helper # Skip tests if _multiprocessing wasn't built. @@ -615,7 +617,7 @@ def test_lose_target_ref(self): @classmethod def _test_child_fd_inflation(self, evt, q): - q.put(test.support.fd_count()) + q.put(os_helper.fd_count()) evt.wait() def test_child_fd_inflation(self): @@ -819,8 +821,8 @@ def test_stderr_flush(self): if self.TYPE == "threads": self.skipTest('test not appropriate for {}'.format(self.TYPE)) - testfn = test.support.TESTFN - self.addCleanup(test.support.unlink, testfn) + testfn = os_helper.TESTFN + self.addCleanup(os_helper.unlink, testfn) proc = self.Process(target=self._test_stderr_flush, args=(testfn,)) proc.start() proc.join() @@ -849,8 +851,8 @@ def test_sys_exit(self): if self.TYPE == 'threads': self.skipTest('test not appropriate for {}'.format(self.TYPE)) - testfn = test.support.TESTFN - self.addCleanup(test.support.unlink, testfn) + testfn = os_helper.TESTFN + self.addCleanup(os_helper.unlink, testfn) for reason in ( [1, 2, 3], @@ -1114,7 +1116,7 @@ def test_task_done(self): close_queue(queue) def test_no_import_lock_contention(self): - with test.support.temp_cwd(): + with os_helper.temp_cwd(): module_name = 'imported_by_an_imported_module' with open(module_name + '.py', 'w') as f: f.write("""if 1: @@ -1127,7 +1129,7 @@ def test_no_import_lock_contention(self): del q """) - with test.support.DirsOnSysPath(os.getcwd()): + with os_helper.DirsOnSysPath(os.getcwd()): try: __import__(module_name) except pyqueue.Empty: @@ -2688,8 +2690,8 @@ def test_resource_warning(self): # force state to RUN to emit ResourceWarning in __del__() pool._state = multiprocessing.pool.RUN - with support.check_warnings(('unclosed running multiprocessing pool', - ResourceWarning)): + with warnings_helper.check_warnings( + ('unclosed running multiprocessing pool', ResourceWarning)): pool = None support.gc_collect() @@ -3199,14 +3201,14 @@ def test_fd_transfer(self): p = self.Process(target=self._writefd, args=(child_conn, b"foo")) p.daemon = True p.start() - self.addCleanup(test.support.unlink, test.support.TESTFN) - with open(test.support.TESTFN, "wb") as f: + self.addCleanup(os_helper.unlink, os_helper.TESTFN) + with open(os_helper.TESTFN, "wb") as f: fd = f.fileno() if msvcrt: fd = msvcrt.get_osfhandle(fd) reduction.send_handle(conn, fd, p.pid) p.join() - with open(test.support.TESTFN, "rb") as f: + with open(os_helper.TESTFN, "rb") as f: self.assertEqual(f.read(), b"foo") @unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction") @@ -3225,8 +3227,8 @@ def test_large_fd_transfer(self): p = self.Process(target=self._writefd, args=(child_conn, b"bar", True)) p.daemon = True p.start() - self.addCleanup(test.support.unlink, test.support.TESTFN) - with open(test.support.TESTFN, "wb") as f: + self.addCleanup(os_helper.unlink, os_helper.TESTFN) + with open(os_helper.TESTFN, "wb") as f: fd = f.fileno() for newfd in range(256, MAXFD): if not self._is_fd_assigned(newfd): @@ -3239,7 +3241,7 @@ def test_large_fd_transfer(self): finally: os.close(newfd) p.join() - with open(test.support.TESTFN, "rb") as f: + with open(os_helper.TESTFN, "rb") as f: self.assertEqual(f.read(), b"bar") @classmethod diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py index 0ba243ee4e74e4..0a03dd20065feb 100644 --- a/Lib/test/test___all__.py +++ b/Lib/test/test___all__.py @@ -1,5 +1,6 @@ import unittest from test import support +from test.support import warnings_helper import os import sys @@ -15,7 +16,7 @@ class AllTest(unittest.TestCase): def check_all(self, modname): names = {} - with support.check_warnings( + with warnings_helper.check_warnings( (".* (module|package)", DeprecationWarning), (".* (module|package)", PendingDeprecationWarning), ("", ResourceWarning), @@ -31,7 +32,7 @@ def check_all(self, modname): raise NoAll(modname) names = {} with self.subTest(module=modname): - with support.check_warnings( + with warnings_helper.check_warnings( ("", DeprecationWarning), ("", ResourceWarning), quiet=True): diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py index 50ba4c19d425ca..91db4c46a350bd 100644 --- a/Lib/test/test_asyncio/test_proactor_events.py +++ b/Lib/test/test_asyncio/test_proactor_events.py @@ -12,7 +12,6 @@ from asyncio.proactor_events import _ProactorWritePipeTransport from asyncio.proactor_events import _ProactorDuplexPipeTransport from asyncio.proactor_events import _ProactorDatagramTransport -from test import support from test.support import socket_helper from test.test_asyncio import utils as test_utils @@ -935,20 +934,20 @@ 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.ProactorEventLoop() self.set_event_loop(self.loop) self.addCleanup(self.loop.close) - self.file = open(support.TESTFN, 'rb') + self.file = open(os_helper.TESTFN, 'rb') self.addCleanup(self.file.close) super().setUp() diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py index 0d84ff8bce2c07..a8f764f48ca00f 100644 --- a/Lib/test/test_ntpath.py +++ b/Lib/test/test_ntpath.py @@ -6,7 +6,7 @@ from test.support import os_helper from test.support import TestFailed from test.support.os_helper import FakePath -from test import support, test_genericpath +from test import test_genericpath from tempfile import TemporaryFile @@ -287,7 +287,7 @@ def test_realpath_broken_symlinks(self): os.mkdir(ABSTFN) self.addCleanup(os_helper.rmtree, ABSTFN) - with support.change_cwd(ABSTFN): + with os_helper.change_cwd(ABSTFN): os.mkdir("subdir") os.chdir("subdir") os.symlink(".", "recursive") @@ -443,11 +443,11 @@ def test_realpath_cwd(self): self.assertPathEqual(test_file_long, ntpath.realpath(test_file_short)) - with support.change_cwd(test_dir_long): + with os_helper.change_cwd(test_dir_long): self.assertPathEqual(test_file_long, ntpath.realpath("file.txt")) - with support.change_cwd(test_dir_long.lower()): + with os_helper.change_cwd(test_dir_long.lower()): self.assertPathEqual(test_file_long, ntpath.realpath("file.txt")) - with support.change_cwd(test_dir_short): + with os_helper.change_cwd(test_dir_short): self.assertPathEqual(test_file_long, ntpath.realpath("file.txt")) def test_expandvars(self): @@ -673,7 +673,7 @@ def test_ismount(self): # locations below cannot then refer to mount points # drive, path = ntpath.splitdrive(sys.executable) - with support.change_cwd(ntpath.dirname(sys.executable)): + with os_helper.change_cwd(ntpath.dirname(sys.executable)): self.assertFalse(ntpath.ismount(drive.lower())) self.assertFalse(ntpath.ismount(drive.upper())) diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py index 624fbf21ba7d88..d3766e580b9843 100644 --- a/Lib/test/test_ossaudiodev.py +++ b/Lib/test/test_ossaudiodev.py @@ -1,9 +1,10 @@ from test import support +from test.support import import_helper support.requires('audio') from test.support import findfile -ossaudiodev = support.import_module('ossaudiodev') +ossaudiodev = import_helper.import_module('ossaudiodev') import errno import sys diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 5ad306e0ed5795..b5d21e54610e3d 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -196,7 +196,7 @@ def test_uname_win32_ARCHITEW6432(self): # using it, per # http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx try: - with support.EnvironmentVarGuard() as environ: + with os_helper.EnvironmentVarGuard() as environ: if 'PROCESSOR_ARCHITEW6432' in environ: del environ['PROCESSOR_ARCHITEW6432'] environ['PROCESSOR_ARCHITECTURE'] = 'foo' diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 18819a5dc1cfee..f37e82505796db 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -2,7 +2,9 @@ import posixpath import unittest from posixpath import realpath, abspath, dirname, basename -from test import support, test_genericpath +from test import test_genericpath +from test.support import import_helper +from test.support import os_helper from test.support import FakePath from unittest import mock @@ -15,7 +17,7 @@ # An absolute path to a temporary filename for testing. We can't rely on TESTFN # being an absolute path, so we need this. -ABSTFN = abspath(support.TESTFN) +ABSTFN = abspath(os_helper.TESTFN) def skip_if_ABSTFN_contains_backslash(test): """ @@ -40,8 +42,8 @@ def setUp(self): def tearDown(self): for suffix in ["", "1", "2"]: - support.unlink(support.TESTFN + suffix) - safe_rmdir(support.TESTFN + suffix) + os_helper.unlink(os_helper.TESTFN + suffix) + safe_rmdir(os_helper.TESTFN + suffix) def test_join(self): self.assertEqual(posixpath.join("/foo", "bar", "/bar", "baz"), @@ -152,25 +154,25 @@ def test_dirname(self): self.assertEqual(posixpath.dirname(b"//foo//bar"), b"//foo") def test_islink(self): - self.assertIs(posixpath.islink(support.TESTFN + "1"), False) - self.assertIs(posixpath.lexists(support.TESTFN + "2"), False) + self.assertIs(posixpath.islink(os_helper.TESTFN + "1"), False) + self.assertIs(posixpath.lexists(os_helper.TESTFN + "2"), False) - with open(support.TESTFN + "1", "wb") as f: + with open(os_helper.TESTFN + "1", "wb") as f: f.write(b"foo") - self.assertIs(posixpath.islink(support.TESTFN + "1"), False) + self.assertIs(posixpath.islink(os_helper.TESTFN + "1"), False) - if support.can_symlink(): - os.symlink(support.TESTFN + "1", support.TESTFN + "2") - self.assertIs(posixpath.islink(support.TESTFN + "2"), True) - os.remove(support.TESTFN + "1") - self.assertIs(posixpath.islink(support.TESTFN + "2"), True) - self.assertIs(posixpath.exists(support.TESTFN + "2"), False) - self.assertIs(posixpath.lexists(support.TESTFN + "2"), True) + if os_helper.can_symlink(): + os.symlink(os_helper.TESTFN + "1", os_helper.TESTFN + "2") + self.assertIs(posixpath.islink(os_helper.TESTFN + "2"), True) + os.remove(os_helper.TESTFN + "1") + self.assertIs(posixpath.islink(os_helper.TESTFN + "2"), True) + self.assertIs(posixpath.exists(os_helper.TESTFN + "2"), False) + self.assertIs(posixpath.lexists(os_helper.TESTFN + "2"), True) - self.assertIs(posixpath.islink(support.TESTFN + "\udfff"), False) - self.assertIs(posixpath.islink(os.fsencode(support.TESTFN) + b"\xff"), False) - self.assertIs(posixpath.islink(support.TESTFN + "\x00"), False) - self.assertIs(posixpath.islink(os.fsencode(support.TESTFN) + b"\x00"), False) + self.assertIs(posixpath.islink(os_helper.TESTFN + "\udfff"), False) + self.assertIs(posixpath.islink(os.fsencode(os_helper.TESTFN) + b"\xff"), False) + self.assertIs(posixpath.islink(os_helper.TESTFN + "\x00"), False) + self.assertIs(posixpath.islink(os.fsencode(os_helper.TESTFN) + b"\x00"), False) def test_ismount(self): self.assertIs(posixpath.ismount("/"), True) @@ -190,7 +192,7 @@ def test_ismount_non_existent(self): self.assertIs(posixpath.ismount('/\x00'), False) self.assertIs(posixpath.ismount(b'/\x00'), False) - @unittest.skipUnless(support.can_symlink(), + @unittest.skipUnless(os_helper.can_symlink(), "Test requires symlink support") def test_ismount_symlinks(self): # Symlinks are never mountpoints. @@ -245,7 +247,7 @@ def test_expanduser(self): self.assertEqual(posixpath.expanduser(b"foo"), b"foo") def test_expanduser_home_envvar(self): - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: env['HOME'] = '/home/victor' self.assertEqual(posixpath.expanduser("~"), "/home/victor") @@ -261,7 +263,7 @@ def test_expanduser_home_envvar(self): self.assertEqual(posixpath.expanduser("~/foo"), "/foo") def test_expanduser_pwd(self): - pwd = support.import_module('pwd') + pwd = import_helper.import_module('pwd') self.assertIsInstance(posixpath.expanduser("~/"), str) self.assertIsInstance(posixpath.expanduser(b"~/"), bytes) @@ -281,7 +283,7 @@ def test_expanduser_pwd(self): self.assertIsInstance(posixpath.expanduser(b"~root/"), bytes) self.assertIsInstance(posixpath.expanduser(b"~foo/"), bytes) - with support.EnvironmentVarGuard() as env: + with os_helper.EnvironmentVarGuard() as env: # expanduser should fall back to using the password database del env['HOME'] @@ -348,7 +350,7 @@ def test_realpath_basic(self): os.symlink(ABSTFN+"1", ABSTFN) self.assertEqual(realpath(ABSTFN), ABSTFN+"1") finally: - support.unlink(ABSTFN) + os_helper.unlink(ABSTFN) @unittest.skipUnless(hasattr(os, "symlink"), "Missing symlink implementation") @@ -358,7 +360,7 @@ def test_realpath_relative(self): os.symlink(posixpath.relpath(ABSTFN+"1"), ABSTFN) self.assertEqual(realpath(ABSTFN), ABSTFN+"1") finally: - support.unlink(ABSTFN) + os_helper.unlink(ABSTFN) @unittest.skipUnless(hasattr(os, "symlink"), "Missing symlink implementation") @@ -392,15 +394,15 @@ def test_realpath_symlink_loops(self): self.assertEqual(realpath(ABSTFN+"c"), ABSTFN+"c") # Test using relative path as well. - with support.change_cwd(dirname(ABSTFN)): + with os_helper.change_cwd(dirname(ABSTFN)): self.assertEqual(realpath(basename(ABSTFN)), ABSTFN) finally: - support.unlink(ABSTFN) - support.unlink(ABSTFN+"1") - support.unlink(ABSTFN+"2") - support.unlink(ABSTFN+"y") - support.unlink(ABSTFN+"c") - support.unlink(ABSTFN+"a") + os_helper.unlink(ABSTFN) + os_helper.unlink(ABSTFN+"1") + os_helper.unlink(ABSTFN+"2") + os_helper.unlink(ABSTFN+"y") + os_helper.unlink(ABSTFN+"c") + os_helper.unlink(ABSTFN+"a") @unittest.skipUnless(hasattr(os, "symlink"), "Missing symlink implementation") @@ -413,8 +415,8 @@ def test_realpath_repeated_indirect_symlinks(self): os.symlink('self/self/self', ABSTFN + '/link') self.assertEqual(realpath(ABSTFN + '/link'), ABSTFN) finally: - support.unlink(ABSTFN + '/self') - support.unlink(ABSTFN + '/link') + os_helper.unlink(ABSTFN + '/self') + os_helper.unlink(ABSTFN + '/link') safe_rmdir(ABSTFN) @unittest.skipUnless(hasattr(os, "symlink"), @@ -430,11 +432,11 @@ def test_realpath_deep_recursion(self): self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN) # Test using relative path as well. - with support.change_cwd(ABSTFN): + with os_helper.change_cwd(ABSTFN): self.assertEqual(realpath('%d' % depth), ABSTFN) finally: for i in range(depth + 1): - support.unlink(ABSTFN + '/%d' % i) + os_helper.unlink(ABSTFN + '/%d' % i) safe_rmdir(ABSTFN) @unittest.skipUnless(hasattr(os, "symlink"), @@ -450,10 +452,10 @@ def test_realpath_resolve_parents(self): os.mkdir(ABSTFN + "/y") os.symlink(ABSTFN + "/y", ABSTFN + "/k") - with support.change_cwd(ABSTFN + "/k"): + with os_helper.change_cwd(ABSTFN + "/k"): self.assertEqual(realpath("a"), ABSTFN + "/y/a") finally: - support.unlink(ABSTFN + "/k") + os_helper.unlink(ABSTFN + "/k") safe_rmdir(ABSTFN + "/y") safe_rmdir(ABSTFN) @@ -477,11 +479,11 @@ def test_realpath_resolve_before_normalizing(self): # Absolute path. self.assertEqual(realpath(ABSTFN + "/link-y/.."), ABSTFN + "/k") # Relative path. - with support.change_cwd(dirname(ABSTFN)): + with os_helper.change_cwd(dirname(ABSTFN)): self.assertEqual(realpath(basename(ABSTFN) + "/link-y/.."), ABSTFN + "/k") finally: - support.unlink(ABSTFN + "/link-y") + os_helper.unlink(ABSTFN + "/link-y") safe_rmdir(ABSTFN + "/k/y") safe_rmdir(ABSTFN + "/k") safe_rmdir(ABSTFN) @@ -497,12 +499,12 @@ def test_realpath_resolve_first(self): os.mkdir(ABSTFN) os.mkdir(ABSTFN + "/k") os.symlink(ABSTFN, ABSTFN + "link") - with support.change_cwd(dirname(ABSTFN)): + with os_helper.change_cwd(dirname(ABSTFN)): base = basename(ABSTFN) self.assertEqual(realpath(base + "link"), ABSTFN) self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k") finally: - support.unlink(ABSTFN + "link") + os_helper.unlink(ABSTFN + "link") safe_rmdir(ABSTFN + "/k") safe_rmdir(ABSTFN) @@ -627,9 +629,9 @@ class PathLikeTests(unittest.TestCase): path = posixpath def setUp(self): - self.file_name = support.TESTFN - self.file_path = FakePath(support.TESTFN) - self.addCleanup(support.unlink, self.file_name) + self.file_name = os_helper.TESTFN + self.file_path = FakePath(os_helper.TESTFN) + self.addCleanup(os_helper.unlink, self.file_name) with open(self.file_name, 'xb', 0) as file: file.write(b"test_posixpath.PathLikeTests") diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py index 009645689f4237..b58f28a4bc8885 100644 --- a/Lib/test/test_py_compile.py +++ b/Lib/test/test_py_compile.py @@ -228,7 +228,7 @@ def setUp(self): file.write('x = 123\n') def tearDown(self): - support.rmtree(self.directory) + os_helper.rmtree(self.directory) def pycompilecmd(self, *args, **kwargs): # assert_python_* helpers don't return proc object. We'll just use diff --git a/Lib/test/test_source_encoding.py b/Lib/test/test_source_encoding.py index 5ca43461d9940d..b410c03221bf32 100644 --- a/Lib/test/test_source_encoding.py +++ b/Lib/test/test_source_encoding.py @@ -1,7 +1,9 @@ # -*- coding: koi8-r -*- import unittest -from test.support import TESTFN, unlink, unload, rmtree, script_helper, captured_stdout +from test.support import script_helper, captured_stdout +from test.support.os_helper import TESTFN, unlink, rmtree +from test.support.import_helper import unload import importlib import os import sys diff --git a/Lib/test/test_startfile.py b/Lib/test/test_startfile.py index 1a26a8025e6243..589ffa25244da9 100644 --- a/Lib/test/test_startfile.py +++ b/Lib/test/test_startfile.py @@ -9,6 +9,7 @@ import unittest from test import support +from test.support import os_helper import os import platform import sys @@ -27,7 +28,7 @@ def test_empty(self): # we're not about to delete. If we're running under -j, that # means the test harness provided directory isn't a safe option. # See http://bugs.python.org/issue15526 for more details - with support.change_cwd(path.dirname(sys.executable)): + with os_helper.change_cwd(path.dirname(sys.executable)): empty = path.join(path.dirname(__file__), "empty.vbs") startfile(empty) startfile(empty, "open") diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py index 2accad1aeebd4f..04e572c00a1969 100644 --- a/Lib/test/test_sundry.py +++ b/Lib/test/test_sundry.py @@ -3,15 +3,17 @@ import platform import sys from test import support +from test.support import import_helper +from test.support import warnings_helper import unittest class TestUntestedModules(unittest.TestCase): def test_untested_modules_can_be_imported(self): untested = ('encodings', 'formatter') - with support.check_warnings(quiet=True): + with warnings_helper.check_warnings(quiet=True): for name in untested: try: - support.import_module('test.test_{}'.format(name)) + import_helper.import_module('test.test_{}'.format(name)) except unittest.SkipTest: importlib.import_module(name) else: diff --git a/Lib/test/test_winconsoleio.py b/Lib/test/test_winconsoleio.py index a44f7bbd27b700..1807e47c66c387 100644 --- a/Lib/test/test_winconsoleio.py +++ b/Lib/test/test_winconsoleio.py @@ -6,7 +6,7 @@ import sys import tempfile import unittest -from test import support +from test.support import os_helper if sys.platform != 'win32': raise unittest.SkipTest("test only relevant on win32") @@ -109,7 +109,7 @@ def test_conin_conout_names(self): def test_conout_path(self): temp_path = tempfile.mkdtemp() - self.addCleanup(support.rmtree, temp_path) + self.addCleanup(os_helper.rmtree, temp_path) conout_path = os.path.join(temp_path, 'CONOUT$') diff --git a/Lib/test/test_zoneinfo/_support.py b/Lib/test/test_zoneinfo/_support.py index 0fe162c2583687..5a76c163fb75bd 100644 --- a/Lib/test/test_zoneinfo/_support.py +++ b/Lib/test/test_zoneinfo/_support.py @@ -3,7 +3,7 @@ import sys import threading import unittest -from test.support import import_fresh_module +from test.support.import_helper import import_fresh_module OS_ENV_LOCK = threading.Lock() TZPATH_LOCK = threading.Lock() From cdd25b597bcf664e83f545043a481aa710ee7093 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Fri, 7 Aug 2020 20:48:35 +0800 Subject: [PATCH 2/5] fix test errors --- Lib/test/_test_multiprocessing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 93f58b21f735f7..58663c02002e94 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -1129,7 +1129,7 @@ def test_no_import_lock_contention(self): del q """) - with os_helper.DirsOnSysPath(os.getcwd()): + with import_helper.DirsOnSysPath(os.getcwd()): try: __import__(module_name) except pyqueue.Empty: From 2836625913dca718bcf58b12a73bb99b4ec86dbb Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Fri, 7 Aug 2020 21:29:49 +0800 Subject: [PATCH 3/5] import os_helper in test_proactor_events --- Lib/test/support/__init__.py | 19 ------------------- Lib/test/test_asyncio/test_proactor_events.py | 1 + 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index b517df7b53b6ea..f2988eb1930bd2 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -14,25 +14,6 @@ import types import unittest -from .import_helper import ( - CleanImport, DirsOnSysPath, _ignore_deprecated_imports, - _save_and_block_module, _save_and_remove_module, - forget, import_fresh_module, import_module, make_legacy_pyc, - modules_cleanup, modules_setup, unload) -from .os_helper import ( - FS_NONASCII, SAVEDCWD, TESTFN, TESTFN_ASCII, TESTFN_NONASCII, - TESTFN_UNENCODABLE, TESTFN_UNDECODABLE, - TESTFN_UNICODE, can_symlink, can_xattr, - change_cwd, create_empty_file, fd_count, - fs_is_case_insensitive, make_bad_fd, rmdir, - rmtree, skip_unless_symlink, skip_unless_xattr, - temp_cwd, temp_dir, temp_umask, unlink, - EnvironmentVarGuard, FakePath, _longpath) -from .warnings_helper import ( - WarningsRecorder, _filterwarnings, - check_no_resource_warning, check_no_warnings, - check_syntax_warning, check_warnings, ignore_warnings) - from .testresult import get_test_runner diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py index 91db4c46a350bd..d0ab38743ecd1f 100644 --- a/Lib/test/test_asyncio/test_proactor_events.py +++ b/Lib/test/test_asyncio/test_proactor_events.py @@ -12,6 +12,7 @@ from asyncio.proactor_events import _ProactorWritePipeTransport from asyncio.proactor_events import _ProactorDuplexPipeTransport from asyncio.proactor_events import _ProactorDatagramTransport +from test.support import os_helper from test.support import socket_helper from test.test_asyncio import utils as test_utils From cd5639a7e00f5867454c6d3497951e3dc30dee12 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Fri, 7 Aug 2020 22:03:44 +0800 Subject: [PATCH 4/5] update tests --- Lib/test/support/__init__.py | 19 +++++++++++++++++++ Lib/test/test_asyncio/test_proactor_events.py | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index f2988eb1930bd2..b517df7b53b6ea 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -14,6 +14,25 @@ import types import unittest +from .import_helper import ( + CleanImport, DirsOnSysPath, _ignore_deprecated_imports, + _save_and_block_module, _save_and_remove_module, + forget, import_fresh_module, import_module, make_legacy_pyc, + modules_cleanup, modules_setup, unload) +from .os_helper import ( + FS_NONASCII, SAVEDCWD, TESTFN, TESTFN_ASCII, TESTFN_NONASCII, + TESTFN_UNENCODABLE, TESTFN_UNDECODABLE, + TESTFN_UNICODE, can_symlink, can_xattr, + change_cwd, create_empty_file, fd_count, + fs_is_case_insensitive, make_bad_fd, rmdir, + rmtree, skip_unless_symlink, skip_unless_xattr, + temp_cwd, temp_dir, temp_umask, unlink, + EnvironmentVarGuard, FakePath, _longpath) +from .warnings_helper import ( + WarningsRecorder, _filterwarnings, + check_no_resource_warning, check_no_warnings, + check_syntax_warning, check_warnings, ignore_warnings) + from .testresult import get_test_runner diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py index d0ab38743ecd1f..91db4c46a350bd 100644 --- a/Lib/test/test_asyncio/test_proactor_events.py +++ b/Lib/test/test_asyncio/test_proactor_events.py @@ -12,7 +12,6 @@ from asyncio.proactor_events import _ProactorWritePipeTransport from asyncio.proactor_events import _ProactorDuplexPipeTransport from asyncio.proactor_events import _ProactorDatagramTransport -from test.support import os_helper from test.support import socket_helper from test.test_asyncio import utils as test_utils From 02072beb337a46a8fecb3bccdd5147e56991c9df Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Fri, 7 Aug 2020 22:45:18 +0800 Subject: [PATCH 5/5] fix test_proactor_events --- Lib/test/test_asyncio/test_proactor_events.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py index 91db4c46a350bd..d0ab38743ecd1f 100644 --- a/Lib/test/test_asyncio/test_proactor_events.py +++ b/Lib/test/test_asyncio/test_proactor_events.py @@ -12,6 +12,7 @@ from asyncio.proactor_events import _ProactorWritePipeTransport from asyncio.proactor_events import _ProactorDuplexPipeTransport from asyncio.proactor_events import _ProactorDatagramTransport +from test.support import os_helper from test.support import socket_helper from test.test_asyncio import utils as test_utils