diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-07-02 13:34:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-02 13:34:55 +0200 |
commit | c45e0d58bc0f949dd5db3aa9035e27e032b19ca1 (patch) | |
tree | 3391212bc1fc535c7fe766fdcf4ab4e8e63ec58a | |
parent | c53173aa00689aa1be17ce5406289718f6b30532 (diff) | |
download | cpython-git-c45e0d58bc0f949dd5db3aa9035e27e032b19ca1.tar.gz |
Revert "Remove unused imports in tests (GH-14518) (GH-14522)"revert-14522-remove_unused_imports37
This reverts commit e34b5f4d6483187969d5149c801d056b72ef2ddb.
48 files changed, 73 insertions, 22 deletions
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index e2274254fd..1dfbe47a2f 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -587,6 +587,7 @@ class Regrtest: def cleanup(self): import glob + import shutil path = os.path.join(self.tmp_dir, 'test_python_*') print("Cleanup %s directory" % self.tmp_dir) diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 6d10e8b576..87bfa9f546 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -5,6 +5,7 @@ if __name__ != 'test.support': import collections.abc import contextlib +import datetime import errno import faulthandler import fnmatch @@ -12,6 +13,7 @@ import functools import gc import importlib import importlib.util +import io import logging.handlers import nntplib import os diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py index e82cfc1a46..ff52f5b6fe 100644 --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -7,6 +7,7 @@ import io import sys import struct import aifc +import warnings class AifcTest(audiotests.AudioWriteTests, diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 0c342e2e4e..51f0effaf2 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -1,5 +1,6 @@ # Author: Steven J. Bethard <steven.bethard@gmail.com>. +import codecs import inspect import os import shutil diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py index 14c0ec43d4..1d147c7419 100644 --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -7,6 +7,7 @@ import asyncore import errno import socket import sys +import _thread as thread import threading import time import unittest diff --git a/Lib/test/test_asyncio/test_pep492.py b/Lib/test/test_asyncio/test_pep492.py index ac3ae6811f..f2d588f544 100644 --- a/Lib/test/test_asyncio/test_pep492.py +++ b/Lib/test/test_asyncio/test_pep492.py @@ -4,6 +4,7 @@ import sys import types import unittest +from test import support from unittest import mock import asyncio diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py index 3b9c12f24e..866ef81fb2 100644 --- a/Lib/test/test_asyncio/test_sslproto.py +++ b/Lib/test/test_asyncio/test_sslproto.py @@ -15,6 +15,7 @@ import asyncio from asyncio import log from asyncio import protocols from asyncio import sslproto +from asyncio import tasks from test.test_asyncio import utils as test_utils from test.test_asyncio import functional as func_tests diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py index 51d474cf15..ec171fa83d 100644 --- a/Lib/test/test_asyncio/test_unix_events.py +++ b/Lib/test/test_asyncio/test_unix_events.py @@ -22,6 +22,7 @@ if sys.platform == 'win32': import asyncio from asyncio import log +from asyncio import base_events from asyncio import events from asyncio import unix_events from test.test_asyncio import utils as test_utils diff --git a/Lib/test/test_c_locale_coercion.py b/Lib/test/test_c_locale_coercion.py index 94391c8799..0355547436 100644 --- a/Lib/test/test_c_locale_coercion.py +++ b/Lib/test/test_c_locale_coercion.py @@ -2,6 +2,7 @@ import locale import os +import shutil import subprocess import sys import sysconfig @@ -9,8 +10,10 @@ import unittest from collections import namedtuple import test.support -from test.support.script_helper import run_python_until_end - +from test.support.script_helper import ( + run_python_until_end, + interpreter_requires_environment, +) # Set the list of ways we expect to be able to ask for the "C" locale EXPECTED_C_LOCALE_EQUIVALENTS = ["C", "invalid.ascii"] diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 6eb3bd967b..d94ee0227c 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -8,6 +8,7 @@ import random import re import subprocess import sys +import sysconfig import textwrap import threading import time diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index f90bfb0674..95cdc8db7e 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -5,6 +5,7 @@ import os import subprocess import sys +import sysconfig import tempfile import unittest from test import support diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 1aca9facda..16735b815e 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -3,9 +3,11 @@ import collections import copy import doctest +import keyword import operator import pickle from random import choice, randrange +import re import string import sys from test import support diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index ced2290288..30c2e27b3c 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -1,5 +1,6 @@ """Unit tests for contextlib.py, and other context managers.""" +import asyncio import io import sys import tempfile diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py index f32320956b..ac24f39767 100644 --- a/Lib/test/test_coroutines.py +++ b/Lib/test/test_coroutines.py @@ -2,6 +2,7 @@ import contextlib import copy import inspect import pickle +import re import sys import types import unittest diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py index 116e626740..f077f05f5b 100644 --- a/Lib/test/test_docxmlrpc.py +++ b/Lib/test/test_docxmlrpc.py @@ -2,6 +2,7 @@ from xmlrpc.server import DocXMLRPCServer import http.client import sys import threading +from test import support import unittest def make_request_and_skipIf(condition, reason): diff --git a/Lib/test/test_email/test_policy.py b/Lib/test/test_email/test_policy.py index 1e39aa062c..0aea934df4 100644 --- a/Lib/test/test_email/test_policy.py +++ b/Lib/test/test_email/test_policy.py @@ -1,4 +1,5 @@ import io +import sys import types import textwrap import unittest diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 0196c4d000..9d10df5f94 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -9,7 +9,7 @@ import weakref import errno from test.support import (TESTFN, captured_stderr, check_impl_detail, - check_warnings, cpython_only, gc_collect, + check_warnings, cpython_only, gc_collect, run_unittest, no_tracing, unlink, import_module, script_helper, SuppressCrashReport) class NaiveException(Exception): diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index 5283596ceb..700b7ad6b8 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -9,6 +9,7 @@ import sysconfig from test import support from test.support import script_helper, is_android import tempfile +import threading import unittest from textwrap import dedent diff --git a/Lib/test/test_fork1.py b/Lib/test/test_fork1.py index 2ab856ff56..9ca9724c4c 100644 --- a/Lib/test/test_fork1.py +++ b/Lib/test/test_fork1.py @@ -10,7 +10,8 @@ import time import unittest from test.fork_wait import ForkWait -from test.support import reap_children, get_attribute, verbose +from test.support import (reap_children, get_attribute, + import_module, verbose) # Skip test if fork does not exist. diff --git a/Lib/test/test_frozen.py b/Lib/test/test_frozen.py index 142f17d518..a7c748422b 100644 --- a/Lib/test/test_frozen.py +++ b/Lib/test/test_frozen.py @@ -13,6 +13,7 @@ import sys import unittest from test.support import captured_stdout +from importlib import util class TestFrozen(unittest.TestCase): diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py index b78c0845b1..7758e1fcd8 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -3,6 +3,7 @@ # The code for testing gdb was adapted from similar work in Unladen Swallow's # Lib/test/test_jit_gdb.py +import locale import os import platform import re diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index c45086562d..7a21cb7e95 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -3,6 +3,7 @@ import gc import pickle import sys import unittest +import warnings import weakref import inspect diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index fac38000e6..b5ed05eab7 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -1,6 +1,7 @@ import os import base64 import gettext +import locale import unittest from test import support diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 241ac853d7..88c22b89d4 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -4,6 +4,7 @@ from test.support import check_syntax_error import inspect import unittest +import sys # testing import * from sys import * @@ -11,6 +12,7 @@ from sys import * # with import machinery import test.ann_module as ann_module import typing +from collections import ChainMap from test import ann_module2 import test diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index 8ab532af3f..9305e47ee9 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -1,6 +1,7 @@ from test import support from contextlib import contextmanager +import errno import imaplib import os.path import socketserver diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 4c4f0d9efc..1fc4de11e1 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -5,6 +5,7 @@ from importlib._bootstrap_external import _get_sourcefile import builtins import marshal import os +import platform import py_compile import random import stat @@ -19,9 +20,9 @@ import contextlib import test.support from test.support import ( - TESTFN, forget, is_jython, - make_legacy_pyc, rmtree, swap_attr, swap_item, temp_umask, - unlink, unload, cpython_only, TESTFN_UNENCODABLE, + 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, temp_dir, DirsOnSysPath) from test.support import script_helper from test.test_importlib.util import uncache diff --git a/Lib/test/test_importlib/test_locks.py b/Lib/test/test_importlib/test_locks.py index 21794d911e..d86172ab58 100644 --- a/Lib/test/test_importlib/test_locks.py +++ b/Lib/test/test_importlib/test_locks.py @@ -4,6 +4,7 @@ init = test_util.import_importlib('importlib') import sys import threading +import unittest import weakref from test import support diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py index 792a15c50f..e2c2178ae6 100644 --- a/Lib/test/test_locale.py +++ b/Lib/test/test_locale.py @@ -3,7 +3,7 @@ import unittest import locale import sys import codecs - +import warnings class BaseLocalizedTest(unittest.TestCase): # diff --git a/Lib/test/test_netrc.py b/Lib/test/test_netrc.py index ae53988c45..f59e5371ac 100644 --- a/Lib/test/test_netrc.py +++ b/Lib/test/test_netrc.py @@ -1,4 +1,5 @@ import netrc, os, unittest, sys, tempfile, textwrap +from unittest import mock from test import support diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 1ec9a6a950..8032da0530 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -9,6 +9,7 @@ import contextlib import decimal import errno import fractions +import getpass import itertools import locale import mmap diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 6bca89003a..e73b31cb64 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -1,6 +1,7 @@ import os import posixpath import unittest +import warnings from posixpath import realpath, abspath, dirname, basename from test import support, test_genericpath from test.support import FakePath @@ -11,7 +12,6 @@ try: except ImportError: posix = None - # An absolute path to a temporary filename for testing. We can't rely on TESTFN # being an absolute path, so we need this. diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py index 0489b41d7c..eaab591f74 100644 --- a/Lib/test/test_pyclbr.py +++ b/Lib/test/test_pyclbr.py @@ -3,11 +3,14 @@ Nick Mathewson ''' +import os import sys from textwrap import dedent from types import FunctionType, MethodType, BuiltinFunctionType import pyclbr from unittest import TestCase, main as unittest_main +from test import support +from functools import partial StaticMethodType = type(staticmethod(lambda: None)) ClassMethodType = type(classmethod(lambda c: None)) diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 8e30b4c8f6..198cea93eb 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -21,6 +21,7 @@ import urllib.parse import xml.etree import xml.etree.ElementTree import textwrap +import threading from io import StringIO from collections import namedtuple from test.support.script_helper import assert_python_ok diff --git a/Lib/test/test_queue.py b/Lib/test/test_queue.py index c8528f9774..1a8d5f8856 100644 --- a/Lib/test/test_queue.py +++ b/Lib/test/test_queue.py @@ -1,8 +1,10 @@ # Some simple queue module tests, plus some failure conditions # to ensure the Queue locks remain stable. +import collections import itertools import queue import random +import sys import threading import time import unittest diff --git a/Lib/test/test_resource.py b/Lib/test/test_resource.py index 62c7963fe6..b07eb73b2a 100644 --- a/Lib/test/test_resource.py +++ b/Lib/test/test_resource.py @@ -1,5 +1,6 @@ import contextlib import sys +import os import unittest from test import support import time diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py index 0da6f3a604..02b4d62567 100644 --- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -11,7 +11,8 @@ import warnings from test.support import ( forget, make_legacy_pyc, unload, verbose, no_tracing, create_empty_file, temp_dir) -from test.support.script_helper import make_script, make_zip_script +from test.support.script_helper import ( + make_pkg, make_script, make_zip_pkg, make_zip_script) import runpy diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 251a03a54d..3044960a0e 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -17,6 +17,7 @@ from xml.sax.handler import feature_namespaces, feature_external_ges from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl from io import BytesIO, StringIO import codecs +import gc import os.path import shutil from urllib.error import URLError diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index c3f5b14844..406684bdbe 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -5,6 +5,7 @@ import socket import statistics import subprocess import sys +import threading import time import unittest from test import support diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py index 4add8fcabf..b4149d3ef0 100644 --- a/Lib/test/test_smtplib.py +++ b/Lib/test/test_smtplib.py @@ -19,7 +19,7 @@ import threading import unittest from test import support, mock_socket -from test.support import HOST +from test.support import HOST, HOSTv4, HOSTv6 from unittest.mock import Mock diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 36cf22a9f8..8419061b2a 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -3,6 +3,7 @@ from unittest import mock from test import support import subprocess import sys +import platform import signal import io import itertools @@ -20,11 +21,17 @@ import textwrap from test.support import FakePath try: + import ctypes +except ImportError: + ctypes = None +else: + import ctypes.util + +try: import _testcapi except ImportError: _testcapi = None - if support.PGO: raise unittest.SkipTest("test is not helpful for PGO") diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index f4eb830cf6..64ffe46052 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -4,6 +4,7 @@ import random from test import support import _thread as thread import time +import sys import weakref from test import lock_tests diff --git a/Lib/test/test_threaded_import.py b/Lib/test/test_threaded_import.py index 8607f363db..035344be4b 100644 --- a/Lib/test/test_threaded_import.py +++ b/Lib/test/test_threaded_import.py @@ -15,7 +15,7 @@ import threading import unittest from unittest import mock from test.support import ( - verbose, run_unittest, TESTFN, reap_threads, + verbose, import_module, run_unittest, TESTFN, reap_threads, forget, unlink, rmtree, start_threads) def task(N, done, done_tasks, errors): diff --git a/Lib/test/test_threadedtempfile.py b/Lib/test/test_threadedtempfile.py index e1d7a10179..f3d4ba3637 100644 --- a/Lib/test/test_threadedtempfile.py +++ b/Lib/test/test_threadedtempfile.py @@ -13,22 +13,19 @@ quickly. Guido reports needing to boost FILES_PER_THREAD to 500 before provoking a 2.0 failure under Linux. """ +NUM_THREADS = 20 +FILES_PER_THREAD = 50 + import tempfile -from test.support import start_threads +from test.support import start_threads, import_module import unittest import io import threading from traceback import print_exc - -NUM_THREADS = 20 -FILES_PER_THREAD = 50 - - startEvent = threading.Event() - class TempFileGreedy(threading.Thread): error_count = 0 ok_count = 0 diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 35952799ba..4e31abf4ec 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -9,6 +9,7 @@ import sysconfig import time import threading import unittest +import warnings try: import _testcapi except ImportError: diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index 7457a7ed04..d596f7db61 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -1,7 +1,7 @@ from test import support from tokenize import (tokenize, _tokenize, untokenize, NUMBER, NAME, OP, STRING, ENDMARKER, ENCODING, tok_name, detect_encoding, - open as tokenize_open, Untokenizer, + open as tokenize_open, Untokenizer, generate_tokens, NEWLINE) from io import BytesIO import unittest diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 8749d095dd..8a3aa8a864 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -110,7 +110,7 @@ class TracebackCases(unittest.TestCase): # Test that tracebacks are correctly printed for encoded source files: # - correct line number (Issue2384) # - respect file encoding (Issue3975) - import sys, subprocess + import tempfile, sys, subprocess, os # The spawned subprocess has its stdout redirected to a PIPE, and its # encoding may be different from the current interpreter, on Windows diff --git a/Lib/test/test_utf8_mode.py b/Lib/test/test_utf8_mode.py index a7d1dc940a..06fe1979dd 100644 --- a/Lib/test/test_utf8_mode.py +++ b/Lib/test/test_utf8_mode.py @@ -3,6 +3,7 @@ Test the implementation of the PEP 540: the UTF-8 Mode. """ import locale +import os import sys import textwrap import unittest diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 3821d9accf..67f9f46e65 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -15,6 +15,7 @@ import sys import tempfile from test.support import (captured_stdout, captured_stderr, requires_zlib, can_symlink, EnvironmentVarGuard, rmtree) +import threading import unittest import venv |