diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -14,17 +14,17 @@ import errno import signal import array import socket import random import logging import struct import operator import test.support -import test.script_helper +import test.support.script_helper # Skip tests if _multiprocessing wasn't built. _multiprocessing = test.support.import_module('_multiprocessing') # Skip tests if sem_open implementation is broken. test.support.import_module('multiprocessing.synchronize') # import threading after _multiprocessing to raise a more revelant error # message: "No module named _multiprocessing". _multiprocessing is not compiled @@ -3472,21 +3472,21 @@ class TestTimeouts(unittest.TestCase): # Test what happens with no "if __name__ == '__main__'" # class TestNoForkBomb(unittest.TestCase): def test_noforkbomb(self): sm = multiprocessing.get_start_method() name = os.path.join(os.path.dirname(__file__), 'mp_fork_bomb.py') if sm != 'fork': - rc, out, err = test.script_helper.assert_python_failure(name, sm) + rc, out, err = test.support.script_helper.assert_python_failure(name, sm) self.assertEqual(out, b'') self.assertIn(b'RuntimeError', err) else: - rc, out, err = test.script_helper.assert_python_ok(name, sm) + rc, out, err = test.support.script_helper.assert_python_ok(name, sm) self.assertEqual(out.rstrip(), b'123') self.assertEqual(err, b'') # # Issue #17555: ForkAwareThreadLock # class TestForkAwareThreadLock(unittest.TestCase): diff --git a/Lib/test/script_helper.py b/Lib/test/support/script_helper.py rename from Lib/test/script_helper.py rename to Lib/test/support/script_helper.py --- a/Lib/test/script_helper.py +++ b/Lib/test/support/script_helper.py @@ -9,17 +9,17 @@ import os.path import tempfile import subprocess import py_compile import contextlib import shutil import zipfile from importlib.util import source_from_cache -from test.support import make_legacy_pyc, strip_python_stderr, temp_dir +from test.support import make_legacy_pyc, strip_python_stderr # Cached result of the expensive test performed in the function below. __cached_interp_requires_environment = None def interpreter_requires_environment(): """ Returns True if our sys.executable interpreter requires environment diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -11,17 +11,17 @@ import unittest from unittest import mock import asyncio from asyncio import base_events from asyncio import constants from asyncio import test_utils try: from test import support - from test.script_helper import assert_python_ok + from test.support.script_helper import assert_python_ok except ImportError: from asyncio import test_support as support from asyncio.test_support import assert_python_ok MOCK_ANY = mock.ANY PY34 = sys.version_info >= (3, 4) diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -8,17 +8,17 @@ import unittest import weakref from unittest import mock import asyncio from asyncio import coroutines from asyncio import test_utils try: from test import support - from test.script_helper import assert_python_ok + from test.support.script_helper import assert_python_ok except ImportError: from asyncio import test_support as support from asyncio.test_support import assert_python_ok PY34 = (sys.version_info >= (3, 4)) PY35 = (sys.version_info >= (3, 5)) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -11,17 +11,17 @@ import platform import random import sys import traceback import types import unittest import warnings from operator import neg from test.support import TESTFN, unlink, run_unittest, check_warnings -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok try: import pty, signal except ImportError: pty = signal = None class Squares: diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -1,13 +1,13 @@ import calendar import unittest from test import support -from test.script_helper import assert_python_ok, assert_python_failure +from test.support.script_helper import assert_python_ok, assert_python_failure import time import locale import sys import datetime import os result_2004_01_text = """\ January 2004 diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -6,17 +6,17 @@ import pickle import random import subprocess import sys import textwrap import time import unittest from test import support from test.support import MISSING_C_DOCSTRINGS -from test.script_helper import assert_python_failure +from test.support.script_helper import assert_python_failure try: import _posixsubprocess except ImportError: _posixsubprocess = None try: import threading except ImportError: threading = None diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py --- a/Lib/test/test_cgitb.py +++ b/Lib/test/test_cgitb.py @@ -1,9 +1,10 @@ -from test.script_helper import assert_python_failure, temp_dir +from test.support import temp_dir +from test.support.script_helper import assert_python_failure import unittest import sys import cgitb class TestCgitb(unittest.TestCase): def test_fonts(self): text = "Hello Robbie!" diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -3,18 +3,18 @@ # See test_cmd_line_script.py for testing of script execution import test.support, unittest import os import shutil import sys import subprocess import tempfile -from test import script_helper -from test.script_helper import (spawn_python, kill_python, assert_python_ok, +from test.support import script_helper +from test.support.script_helper import (spawn_python, kill_python, assert_python_ok, assert_python_failure) # XXX (ncoghlan): Move to script_helper and make consistent with run_python def _kill_python_and_exit_code(p): data = kill_python(p) returncode = p.wait() return data, returncode @@ -54,17 +54,17 @@ class CmdLineTest(unittest.TestCase): # codec), a recursion loop can occur. rc, out, err = assert_python_ok('-v') self.assertNotIn(b'stack overflow', err) rc, out, err = assert_python_ok('-vv') self.assertNotIn(b'stack overflow', err) def test_xoptions(self): def get_xoptions(*args): - # use subprocess module directly because test.script_helper adds + # use subprocess module directly because test.support.script_helper adds # "-X faulthandler" to the command line args = (sys.executable, '-E') + args args += ('-c', 'import sys; print(sys._xoptions)') out = subprocess.check_output(args) opts = eval(out.splitlines()[0]) return opts opts = get_xoptions() diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py --- a/Lib/test/test_cmd_line_script.py +++ b/Lib/test/test_cmd_line_script.py @@ -8,20 +8,19 @@ import unittest import sys import os import os.path import py_compile import subprocess import textwrap from test import support -from test.script_helper import ( +from test.support.script_helper import ( make_pkg, make_script, make_zip_pkg, make_zip_script, - assert_python_ok, assert_python_failure, temp_dir, - spawn_python, kill_python) + assert_python_ok, assert_python_failure, spawn_python, kill_python) verbose = support.verbose example_args = ['test1', 'test2', 'test3'] test_source = """\ # Script may be run with optimisation enabled, so don't rely on assert # statements being executed @@ -218,196 +217,196 @@ class CmdLineTest(unittest.TestCase): def test_repl_stderr_flush(self): self.check_repl_stderr_flush() def test_repl_stderr_flush_separate_stderr(self): self.check_repl_stderr_flush(True) def test_basic_script(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'script') self._check_script(script_name, script_name, script_name, script_dir, None, importlib.machinery.SourceFileLoader) def test_script_compiled(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'script') py_compile.compile(script_name, doraise=True) os.remove(script_name) pyc_file = support.make_legacy_pyc(script_name) self._check_script(pyc_file, pyc_file, pyc_file, script_dir, None, importlib.machinery.SourcelessFileLoader) def test_directory(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, '__main__') self._check_script(script_dir, script_name, script_dir, script_dir, '', importlib.machinery.SourceFileLoader) def test_directory_compiled(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, '__main__') py_compile.compile(script_name, doraise=True) os.remove(script_name) pyc_file = support.make_legacy_pyc(script_name) self._check_script(script_dir, pyc_file, script_dir, script_dir, '', importlib.machinery.SourcelessFileLoader) def test_directory_error(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: msg = "can't find '__main__' module in %r" % script_dir self._check_import_error(script_dir, msg) def test_zipfile(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, '__main__') zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name) self._check_script(zip_name, run_name, zip_name, zip_name, '', zipimport.zipimporter) def test_zipfile_compiled(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, '__main__') compiled_name = py_compile.compile(script_name, doraise=True) zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name) self._check_script(zip_name, run_name, zip_name, zip_name, '', zipimport.zipimporter) def test_zipfile_error(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'not_main') zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name) msg = "can't find '__main__' module in %r" % zip_name self._check_import_error(zip_name, msg) def test_module_in_package(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir) script_name = _make_test_script(pkg_dir, 'script') launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script') self._check_script(launch_name, script_name, script_name, script_dir, 'test_pkg', importlib.machinery.SourceFileLoader) def test_module_in_package_in_zipfile(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script') launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script', zip_name) self._check_script(launch_name, run_name, run_name, zip_name, 'test_pkg', zipimport.zipimporter) def test_module_in_subpackage_in_zipfile(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2) launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.test_pkg.script', zip_name) self._check_script(launch_name, run_name, run_name, zip_name, 'test_pkg.test_pkg', zipimport.zipimporter) def test_package(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir) script_name = _make_test_script(pkg_dir, '__main__') launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') self._check_script(launch_name, script_name, script_name, script_dir, 'test_pkg', importlib.machinery.SourceFileLoader) def test_package_compiled(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir) script_name = _make_test_script(pkg_dir, '__main__') compiled_name = py_compile.compile(script_name, doraise=True) os.remove(script_name) pyc_file = support.make_legacy_pyc(script_name) launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') self._check_script(launch_name, pyc_file, pyc_file, script_dir, 'test_pkg', importlib.machinery.SourcelessFileLoader) def test_package_error(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir) msg = ("'test_pkg' is a package and cannot " "be directly executed") launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') self._check_import_error(launch_name, msg) def test_package_recursion(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir) main_dir = os.path.join(pkg_dir, '__main__') make_pkg(main_dir) msg = ("Cannot use package as __main__ module; " "'test_pkg' is a package and cannot " "be directly executed") launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') self._check_import_error(launch_name, msg) def test_issue8202(self): # Make sure package __init__ modules see "-m" in sys.argv0 while # searching for the module to execute - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: with support.change_cwd(path=script_dir): pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir, "import sys; print('init_argv0==%r' % sys.argv[0])") script_name = _make_test_script(pkg_dir, 'script') rc, out, err = assert_python_ok('-m', 'test_pkg.script', *example_args, __isolated=False) if verbose > 1: print(repr(out)) expected = "init_argv0==%r" % '-m' self.assertIn(expected.encode('utf-8'), out) self._check_output(script_name, rc, out, script_name, script_name, '', 'test_pkg', importlib.machinery.SourceFileLoader) def test_issue8202_dash_c_file_ignored(self): # Make sure a "-c" file in the current directory # does not alter the value of sys.path[0] - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: with support.change_cwd(path=script_dir): with open("-c", "w") as f: f.write("data") rc, out, err = assert_python_ok('-c', 'import sys; print("sys.path[0]==%r" % sys.path[0])', __isolated=False) if verbose > 1: print(repr(out)) expected = "sys.path[0]==%r" % '' self.assertIn(expected.encode('utf-8'), out) def test_issue8202_dash_m_file_ignored(self): # Make sure a "-m" file in the current directory # does not alter the value of sys.path[0] - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'other') with support.change_cwd(path=script_dir): with open("-m", "w") as f: f.write("data") rc, out, err = assert_python_ok('-m', 'other', *example_args, __isolated=False) self._check_output(script_name, rc, out, script_name, script_name, '', '', importlib.machinery.SourceFileLoader) def test_dash_m_error_code_is_one(self): # If a module is invoked with the -m command line flag # and results in an error that the return code to the # shell is '1' - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: with support.change_cwd(path=script_dir): pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir) script_name = _make_test_script(pkg_dir, 'other', "if __name__ == '__main__': raise ValueError") rc, out, err = assert_python_failure('-m', 'test_pkg.other', *example_args) if verbose > 1: print(repr(out)) @@ -417,17 +416,17 @@ class CmdLineTest(unittest.TestCase): # Make sure PEP 409 syntax properly suppresses # the context of an exception script = textwrap.dedent("""\ try: raise ValueError except: raise NameError from None """) - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'script', script) exitcode, stdout, stderr = assert_python_failure(script_name) text = stderr.decode('ascii').split('\n') self.assertEqual(len(text), 4) self.assertTrue(text[0].startswith('Traceback')) self.assertTrue(text[1].startswith(' File ')) self.assertTrue(text[3].startswith('NameError')) @@ -461,17 +460,17 @@ class CmdLineTest(unittest.TestCase): try: raise ValueError('some text') except ValueError as err: error = err if error: sys.exit(error) """) - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'script', script) exitcode, stdout, stderr = assert_python_failure(script_name) text = stderr.decode('ascii') self.assertEqual(text, "some text") def test_main(): support.run_unittest(CmdLineTest) diff --git a/Lib/test/test_compileall.py b/Lib/test/test_compileall.py --- a/Lib/test/test_compileall.py +++ b/Lib/test/test_compileall.py @@ -12,17 +12,18 @@ import io from unittest import mock, skipUnless try: from concurrent.futures import ProcessPoolExecutor _have_multiprocessing = True except ImportError: _have_multiprocessing = False -from test import support, script_helper +from test import support +from test.support import script_helper class CompileallTests(unittest.TestCase): def setUp(self): self.directory = tempfile.mkdtemp() self.source_path = os.path.join(self.directory, '_test.py') self.bc_path = importlib.util.cache_from_source(self.source_path) with open(self.source_path, 'w') as file: diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -4,17 +4,17 @@ import test.support test.support.import_module('_multiprocessing') # Skip tests if sem_open implementation is broken. test.support.import_module('multiprocessing.synchronize') # import threading after _multiprocessing to raise a more revelant error # message: "No module named _multiprocessing". _multiprocessing is not compiled # without thread support. test.support.import_module('threading') -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok import os import sys import threading import time import unittest import weakref diff --git a/Lib/test/test_crashers.py b/Lib/test/test_crashers.py --- a/Lib/test/test_crashers.py +++ b/Lib/test/test_crashers.py @@ -3,17 +3,17 @@ # # If a crasher is fixed, it should be moved elsewhere in the test suite to # ensure it continues to work correctly. import unittest import glob import os.path import test.support -from test.script_helper import assert_python_failure +from test.support.script_helper import assert_python_failure CRASHER_DIR = os.path.join(os.path.dirname(__file__), "crashers") CRASHER_FILES = os.path.join(CRASHER_DIR, "*.py") infinite_loops = ["infinite_loop_re.py", "nasty_eq_vs_dict.py"] class CrasherTest(unittest.TestCase): diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py +++ b/Lib/test/test_doctest.py @@ -2724,18 +2724,18 @@ in the readline library that is triggere running them in a new python process. See: http://lists.gnu.org/archive/html/bug-readline/2013-06/msg00000.html With those preliminaries out of the way, we'll start with a file with two simple tests and no errors. We'll run both the unadorned doctest command, and the verbose version, and then check the output: - >>> from test import script_helper - >>> with script_helper.temp_dir() as tmpdir: + >>> from test.support import script_helper, temp_dir + >>> with temp_dir() as tmpdir: ... fn = os.path.join(tmpdir, 'myfile.doc') ... with open(fn, 'w') as f: ... _ = f.write('This is a very simple test file.\n') ... _ = f.write(' >>> 1 + 1\n') ... _ = f.write(' 2\n') ... _ = f.write(' >>> "a"\n') ... _ = f.write(" 'a'\n") ... _ = f.write('\n') @@ -2775,18 +2775,18 @@ Now we'll write a couple files, one with with two tests, both of the files having "errors" in the tests that can be made non-errors by applying the appropriate doctest options to the run (ELLIPSIS in the first file, NORMALIZE_WHITESPACE in the second). This combination will allow to thoroughly test the -f and -o flags, as well as the doctest command's ability to process more than one file on the command line and, since the second file ends in '.py', its handling of python module files (as opposed to straight text files). - >>> from test import script_helper - >>> with script_helper.temp_dir() as tmpdir: + >>> from test.support import script_helper, temp_dir + >>> with temp_dir() as tmpdir: ... fn = os.path.join(tmpdir, 'myfile.doc') ... with open(fn, 'w') as f: ... _ = f.write('This is another simple test file.\n') ... _ = f.write(' >>> 1 + 1\n') ... _ = f.write(' 2\n') ... _ = f.write(' >>> "abcdef"\n') ... _ = f.write(" 'a...f'\n") ... _ = f.write(' >>> "ajkml"\n') diff --git a/Lib/test/test_eintr.py b/Lib/test/test_eintr.py --- a/Lib/test/test_eintr.py +++ b/Lib/test/test_eintr.py @@ -1,13 +1,15 @@ import os import signal import unittest -from test import script_helper, support +from test import support +from test.support import script_helper + @unittest.skipUnless(os.name == "posix", "only supported on Unix") class EINTRTests(unittest.TestCase): @unittest.skipUnless(hasattr(signal, "setitimer"), "requires setitimer()") def test_all(self): # Run the tester in a sub-process, to make sure there is only one diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -1,18 +1,19 @@ from contextlib import contextmanager import datetime import faulthandler import os import re import signal import subprocess import sys -from test import support, script_helper -from test.script_helper import assert_python_ok +from test import support +from test.support import script_helper +from test.support.script_helper import assert_python_ok import tempfile import unittest from textwrap import dedent try: import threading HAVE_THREADS = True except ImportError: diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -1,12 +1,13 @@ import unittest from test.support import (verbose, refcount_test, run_unittest, - strip_python_stderr, cpython_only, start_threads) -from test.script_helper import assert_python_ok, make_script, temp_dir + strip_python_stderr, cpython_only, start_threads, + temp_dir) +from test.support.script_helper import assert_python_ok, make_script import sys import time import gc import weakref try: import threading diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py --- a/Lib/test/test_hash.py +++ b/Lib/test/test_hash.py @@ -2,17 +2,17 @@ # iff a==b then hash(a)==hash(b) # # Also test that hash implementations are inherited as expected import datetime import os import sys import unittest -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok from collections import Hashable IS_64BIT = sys.maxsize > 2**32 def lcg(x, length=16): """Linear congruential generator""" if x == 0: return bytes(length) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -16,18 +16,19 @@ import textwrap import errno import shutil import contextlib import test.support from test.support import ( EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython, make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask, - unlink, unload, create_empty_file, cpython_only, TESTFN_UNENCODABLE) -from test import script_helper + unlink, unload, create_empty_file, cpython_only, TESTFN_UNENCODABLE, + temp_dir) +from test.support import script_helper skip_if_dont_write_bytecode = unittest.skipIf( sys.dont_write_bytecode, "test meaningful only when writing bytecode") def remove_files(name): for f in (name + ".py", @@ -40,17 +41,17 @@ def remove_files(name): @contextlib.contextmanager def _ready_to_import(name=None, source=""): # sets up a temporary directory and removes it # creates the module file # temporarily clears the module from sys.modules (if any) # reverts or removes the module when cleaning up name = name or "spam" - with script_helper.temp_dir() as tempdir: + with temp_dir() as tempdir: path = script_helper.make_script(tempdir, name, source) old_module = sys.modules.pop(name, None) try: sys.path.insert(0, tempdir) yield name, path sys.path.remove(tempdir) finally: if old_module is not None: diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -21,17 +21,17 @@ import unittest.mock try: from concurrent.futures import ThreadPoolExecutor except ImportError: ThreadPoolExecutor = None from test.support import run_unittest, TESTFN, DirsOnSysPath, cpython_only from test.support import MISSING_C_DOCSTRINGS, cpython_only -from test.script_helper import assert_python_ok, assert_python_failure +from test.support.script_helper import assert_python_ok, assert_python_failure from test import inspect_fodder as mod from test import inspect_fodder2 as mod2 from test.test_import import _ready_to_import # Functions tested in this suite: # ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode, diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -30,17 +30,17 @@ import signal import sys import time import unittest import warnings import weakref from collections import deque, UserList from itertools import cycle, count from test import support -from test.script_helper import assert_python_ok, run_python_until_end +from test.support.script_helper import assert_python_ok, run_python_until_end import codecs import io # C implementation of io import _pyio as pyio # Python implementation of io try: import threading except ImportError: threading = None diff --git a/Lib/test/test_json/test_tool.py b/Lib/test/test_json/test_tool.py --- a/Lib/test/test_json/test_tool.py +++ b/Lib/test/test_json/test_tool.py @@ -1,15 +1,15 @@ import os import sys import textwrap import unittest import subprocess from test import support -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok class TestTool(unittest.TestCase): data = """ [["blorpie"],[ "whoops" ] , [ ],\t"d-shtaeou",\r"d-nthiouh", "i-vhbjkhnth", {"nifty":87}, {"morefield" :\tfalse,"field" diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -33,17 +33,17 @@ import json import os import queue import random import re import socket import struct import sys import tempfile -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok from test import support import textwrap import time import unittest import warnings import weakref try: import threading diff --git a/Lib/test/test_module.py b/Lib/test/test_module.py --- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -1,13 +1,13 @@ # Test the module type import unittest import weakref from test.support import gc_collect -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok import sys ModuleType = type(sys) class FullLoader: @classmethod def module_repr(cls, m): return "".format(m.__name__) diff --git a/Lib/test/test_multiprocessing_main_handling.py b/Lib/test/test_multiprocessing_main_handling.py --- a/Lib/test/test_multiprocessing_main_handling.py +++ b/Lib/test/test_multiprocessing_main_handling.py @@ -8,20 +8,19 @@ import importlib import importlib.machinery import zipimport import unittest import sys import os import os.path import py_compile -from test.script_helper import ( +from test.support.script_helper import ( make_pkg, make_script, make_zip_pkg, make_zip_script, - assert_python_ok, assert_python_failure, temp_dir, - spawn_python, kill_python) + assert_python_ok, assert_python_failure, spawn_python, kill_python) # Look up which start methods are available to test import multiprocessing AVAILABLE_START_METHODS = set(multiprocessing.get_all_start_methods()) # Issue #22332: Skip tests if sem_open implementation is broken. support.import_module('multiprocessing.synchronize') @@ -152,117 +151,117 @@ class MultiProcessingCmdLineMixin(): def _check_script(self, script_name, *cmd_line_switches): if not __debug__: cmd_line_switches += ('-' + 'O' * sys.flags.optimize,) run_args = cmd_line_switches + (script_name, self.start_method) rc, out, err = assert_python_ok(*run_args, __isolated=False) self._check_output(script_name, rc, out, err) def test_basic_script(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'script') self._check_script(script_name) def test_basic_script_no_suffix(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'script', omit_suffix=True) self._check_script(script_name) def test_ipython_workaround(self): # Some versions of the IPython launch script are missing the # __name__ = "__main__" guard, and multiprocessing has long had # a workaround for that case # See https://github.com/ipython/ipython/issues/4698 source = test_source_main_skipped_in_children - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'ipython', source=source) self._check_script(script_name) script_no_suffix = _make_test_script(script_dir, 'ipython', source=source, omit_suffix=True) self._check_script(script_no_suffix) def test_script_compiled(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, 'script') py_compile.compile(script_name, doraise=True) os.remove(script_name) pyc_file = support.make_legacy_pyc(script_name) self._check_script(pyc_file) def test_directory(self): source = self.main_in_children_source - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, '__main__', source=source) self._check_script(script_dir) def test_directory_compiled(self): source = self.main_in_children_source - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, '__main__', source=source) py_compile.compile(script_name, doraise=True) os.remove(script_name) pyc_file = support.make_legacy_pyc(script_name) self._check_script(script_dir) def test_zipfile(self): source = self.main_in_children_source - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, '__main__', source=source) zip_name, run_name = make_zip_script(script_dir, 'test_zip', script_name) self._check_script(zip_name) def test_zipfile_compiled(self): source = self.main_in_children_source - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: script_name = _make_test_script(script_dir, '__main__', source=source) compiled_name = py_compile.compile(script_name, doraise=True) zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name) self._check_script(zip_name) def test_module_in_package(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir) script_name = _make_test_script(pkg_dir, 'check_sibling') launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.check_sibling') self._check_script(launch_name) def test_module_in_package_in_zipfile(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script') launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.script', zip_name) self._check_script(launch_name) def test_module_in_subpackage_in_zipfile(self): - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: zip_name, run_name = _make_test_zip_pkg(script_dir, 'test_zip', 'test_pkg', 'script', depth=2) launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg.test_pkg.script', zip_name) self._check_script(launch_name) def test_package(self): source = self.main_in_children_source - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir) script_name = _make_test_script(pkg_dir, '__main__', source=source) launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') self._check_script(launch_name) def test_package_compiled(self): source = self.main_in_children_source - with temp_dir() as script_dir: + with support.temp_dir() as script_dir: pkg_dir = os.path.join(script_dir, 'test_pkg') make_pkg(pkg_dir) script_name = _make_test_script(pkg_dir, '__main__', source=source) compiled_name = py_compile.compile(script_name, doraise=True) os.remove(script_name) pyc_file = support.make_legacy_pyc(script_name) launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -59,17 +59,17 @@ try: all_users = [u.pw_uid for u in pwd.getpwall()] except ImportError: all_users = [] try: from _testcapi import INT_MAX, PY_SSIZE_T_MAX except ImportError: INT_MAX = PY_SSIZE_T_MAX = sys.maxsize -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok root_in_posix = False if hasattr(os, 'geteuid'): root_in_posix = (os.geteuid() == 0) with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) os.stat_float_times(True) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -1,15 +1,15 @@ import parser import unittest import sys import operator import struct from test import support -from test.script_helper import assert_python_failure +from test.support.script_helper import assert_python_failure # # First, we test that we can generate trees from valid source fragments, # and that these valid trees are indeed allowed by the tree-loading side # of the parser module. # class RoundtripLegalSyntaxTestCase(unittest.TestCase): diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -16,17 +16,17 @@ import test.support import time import types import unittest import urllib.parse import xml.etree import textwrap from io import StringIO from collections import namedtuple -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok from test.support import ( TESTFN, rmtree, reap_children, reap_threads, captured_output, captured_stdout, captured_stderr, unlink, requires_docstrings ) from test import pydoc_mod try: diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -1,16 +1,16 @@ """ Very minimal unittests for parts of the readline module. """ import os import tempfile import unittest from test.support import import_module, unlink -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok # Skip tests if there is no readline module readline = import_module('readline') class TestHistoryManipulation (unittest.TestCase): """ These tests were added to check that the libedit emulation on OSX and the "real" readline have the same interface for history manipulation. That's diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py --- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -4,19 +4,19 @@ import os import os.path import sys import re import tempfile import importlib, importlib.machinery, importlib.util import py_compile from test.support import ( forget, make_legacy_pyc, unload, verbose, no_tracing, - create_empty_file) -from test.script_helper import ( - make_pkg, make_script, make_zip_pkg, make_zip_script, temp_dir) + create_empty_file, temp_dir) +from test.support.script_helper import ( + make_pkg, make_script, make_zip_pkg, make_zip_script) import runpy from runpy import _run_code, _run_module_code, run_module, run_path # Note: This module can't safely test _run_module_as_main as it # runs its tests in the current process, which would mess with the # real __main__ module (usually test.regrtest) # See test_cmd_line_script for a test that executes that code path diff --git a/Lib/test/test_script_helper.py b/Lib/test/test_script_helper.py --- a/Lib/test/test_script_helper.py +++ b/Lib/test/test_script_helper.py @@ -1,13 +1,13 @@ -"""Unittests for test.script_helper. Who tests the test helper?""" +"""Unittests for test.support.script_helper. Who tests the test helper?""" import subprocess import sys -from test import script_helper +from test.support import script_helper import unittest from unittest import mock class TestScriptHelper(unittest.TestCase): def test_assert_python_ok(self): t = script_helper.assert_python_ok('-c', 'import sys; sys.exit(0)') diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -6,17 +6,17 @@ import gc import pickle import select import signal import socket import struct import subprocess import traceback import sys, os, time, errno -from test.script_helper import assert_python_ok, spawn_python +from test.support.script_helper import assert_python_ok, spawn_python try: import threading except ImportError: threading = None try: import _testcapi except ImportError: _testcapi = None diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1,10 +1,10 @@ import unittest -from test import script_helper +from test.support import script_helper from test import support import subprocess import sys import signal import io import locale import os import errno @@ -389,17 +389,17 @@ class ProcessTestCase(BaseTestCase): cwd=python_dir) def test_cwd_with_absolute_arg(self): # Check that Popen can find the executable when the cwd is wrong # if args[0] is an absolute path. python_dir, python_base = self._split_python_path() abs_python = os.path.join(python_dir, python_base) rel_python = os.path.join(os.curdir, python_base) - with script_helper.temp_dir() as wrong_dir: + with support.temp_dir() as wrong_dir: # Before calling with an absolute path, confirm that using a # relative path fails. self.assertRaises(FileNotFoundError, subprocess.Popen, [rel_python], cwd=wrong_dir) wrong_dir = self._normalize_cwd(wrong_dir) self._assert_cwd(wrong_dir, abs_python, cwd=wrong_dir) @unittest.skipIf(sys.base_prefix != sys.prefix, diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1,10 +1,10 @@ import unittest, test.support -from test.script_helper import assert_python_ok, assert_python_failure +from test.support.script_helper import assert_python_ok, assert_python_failure import sys, io, os import struct import subprocess import textwrap import warnings import operator import codecs import gc @@ -703,17 +703,17 @@ class SysModuleTest(unittest.TestCase): # PEP 421 requires that .name be lower case. self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) @test.support.cpython_only def test_debugmallocstats(self): # Test sys._debugmallocstats() - from test.script_helper import assert_python_ok + from test.support.script_helper import assert_python_ok args = ['-c', 'import sys; sys._debugmallocstats()'] ret, out, err = assert_python_ok(*args) self.assertIn(b"free PyDictObjects", err) # The function has no parameter self.assertRaises(TypeError, sys._debugmallocstats, True) @unittest.skipUnless(hasattr(sys, "getallocatedblocks"), diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -3,17 +3,18 @@ import os import io from hashlib import md5 from contextlib import contextmanager import unittest import unittest.mock import tarfile -from test import support, script_helper +from test import support +from test.support import script_helper # Check for our compression modules. try: import gzip except ImportError: gzip = None try: import bz2 diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -7,17 +7,18 @@ import signal import sys import re import warnings import contextlib import weakref from unittest import mock import unittest -from test import support, script_helper +from test import support +from test.support import script_helper if hasattr(os, 'stat'): import stat has_stat = 1 else: has_stat = 0 diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -1,15 +1,15 @@ """ Tests for the threading module. """ import test.support from test.support import verbose, strip_python_stderr, import_module, cpython_only -from test.script_helper import assert_python_ok, assert_python_failure +from test.support.script_helper import assert_python_ok, assert_python_failure import random import re import sys _thread = import_module('_thread') threading = import_module('threading') import time import unittest diff --git a/Lib/test/test_tools/test_md5sum.py b/Lib/test/test_tools/test_md5sum.py --- a/Lib/test/test_tools/test_md5sum.py +++ b/Lib/test/test_tools/test_md5sum.py @@ -1,15 +1,15 @@ """Tests for the md5sum script in the Tools directory.""" import os import sys import unittest from test import support -from test.script_helper import assert_python_ok, assert_python_failure +from test.support.script_helper import assert_python_ok, assert_python_failure from test.test_tools import scriptsdir, import_tool, skip_if_missing skip_if_missing() class MD5SumTests(unittest.TestCase): @classmethod def setUpClass(cls): diff --git a/Lib/test/test_tools/test_pindent.py b/Lib/test/test_tools/test_pindent.py --- a/Lib/test/test_tools/test_pindent.py +++ b/Lib/test/test_tools/test_pindent.py @@ -1,17 +1,17 @@ """Tests for the pindent script in the Tools directory.""" import os import sys import unittest import subprocess import textwrap from test import support -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok from test.test_tools import scriptsdir, skip_if_missing skip_if_missing() class PindentTests(unittest.TestCase): script = os.path.join(scriptsdir, 'pindent.py') diff --git a/Lib/test/test_tools/test_reindent.py b/Lib/test/test_tools/test_reindent.py --- a/Lib/test/test_tools/test_reindent.py +++ b/Lib/test/test_tools/test_reindent.py @@ -1,17 +1,17 @@ """Tests for scripts in the Tools directory. This file contains regression tests for some of the scripts found in the Tools directory of a Python checkout or tarball, such as reindent.py. """ import os import unittest -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok from test.test_tools import scriptsdir, skip_if_missing skip_if_missing() class ReindentTests(unittest.TestCase): script = os.path.join(scriptsdir, 'reindent.py') diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -2,17 +2,17 @@ from collections import namedtuple from io import StringIO import linecache import sys import unittest import re from test.support import TESTFN, Error, captured_output, unlink, cpython_only -from test.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok import textwrap import traceback test_code = namedtuple('code', ['co_filename', 'co_name']) test_frame = namedtuple('frame', ['f_code', 'f_globals', 'f_locals']) test_tb = namedtuple('tb', ['tb_frame', 'tb_lineno', 'tb_next']) diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py --- a/Lib/test/test_tracemalloc.py +++ b/Lib/test/test_tracemalloc.py @@ -1,16 +1,17 @@ import contextlib import os import sys import tracemalloc import unittest from unittest.mock import patch -from test.script_helper import assert_python_ok, assert_python_failure -from test import script_helper, support +from test.support.script_helper import assert_python_ok, assert_python_failure +from test import support +from test.support import script_helper try: import threading except ImportError: threading = None EMPTY_STRING_SIZE = sys.getsizeof(b'') def get_frames(nframe, lineno_delta): diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -1,16 +1,16 @@ from contextlib import contextmanager import linecache import os from io import StringIO import sys import unittest from test import support -from test.script_helper import assert_python_ok, assert_python_failure +from test.support.script_helper import assert_python_ok, assert_python_failure from test import warning_tests import warnings as original_warnings py_warnings = support.import_fresh_module('warnings', blocked=['_warnings']) c_warnings = support.import_fresh_module('warnings', fresh=['_warnings']) diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -2,17 +2,18 @@ import gc import sys import unittest import collections import weakref import operator import contextlib import copy -from test import support, script_helper +from test import support +from test.support import script_helper # Used in ReferencesTestCase.test_ref_created_during_del() . ref_from_del = None # Used by FinalizeTestCase as a global that may be replaced by None # when the interpreter shuts down. _global_var = 'foobar' diff --git a/Lib/test/test_zipimport_support.py b/Lib/test/test_zipimport_support.py --- a/Lib/test/test_zipimport_support.py +++ b/Lib/test/test_zipimport_support.py @@ -9,18 +9,18 @@ import sys import textwrap import zipfile import zipimport import doctest import inspect import linecache import pdb import unittest -from test.script_helper import (spawn_python, kill_python, assert_python_ok, - temp_dir, make_script, make_zip_script) +from test.support.script_helper import (spawn_python, kill_python, assert_python_ok, + make_script, make_zip_script) verbose = test.support.verbose # Library modules covered by this test set # pdb (Issue 4201) # inspect (Issue 4223) # doctest (Issue 4197) @@ -73,17 +73,17 @@ class ZipSupportTests(unittest.TestCase) def tearDown(self): sys.path[:] = self.path sys.meta_path[:] = self.meta_path sys.path_hooks[:] = self.path_hooks sys.path_importer_cache.clear() def test_inspect_getsource_issue4223(self): test_src = "def foo(): pass\n" - with temp_dir() as d: + with test.support.temp_dir() as d: init_name = make_script(d, '__init__', test_src) name_in_zip = os.path.join('zip_pkg', os.path.basename(init_name)) zip_name, run_name = make_zip_script(d, 'test_zip', init_name, name_in_zip) os.remove(init_name) sys.path.insert(0, zip_name) import zip_pkg @@ -113,17 +113,17 @@ class ZipSupportTests(unittest.TestCase) src = inspect.getsource(mod) src = src.replace("test.test_doctest", "test_zipped_doctest") # Rewrite the module name so that, for example, # "test.sample_doctest" becomes "sample_zipped_doctest". mod_name = mod.__name__.split(".")[-1] mod_name = mod_name.replace("sample_", "sample_zipped_") sample_sources[mod_name] = src - with temp_dir() as d: + with test.support.temp_dir() as d: script_name = make_script(d, 'test_zipped_doctest', test_src) zip_name, run_name = make_zip_script(d, 'test_zip', script_name) z = zipfile.ZipFile(zip_name, 'a') for mod_name, src in sample_sources.items(): z.writestr(mod_name + ".py", src) z.close() @@ -190,17 +190,17 @@ class ZipSupportTests(unittest.TestCase) class Test: ">>> 'line 2'" pass import doctest doctest.testmod() """) pattern = 'File "%s", line 2, in %s' - with temp_dir() as d: + with test.support.temp_dir() as d: script_name = make_script(d, 'script', test_src) rc, out, err = assert_python_ok(script_name) expected = pattern % (script_name, "__main__.Test") if verbose: print ("Expected line", expected) print ("Got stdout:") print (ascii(out)) self.assertIn(expected.encode('utf-8'), out) @@ -217,17 +217,17 @@ class ZipSupportTests(unittest.TestCase) def test_pdb_issue4201(self): test_src = textwrap.dedent("""\ def f(): pass import pdb pdb.Pdb(nosigint=True).runcall(f) """) - with temp_dir() as d: + with test.support.temp_dir() as d: script_name = make_script(d, 'script', test_src) p = spawn_python(script_name) p.stdin.write(b'l\n') data = kill_python(p) # bdb/pdb applies normcase to its filename before displaying self.assertIn(os.path.normcase(script_name.encode('utf-8')), data) zip_name, run_name = make_zip_script(d, "test_zip", script_name, '__main__.py')