[Python-checkins] Remove unused imports in tests (GH-14518) (GH-14522)
Victor Stinner
webhook-mailer at python.org
Mon Jul 1 14:02:43 EDT 2019
https://github.com/python/cpython/commit/e34b5f4d6483187969d5149c801d056b72ef2ddb
commit: e34b5f4d6483187969d5149c801d056b72ef2ddb
branch: 3.7
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-07-01T20:02:39+02:00
summary:
Remove unused imports in tests (GH-14518) (GH-14522)
(cherry picked from commit 8f4ef3b019ce380022018587571b0f970e668de3)
files:
M Lib/test/libregrtest/main.py
M Lib/test/support/__init__.py
M Lib/test/test_aifc.py
M Lib/test/test_argparse.py
M Lib/test/test_asynchat.py
M Lib/test/test_asyncio/test_pep492.py
M Lib/test/test_asyncio/test_sslproto.py
M Lib/test/test_asyncio/test_unix_events.py
M Lib/test/test_c_locale_coercion.py
M Lib/test/test_capi.py
M Lib/test/test_cmd_line.py
M Lib/test/test_collections.py
M Lib/test/test_contextlib.py
M Lib/test/test_coroutines.py
M Lib/test/test_docxmlrpc.py
M Lib/test/test_email/test_policy.py
M Lib/test/test_exceptions.py
M Lib/test/test_faulthandler.py
M Lib/test/test_fork1.py
M Lib/test/test_frozen.py
M Lib/test/test_gdb.py
M Lib/test/test_generators.py
M Lib/test/test_gettext.py
M Lib/test/test_grammar.py
M Lib/test/test_imaplib.py
M Lib/test/test_import/__init__.py
M Lib/test/test_importlib/test_locks.py
M Lib/test/test_locale.py
M Lib/test/test_netrc.py
M Lib/test/test_os.py
M Lib/test/test_posixpath.py
M Lib/test/test_pyclbr.py
M Lib/test/test_pydoc.py
M Lib/test/test_queue.py
M Lib/test/test_resource.py
M Lib/test/test_runpy.py
M Lib/test/test_sax.py
M Lib/test/test_signal.py
M Lib/test/test_smtplib.py
M Lib/test/test_subprocess.py
M Lib/test/test_thread.py
M Lib/test/test_threaded_import.py
M Lib/test/test_threadedtempfile.py
M Lib/test/test_time.py
M Lib/test/test_tokenize.py
M Lib/test/test_traceback.py
M Lib/test/test_utf8_mode.py
M Lib/test/test_venv.py
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
index 1dfbe47a2fab..e2274254fdb8 100644
--- a/Lib/test/libregrtest/main.py
+++ b/Lib/test/libregrtest/main.py
@@ -587,7 +587,6 @@ def create_temp_dir(self):
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 87bfa9f54627..6d10e8b576e4 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -5,7 +5,6 @@
import collections.abc
import contextlib
-import datetime
import errno
import faulthandler
import fnmatch
@@ -13,7 +12,6 @@
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 ff52f5b6feb8..e82cfc1a4690 100644
--- a/Lib/test/test_aifc.py
+++ b/Lib/test/test_aifc.py
@@ -7,7 +7,6 @@
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 51f0effaf2ff..0c342e2e4e0d 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -1,6 +1,5 @@
# Author: Steven J. Bethard <steven.bethard at 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 1d147c741961..14c0ec43d422 100644
--- a/Lib/test/test_asynchat.py
+++ b/Lib/test/test_asynchat.py
@@ -7,7 +7,6 @@
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 f2d588f54445..ac3ae6811fb5 100644
--- a/Lib/test/test_asyncio/test_pep492.py
+++ b/Lib/test/test_asyncio/test_pep492.py
@@ -4,7 +4,6 @@
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 866ef81fb2ee..3b9c12f24ed3 100644
--- a/Lib/test/test_asyncio/test_sslproto.py
+++ b/Lib/test/test_asyncio/test_sslproto.py
@@ -15,7 +15,6 @@
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 ec171fa83da3..51d474cf152c 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -22,7 +22,6 @@
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 134f07a17ec1..f2351fa5a2ea 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 @@
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 d94ee0227c87..6eb3bd967b86 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -8,7 +8,6 @@
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 95cdc8db7efb..f90bfb067483 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 16735b815e53..1aca9facda69 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 30c2e27b3c7e..ced2290288db 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 ac24f3976738..f32320956bcc 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -2,7 +2,6 @@
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 f077f05f5b4f..116e626740df 100644
--- a/Lib/test/test_docxmlrpc.py
+++ b/Lib/test/test_docxmlrpc.py
@@ -2,7 +2,6 @@
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 0aea934df434..1e39aa062c0a 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 9d10df5f9425..0196c4d0005b 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -9,7 +9,7 @@
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 700b7ad6b885..5283596cebe4 100644
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -9,7 +9,6 @@
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 9ca9724c4c91..2ab856ff5690 100644
--- a/Lib/test/test_fork1.py
+++ b/Lib/test/test_fork1.py
@@ -10,8 +10,7 @@
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 a7c748422b1d..142f17d518e7 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 7758e1fcd86c..b78c0845b1df 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 7a21cb7e954a..c45086562d36 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -3,7 +3,6 @@
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 b5ed05eab7bb..fac38000e635 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 88c22b89d444..241ac853d73c 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 @@
# 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 9305e47ee993..8ab532af3f0d 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 1fc4de11e178..4c4f0d9efc03 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -5,7 +5,6 @@
import builtins
import marshal
import os
-import platform
import py_compile
import random
import stat
@@ -20,9 +19,9 @@
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 d86172ab5837..21794d911ef6 100644
--- a/Lib/test/test_importlib/test_locks.py
+++ b/Lib/test/test_importlib/test_locks.py
@@ -4,7 +4,6 @@
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 e2c2178ae6cc..792a15c50f92 100644
--- a/Lib/test/test_locale.py
+++ b/Lib/test/test_locale.py
@@ -3,7 +3,7 @@
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 f59e5371acad..ae53988c45a6 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 8032da053067..1ec9a6a95091 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -9,7 +9,6 @@
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 e73b31cb648b..6bca89003a97 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 @@
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 eaab591f74ef..0489b41d7c7b 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 198cea93eb52..8e30b4c8f675 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -21,7 +21,6 @@
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 1a8d5f8856c5..c8528f97741d 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 b07eb73b2aeb..62c7963fe699 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 02b4d62567e5..0da6f3a60430 100644
--- a/Lib/test/test_runpy.py
+++ b/Lib/test/test_runpy.py
@@ -11,8 +11,7 @@
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 3044960a0ed1..251a03a54ddc 100644
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -17,7 +17,6 @@
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 406684bdbec7..c3f5b148448c 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -5,7 +5,6 @@
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 b4149d3ef007..4add8fcabfd1 100644
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -19,7 +19,7 @@
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 8419061b2a90..36cf22a9f898 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -3,7 +3,6 @@
from test import support
import subprocess
import sys
-import platform
import signal
import io
import itertools
@@ -20,18 +19,12 @@
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 64ffe4605298..f4eb830cf6d7 100644
--- a/Lib/test/test_thread.py
+++ b/Lib/test/test_thread.py
@@ -4,7 +4,6 @@
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 035344be4b89..8607f363db21 100644
--- a/Lib/test/test_threaded_import.py
+++ b/Lib/test/test_threaded_import.py
@@ -15,7 +15,7 @@
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 f3d4ba36377d..e1d7a10179cc 100644
--- a/Lib/test/test_threadedtempfile.py
+++ b/Lib/test/test_threadedtempfile.py
@@ -13,19 +13,22 @@
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 4e31abf4ec8e..35952799ba6d 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -9,7 +9,6 @@
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 d596f7db61ab..7457a7ed0434 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 8a3aa8a8648f..8749d095ddee 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -110,7 +110,7 @@ def test_encoded_file(self):
# 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 06fe1979ddcc..a7d1dc940ad6 100644
--- a/Lib/test/test_utf8_mode.py
+++ b/Lib/test/test_utf8_mode.py
@@ -3,7 +3,6 @@
"""
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 67f9f46e65e0..3821d9accfdf 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -15,7 +15,6 @@
import tempfile
from test.support import (captured_stdout, captured_stderr, requires_zlib,
can_symlink, EnvironmentVarGuard, rmtree)
-import threading
import unittest
import venv
More information about the Python-checkins
mailing list