diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-07-01 18:02:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-01 18:02:39 (GMT) |
commit | e34b5f4d6483187969d5149c801d056b72ef2ddb (patch) | |
tree | f2a975aa16be21fc1a213856f5243194a17a2103 | |
parent | 8cbffc4d96d1da0fbc38da6f34f2da30c5ffd601 (diff) | |
download | cpython-e34b5f4d6483187969d5149c801d056b72ef2ddb.zip cpython-e34b5f4d6483187969d5149c801d056b72ef2ddb.tar.gz cpython-e34b5f4d6483187969d5149c801d056b72ef2ddb.tar.bz2 |
Remove unused imports in tests (GH-14518) (GH-14522)
(cherry picked from commit 8f4ef3b019ce380022018587571b0f970e668de3)
48 files changed, 22 insertions, 73 deletions
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 1dfbe47..e227425 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -587,7 +587,6 @@ 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 87bfa9f..6d10e8b 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -5,7 +5,6 @@ if __name__ != 'test.support': import collections.abc import contextlib -import datetime import errno import faulthandler import fnmatch @@ -13,7 +12,6 @@ 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 ff52f5b..e82cfc1 100644 --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -7,7 +7,6 @@ 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 51f0eff..0c342e2 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -1,6 +1,5 @@ # 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 1d147c7..14c0ec4 100644 --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -7,7 +7,6 @@ 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 f2d588f..ac3ae68 100644 --- a/Lib/test/test_asyncio/test_pep492.py +++ b/Lib/test/test_asyncio/test_pep492.py @@ -4,7 +4,6 @@ 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 866ef81..3b9c12f 100644 --- a/Lib/test/test_asyncio/test_sslproto.py +++ b/Lib/test/test_asyncio/test_sslproto.py @@ -15,7 +15,6 @@ 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 ec171fa..51d474c 100644 --- a/Lib/test/test_asyncio/test_unix_events.py +++ b/Lib/test/test_asyncio/test_unix_events.py @@ -22,7 +22,6 @@ 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 134f07a..f2351fa 100644 --- a/Lib/test/test_c_locale_coercion.py +++ b/Lib/test/test_c_locale_coercion.py @@ -2,7 +2,6 @@ import locale import os -import shutil import subprocess import sys import sysconfig @@ -10,10 +9,8 @@ import unittest from collections import namedtuple import test.support -from test.support.script_helper import ( - run_python_until_end, - interpreter_requires_environment, -) +from test.support.script_helper import run_python_until_end + # 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 d94ee02..6eb3bd9 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -8,7 +8,6 @@ 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 95cdc8d..f90bfb0 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -5,7 +5,6 @@ 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 16735b8..1aca9fa 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -3,11 +3,9 @@ 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 30c2e27..ced2290 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -1,6 +1,5 @@ """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 ac24f39..f323209 100644 --- a/Lib/test/test_coroutines.py +++ b/Lib/test/test_coroutines.py @@ -2,7 +2,6 @@ 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 f077f05..116e626 100644 --- a/Lib/test/test_docxmlrpc.py +++ b/Lib/test/test_docxmlrpc.py @@ -2,7 +2,6 @@ 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 0aea934..1e39aa0 100644 --- a/Lib/test/test_email/test_policy.py +++ b/Lib/test/test_email/test_policy.py @@ -1,5 +1,4 @@ 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 9d10df5..0196c4d 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, run_unittest, + check_warnings, cpython_only, gc_collect, 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 700b7ad..5283596 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -9,7 +9,6 @@ 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 9ca9724..2ab856f 100644 --- a/Lib/test/test_fork1.py +++ b/Lib/test/test_fork1.py @@ -10,8 +10,7 @@ import time import unittest from test.fork_wait import ForkWait -from test.support import (reap_children, get_attribute, - import_module, verbose) +from test.support import reap_children, get_attribute, verbose # Skip test if fork does not exist. diff --git a/Lib/test/test_frozen.py b/Lib/test/test_frozen.py index a7c7484..142f17d 100644 --- a/Lib/test/test_frozen.py +++ b/Lib/test/test_frozen.py @@ -13,7 +13,6 @@ 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 7758e1f..b78c084 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -3,7 +3,6 @@ # 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 7a21cb7..c450865 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -3,7 +3,6 @@ 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 b5ed05e..fac3800 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -1,7 +1,6 @@ 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 88c22b8..241ac85 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -4,7 +4,6 @@ from test.support import check_syntax_error import inspect import unittest -import sys # testing import * from sys import * @@ -12,7 +11,6 @@ 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 9305e47..8ab532a 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -1,7 +1,6 @@ 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 1fc4de1..4c4f0d9 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -5,7 +5,6 @@ from importlib._bootstrap_external import _get_sourcefile import builtins import marshal import os -import platform import py_compile import random import stat @@ -20,9 +19,9 @@ 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, + TESTFN, forget, is_jython, + make_legacy_pyc, rmtree, swap_attr, swap_item, temp_umask, + unlink, unload, 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 d86172a..21794d9 100644 --- a/Lib/test/test_importlib/test_locks.py +++ b/Lib/test/test_importlib/test_locks.py @@ -4,7 +4,6 @@ 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 e2c2178..792a15c 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 f59e537..ae53988 100644 --- a/Lib/test/test_netrc.py +++ b/Lib/test/test_netrc.py @@ -1,5 +1,4 @@ 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 8032da0..1ec9a6a 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -9,7 +9,6 @@ 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 e73b31c..6bca890 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -1,7 +1,6 @@ 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 @@ -12,6 +11,7 @@ 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 eaab591..0489b41 100644 --- a/Lib/test/test_pyclbr.py +++ b/Lib/test/test_pyclbr.py @@ -3,14 +3,11 @@ 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 198cea9..8e30b4c 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -21,7 +21,6 @@ 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 1a8d5f8..c8528f9 100644 --- a/Lib/test/test_queue.py +++ b/Lib/test/test_queue.py @@ -1,10 +1,8 @@ # 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 b07eb73..62c7963 100644 --- a/Lib/test/test_resource.py +++ b/Lib/test/test_resource.py @@ -1,6 +1,5 @@ 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 02b4d62..0da6f3a 100644 --- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -11,8 +11,7 @@ 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_pkg, make_script, make_zip_pkg, make_zip_script) +from test.support.script_helper import make_script, make_zip_script import runpy diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 3044960..251a03a 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -17,7 +17,6 @@ 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 406684b..c3f5b14 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -5,7 +5,6 @@ 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 b4149d3..4add8fc 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, HOSTv4, HOSTv6 +from test.support import HOST from unittest.mock import Mock diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 8419061..36cf22a 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -3,7 +3,6 @@ from unittest import mock from test import support import subprocess import sys -import platform import signal import io import itertools @@ -21,17 +20,11 @@ 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 64ffe46..f4eb830 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -4,7 +4,6 @@ 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 035344b..8607f36 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, import_module, run_unittest, TESTFN, reap_threads, + verbose, 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 f3d4ba3..e1d7a10 100644 --- a/Lib/test/test_threadedtempfile.py +++ b/Lib/test/test_threadedtempfile.py @@ -13,19 +13,22 @@ 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, import_module +from test.support import start_threads 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 4e31abf..3595279 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -9,7 +9,6 @@ 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 d596f7d..7457a7e 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, generate_tokens, + open as tokenize_open, Untokenizer, NEWLINE) from io import BytesIO import unittest diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 8a3aa8a..8749d09 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 tempfile, sys, subprocess, os + import sys, subprocess # 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 06fe197..a7d1dc9 100644 --- a/Lib/test/test_utf8_mode.py +++ b/Lib/test/test_utf8_mode.py @@ -3,7 +3,6 @@ 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 67f9f46..3821d9a 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -15,7 +15,6 @@ import sys import tempfile from test.support import (captured_stdout, captured_stderr, requires_zlib, can_symlink, EnvironmentVarGuard, rmtree) -import threading import unittest import venv |