From bb0424b122e3d222a558bd4177ce37befd3e0347 Mon Sep 17 00:00:00 2001 From: Hai Shi Date: Tue, 4 Aug 2020 00:47:42 +0800 Subject: bpo-40275: Use new test.support helper submodules in tests (GH-21451) --- Lib/test/test_bdb.py | 7 +- Lib/test/test_code_module.py | 5 +- Lib/test/test_embed.py | 10 +- Lib/test/test_gzip.py | 24 ++- Lib/test/test_largefile.py | 3 +- Lib/test/test_lltrace.py | 8 +- Lib/test/test_ordered_dict.py | 7 +- Lib/test/test_pathlib.py | 72 +++---- Lib/test/test_pipes.py | 4 +- Lib/test/test_posix.py | 358 +++++++++++++++++--------------- Lib/test/test_pydoc.py | 15 +- Lib/test/test_resource.py | 8 +- Lib/test/test_runpy.py | 6 +- Lib/test/test_sax.py | 30 +-- Lib/test/test_sys.py | 7 +- Lib/test/test_syslog.py | 5 +- Lib/test/test_ttk_textonly.py | 4 +- Lib/test/test_unicode_file_functions.py | 20 +- Lib/test/test_urllib2.py | 6 +- Lib/test/test_venv.py | 3 +- 20 files changed, 324 insertions(+), 278 deletions(-) diff --git a/Lib/test/test_bdb.py b/Lib/test/test_bdb.py index ae16880..9bce780 100644 --- a/Lib/test/test_bdb.py +++ b/Lib/test/test_bdb.py @@ -58,6 +58,9 @@ import linecache from contextlib import contextmanager from itertools import islice, repeat import test.support +from test.support import import_helper +from test.support import os_helper + class BdbException(Exception): pass class BdbError(BdbException): """Error raised by the Bdb instance.""" @@ -531,7 +534,7 @@ def run_test(modules, set_list, skip=None): @contextmanager def create_modules(modules): - with test.support.temp_cwd(): + with os_helper.temp_cwd(): sys.path.append(os.getcwd()) try: for m in modules: @@ -543,7 +546,7 @@ def create_modules(modules): yield finally: for m in modules: - test.support.forget(m) + import_helper.forget(m) sys.path.pop() def break_in_func(funcname, fname=__file__, temporary=False, cond=None): diff --git a/Lib/test/test_code_module.py b/Lib/test/test_code_module.py index 24db0ac..226bc3a 100644 --- a/Lib/test/test_code_module.py +++ b/Lib/test/test_code_module.py @@ -4,9 +4,10 @@ import unittest from textwrap import dedent from contextlib import ExitStack from unittest import mock -from test import support +from test.support import import_helper -code = support.import_module('code') + +code = import_helper.import_module('code') class TestInteractiveConsole(unittest.TestCase): diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 2b74052..31dc39f 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1,5 +1,7 @@ # Run the tests in Programs/_testembed.c (tests for the CPython embedding APIs) from test import support +from test.support import import_helper +from test.support import os_helper import unittest from collections import namedtuple @@ -1339,8 +1341,8 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase): # # The global path configuration (_Py_path_config) must be a copy # of the path configuration of PyInterpreter.config (PyConfig). - ctypes = support.import_module('ctypes') - _testinternalcapi = support.import_module('_testinternalcapi') + ctypes = import_helper.import_module('ctypes') + _testinternalcapi = import_helper.import_module('_testinternalcapi') def get_func(name): func = getattr(ctypes.pythonapi, name) @@ -1418,7 +1420,7 @@ class AuditingTests(EmbeddingTestsMixin, unittest.TestCase): returncode=1) def test_audit_run_interactivehook(self): - startup = os.path.join(self.oldcwd, support.TESTFN) + ".py" + startup = os.path.join(self.oldcwd, os_helper.TESTFN) + ".py" with open(startup, "w", encoding="utf-8") as f: print("import sys", file=f) print("sys.__interactivehook__ = lambda: None", file=f) @@ -1431,7 +1433,7 @@ class AuditingTests(EmbeddingTestsMixin, unittest.TestCase): os.unlink(startup) def test_audit_run_startup(self): - startup = os.path.join(self.oldcwd, support.TESTFN) + ".py" + startup = os.path.join(self.oldcwd, os_helper.TESTFN) + ".py" with open(startup, "w", encoding="utf-8") as f: print("pass", file=f) try: diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index 0f235d1..c3fa9b0 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -11,10 +11,12 @@ import sys import unittest from subprocess import PIPE, Popen from test import support +from test.support import import_helper +from test.support import os_helper from test.support import _4G, bigmemtest from test.support.script_helper import assert_python_ok, assert_python_failure -gzip = support.import_module('gzip') +gzip = import_helper.import_module('gzip') data1 = b""" int length=DEFAULTALLOC, err = Z_OK; PyObject *RetVal; @@ -29,7 +31,7 @@ data2 = b"""/* zlibmodule.c -- gzip-compatible data compression */ """ -TEMPDIR = os.path.abspath(support.TESTFN) + '-gzdir' +TEMPDIR = os.path.abspath(os_helper.TESTFN) + '-gzdir' class UnseekableIO(io.BytesIO): @@ -44,13 +46,13 @@ class UnseekableIO(io.BytesIO): class BaseTest(unittest.TestCase): - filename = support.TESTFN + filename = os_helper.TESTFN def setUp(self): - support.unlink(self.filename) + os_helper.unlink(self.filename) def tearDown(self): - support.unlink(self.filename) + os_helper.unlink(self.filename) class TestGzip(BaseTest): @@ -286,7 +288,7 @@ class TestGzip(BaseTest): self.test_write() with gzip.GzipFile(self.filename, 'r') as f: self.assertEqual(f.myfileobj.mode, 'rb') - support.unlink(self.filename) + os_helper.unlink(self.filename) with gzip.GzipFile(self.filename, 'x') as f: self.assertEqual(f.myfileobj.mode, 'xb') @@ -365,7 +367,7 @@ class TestGzip(BaseTest): self.assertEqual(isizeBytes, struct.pack('