Remove unused imports in tests (GH-14518)

This commit is contained in:
Victor Stinner 2019-07-01 18:28:25 +02:00 committed by GitHub
parent f9b7457bd7
commit 8f4ef3b019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 31 additions and 84 deletions

View File

@ -587,7 +587,6 @@ class Regrtest:
def cleanup(self): def cleanup(self):
import glob import glob
import shutil
path = os.path.join(self.tmp_dir, 'test_python_*') path = os.path.join(self.tmp_dir, 'test_python_*')
print("Cleanup %s directory" % self.tmp_dir) print("Cleanup %s directory" % self.tmp_dir)

View File

@ -6,7 +6,6 @@ if __name__ != 'test.support':
import asyncio.events import asyncio.events
import collections.abc import collections.abc
import contextlib import contextlib
import datetime
import errno import errno
import faulthandler import faulthandler
import fnmatch import fnmatch
@ -15,7 +14,6 @@ import gc
import glob import glob
import importlib import importlib
import importlib.util import importlib.util
import io
import logging.handlers import logging.handlers
import nntplib import nntplib
import os import os

View File

@ -4,7 +4,7 @@ import itertools
import os import os
import pickle import pickle
import sys import sys
from textwrap import dedent, indent from textwrap import dedent
import threading import threading
import time import time
import unittest import unittest

View File

@ -1,6 +1,5 @@
# Author: Steven J. Bethard <steven.bethard@gmail.com>. # Author: Steven J. Bethard <steven.bethard@gmail.com>.
import codecs
import inspect import inspect
import os import os
import shutil import shutil

View File

@ -7,7 +7,6 @@ import asyncore
import errno import errno
import socket import socket
import sys import sys
import _thread as thread
import threading import threading
import time import time
import unittest import unittest

View File

@ -26,8 +26,6 @@ if sys.platform != 'win32':
import tty import tty
import asyncio import asyncio
from asyncio import base_events
from asyncio import constants
from asyncio import coroutines from asyncio import coroutines
from asyncio import events from asyncio import events
from asyncio import proactor_events from asyncio import proactor_events

View File

@ -4,7 +4,6 @@ import sys
import types import types
import unittest import unittest
from test import support
from unittest import mock from unittest import mock
import asyncio import asyncio

View File

@ -4,11 +4,9 @@ import io
import socket import socket
import unittest import unittest
import sys import sys
from collections import deque
from unittest import mock from unittest import mock
import asyncio import asyncio
from asyncio import events
from asyncio.proactor_events import BaseProactorEventLoop from asyncio.proactor_events import BaseProactorEventLoop
from asyncio.proactor_events import _ProactorSocketTransport from asyncio.proactor_events import _ProactorSocketTransport
from asyncio.proactor_events import _ProactorWritePipeTransport from asyncio.proactor_events import _ProactorWritePipeTransport

View File

@ -1,5 +1,4 @@
import asyncio import asyncio
import socket
import time import time
import threading import threading
import unittest import unittest

View File

@ -15,7 +15,6 @@ import asyncio
from asyncio import log from asyncio import log
from asyncio import protocols from asyncio import protocols
from asyncio import sslproto from asyncio import sslproto
from asyncio import tasks
from test.test_asyncio import utils as test_utils from test.test_asyncio import utils as test_utils
from test.test_asyncio import functional as func_tests from test.test_asyncio import functional as func_tests

View File

@ -22,8 +22,6 @@ if sys.platform == 'win32':
import asyncio import asyncio
from asyncio import log from asyncio import log
from asyncio import base_events
from asyncio import events
from asyncio import unix_events from asyncio import unix_events
from test.test_asyncio import utils as test_utils from test.test_asyncio import utils as test_utils

View File

@ -2,7 +2,6 @@ import os
import signal import signal
import socket import socket
import sys import sys
import subprocess
import time import time
import threading import threading
import unittest import unittest
@ -12,14 +11,12 @@ if sys.platform != 'win32':
raise unittest.SkipTest('Windows only') raise unittest.SkipTest('Windows only')
import _overlapped import _overlapped
import _testcapi
import _winapi import _winapi
import asyncio import asyncio
from asyncio import windows_events from asyncio import windows_events
from asyncio.streams import _StreamProtocol from asyncio.streams import _StreamProtocol
from test.test_asyncio import utils as test_utils from test.test_asyncio import utils as test_utils
from test.support.script_helper import spawn_python
def tearDownModule(): def tearDownModule():

View File

@ -1,7 +1,6 @@
"""Tests for sys.audit and sys.addaudithook """Tests for sys.audit and sys.addaudithook
""" """
import os
import subprocess import subprocess
import sys import sys
import unittest import unittest

View File

@ -2,7 +2,6 @@
import locale import locale
import os import os
import shutil
import subprocess import subprocess
import sys import sys
import sysconfig import sysconfig
@ -10,10 +9,8 @@ import unittest
from collections import namedtuple from collections import namedtuple
from test import support from test import support
from test.support.script_helper import ( from test.support.script_helper import run_python_until_end
run_python_until_end,
interpreter_requires_environment,
)
# Set the list of ways we expect to be able to ask for the "C" locale # Set the list of ways we expect to be able to ask for the "C" locale
EXPECTED_C_LOCALE_EQUIVALENTS = ["C", "invalid.ascii"] EXPECTED_C_LOCALE_EQUIVALENTS = ["C", "invalid.ascii"]

View File

@ -8,7 +8,6 @@ import random
import re import re
import subprocess import subprocess
import sys import sys
import sysconfig
import textwrap import textwrap
import threading import threading
import time import time

View File

@ -1,4 +1,3 @@
from test.support import check_warnings
import cgi import cgi
import os import os
import sys import sys

View File

@ -6,7 +6,7 @@ import cmath, math
from cmath import phase, polar, rect, pi from cmath import phase, polar, rect, pi
import platform import platform
import sys import sys
import sysconfig
INF = float('inf') INF = float('inf')
NAN = float('nan') NAN = float('nan')

View File

@ -5,7 +5,6 @@
import os import os
import subprocess import subprocess
import sys import sys
import sysconfig
import tempfile import tempfile
import unittest import unittest
from test import support from test import support

View File

@ -1,10 +1,10 @@
import codecs import codecs
import html.entities import html.entities
import sys import sys
import test.support
import unicodedata import unicodedata
import unittest import unittest
class PosReturn: class PosReturn:
# this can be used for configurable callbacks # this can be used for configurable callbacks

View File

@ -29,7 +29,7 @@ def coding_checker(self, coder):
# On small versions of Windows like Windows IoT or Windows Nano Server not all codepages are present # On small versions of Windows like Windows IoT or Windows Nano Server not all codepages are present
def is_code_page_present(cp): def is_code_page_present(cp):
from ctypes import POINTER, WINFUNCTYPE, windll, WinError, Structure, WinDLL from ctypes import POINTER, WINFUNCTYPE, WinDLL
from ctypes.wintypes import BOOL, UINT, BYTE, WCHAR, UINT, DWORD from ctypes.wintypes import BOOL, UINT, BYTE, WCHAR, UINT, DWORD
MAX_LEADBYTES = 12 # 5 ranges, 2 bytes ea., 0 term. MAX_LEADBYTES = 12 # 5 ranges, 2 bytes ea., 0 term.

View File

@ -13,7 +13,7 @@ from test import support
import types import types
import unittest import unittest
from collections import namedtuple, Counter, OrderedDict, _count_elements, _tuplegetter from collections import namedtuple, Counter, OrderedDict, _count_elements
from collections import UserDict, UserString, UserList from collections import UserDict, UserString, UserList
from collections import ChainMap from collections import ChainMap
from collections import deque from collections import deque

View File

@ -6,7 +6,7 @@ import unittest
# rip off all interesting stuff from test_profile # rip off all interesting stuff from test_profile
import cProfile import cProfile
from test.test_profile import ProfileTest, regenerate_expected_output from test.test_profile import ProfileTest, regenerate_expected_output
from test.support.script_helper import assert_python_failure, assert_python_ok from test.support.script_helper import assert_python_failure
from test import support from test import support

View File

@ -2,7 +2,6 @@ from xmlrpc.server import DocXMLRPCServer
import http.client import http.client
import sys import sys
import threading import threading
from test import support
import unittest import unittest
def make_request_and_skipIf(condition, reason): def make_request_and_skipIf(condition, reason):

View File

@ -1,5 +1,4 @@
import io import io
import sys
import types import types
import textwrap import textwrap
import unittest import unittest

View File

@ -5,7 +5,6 @@ import unittest
from collections import namedtuple from collections import namedtuple
import json import json
import os import os
import platform
import re import re
import subprocess import subprocess
import sys import sys

View File

@ -9,7 +9,7 @@ import weakref
import errno import errno
from test.support import (TESTFN, captured_stderr, check_impl_detail, 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, no_tracing, unlink, import_module, script_helper,
SuppressCrashReport) SuppressCrashReport)
from test import support from test import support

View File

@ -9,7 +9,6 @@ import sysconfig
from test import support from test import support
from test.support import script_helper, is_android from test.support import script_helper, is_android
import tempfile import tempfile
import threading
import unittest import unittest
from textwrap import dedent from textwrap import dedent

View File

@ -10,8 +10,7 @@ import time
import unittest import unittest
from test.fork_wait import ForkWait from test.fork_wait import ForkWait
from test.support import (reap_children, get_attribute, from test.support import reap_children, get_attribute, verbose
import_module, verbose)
# Skip test if fork does not exist. # Skip test if fork does not exist.

View File

@ -3,7 +3,6 @@ import gc
import pickle import pickle
import sys import sys
import unittest import unittest
import warnings
import weakref import weakref
import inspect import inspect

View File

@ -2,7 +2,6 @@ import os
import base64 import base64
import contextlib import contextlib
import gettext import gettext
import locale
import unittest import unittest
from test import support from test import support

View File

@ -1,7 +1,6 @@
from test import support from test import support
from contextlib import contextmanager from contextlib import contextmanager
import errno
import imaplib import imaplib
import os.path import os.path
import socketserver import socketserver

View File

@ -5,7 +5,6 @@ from importlib._bootstrap_external import _get_sourcefile
import builtins import builtins
import marshal import marshal
import os import os
import platform
import py_compile import py_compile
import random import random
import shutil import shutil
@ -23,9 +22,9 @@ import glob
import test.support import test.support
from test.support import ( from test.support import (
EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython, TESTFN, forget, is_jython,
make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask, make_legacy_pyc, rmtree, swap_attr, swap_item, temp_umask,
unlink, unload, create_empty_file, cpython_only, TESTFN_UNENCODABLE, unlink, unload, cpython_only, TESTFN_UNENCODABLE,
temp_dir, DirsOnSysPath) temp_dir, DirsOnSysPath)
from test.support import script_helper from test.support import script_helper
from test.test_importlib.util import uncache from test.test_importlib.util import uncache

View File

@ -4,7 +4,6 @@ init = util.import_importlib('importlib')
machinery = util.import_importlib('importlib.machinery') machinery = util.import_importlib('importlib.machinery')
importlib_util = util.import_importlib('importlib.util') importlib_util = util.import_importlib('importlib.util')
import contextlib
import importlib.util import importlib.util
import os import os
import pathlib import pathlib

View File

@ -3,7 +3,7 @@ import unittest
import locale import locale
import sys import sys
import codecs import codecs
import warnings
class BaseLocalizedTest(unittest.TestCase): class BaseLocalizedTest(unittest.TestCase):
# #

View File

@ -12,7 +12,7 @@ import platform
import random import random
import struct import struct
import sys import sys
import sysconfig
eps = 1E-05 eps = 1E-05
NAN = float('nan') NAN = float('nan')

View File

@ -9,7 +9,6 @@ import contextlib
import decimal import decimal
import errno import errno
import fractions import fractions
import getpass
import itertools import itertools
import locale import locale
import mmap import mmap

View File

@ -1,10 +1,9 @@
import dis import dis
import unittest import unittest
import types
import textwrap
from test.bytecode_helper import BytecodeTestCase from test.bytecode_helper import BytecodeTestCase
def count_instr_recursively(f, opname): def count_instr_recursively(f, opname):
count = 0 count = 0
for instr in dis.get_instructions(f): for instr in dis.get_instructions(f):

View File

@ -5,7 +5,6 @@ Pickling tests themselves are in pickletester.py.
import gc import gc
from pickle import PickleBuffer from pickle import PickleBuffer
import sys
import weakref import weakref
import unittest import unittest

View File

@ -2,13 +2,12 @@ import os
import platform import platform
import subprocess import subprocess
import sys import sys
import sysconfig
import tempfile
import unittest import unittest
from unittest import mock from unittest import mock
from test import support from test import support
class PlatformTest(unittest.TestCase): class PlatformTest(unittest.TestCase):
def clear_caches(self): def clear_caches(self):
platform._platform_cache.clear() platform._platform_cache.clear()

View File

@ -1,7 +1,6 @@
import os import os
import posixpath import posixpath
import unittest import unittest
import warnings
from posixpath import realpath, abspath, dirname, basename from posixpath import realpath, abspath, dirname, basename
from test import support, test_genericpath from test import support, test_genericpath
from test.support import FakePath from test.support import FakePath
@ -12,6 +11,7 @@ try:
except ImportError: except ImportError:
posix = None posix = None
# An absolute path to a temporary filename for testing. We can't rely on TESTFN # An absolute path to a temporary filename for testing. We can't rely on TESTFN
# being an absolute path, so we need this. # being an absolute path, so we need this.

View File

@ -3,15 +3,13 @@
Nick Mathewson Nick Mathewson
''' '''
import os
import sys import sys
from textwrap import dedent from textwrap import dedent
from types import FunctionType, MethodType, BuiltinFunctionType from types import FunctionType, MethodType, BuiltinFunctionType
import pyclbr import pyclbr
from unittest import TestCase, main as unittest_main from unittest import TestCase, main as unittest_main
from test import support
from test.test_importlib import util as test_importlib_util from test.test_importlib import util as test_importlib_util
from functools import partial
StaticMethodType = type(staticmethod(lambda: None)) StaticMethodType = type(staticmethod(lambda: None))
ClassMethodType = type(classmethod(lambda c: None)) ClassMethodType = type(classmethod(lambda c: None))

View File

@ -21,7 +21,6 @@ import urllib.parse
import xml.etree import xml.etree
import xml.etree.ElementTree import xml.etree.ElementTree
import textwrap import textwrap
import threading
from io import StringIO from io import StringIO
from collections import namedtuple from collections import namedtuple
from test.support.script_helper import assert_python_ok from test.support.script_helper import assert_python_ok

View File

@ -11,8 +11,7 @@ import warnings
from test.support import ( from test.support import (
forget, make_legacy_pyc, unload, verbose, no_tracing, forget, make_legacy_pyc, unload, verbose, no_tracing,
create_empty_file, temp_dir) create_empty_file, temp_dir)
from test.support.script_helper import ( from test.support.script_helper import make_script, make_zip_script
make_pkg, make_script, make_zip_pkg, make_zip_script)
import runpy import runpy

View File

@ -6,7 +6,6 @@ import socket
import statistics import statistics
import subprocess import subprocess
import sys import sys
import threading
import time import time
import unittest import unittest
from test import support from test import support

View File

@ -19,7 +19,7 @@ import threading
import unittest import unittest
from test import support, mock_socket from test import support, mock_socket
from test.support import HOST, HOSTv4, HOSTv6 from test.support import HOST
from test.support import threading_setup, threading_cleanup, join_thread from test.support import threading_setup, threading_cleanup, join_thread
from unittest.mock import Mock from unittest.mock import Mock

View File

@ -26,7 +26,7 @@ except ImportError:
ssl = support.import_module("ssl") ssl = support.import_module("ssl")
from ssl import TLSVersion, _TLSContentType, _TLSMessageType, _TLSAlertType from ssl import TLSVersion, _TLSContentType, _TLSMessageType
Py_DEBUG = hasattr(sys, 'gettotalrefcount') Py_DEBUG = hasattr(sys, 'gettotalrefcount')
Py_DEBUG_WIN32 = Py_DEBUG and sys.platform == 'win32' Py_DEBUG_WIN32 = Py_DEBUG and sys.platform == 'win32'
@ -4601,7 +4601,6 @@ class TestSSLDebug(unittest.TestCase):
def test_main(verbose=False): def test_main(verbose=False):
if support.verbose: if support.verbose:
import warnings
plats = { plats = {
'Mac': platform.mac_ver, 'Mac': platform.mac_ver,
'Windows': platform.win32_ver, 'Windows': platform.win32_ver,

View File

@ -31,7 +31,6 @@ import os
import sys import sys
import shutil import shutil
import tempfile import tempfile
import warnings
import unittest import unittest

View File

@ -3,7 +3,6 @@ from unittest import mock
from test import support from test import support
import subprocess import subprocess
import sys import sys
import platform
import signal import signal
import io import io
import itertools import itertools
@ -20,18 +19,12 @@ import gc
import textwrap import textwrap
from test.support import FakePath from test.support import FakePath
try:
import ctypes
except ImportError:
ctypes = None
else:
import ctypes.util
try: try:
import _testcapi import _testcapi
except ImportError: except ImportError:
_testcapi = None _testcapi = None
if support.PGO: if support.PGO:
raise unittest.SkipTest("test is not helpful for PGO") raise unittest.SkipTest("test is not helpful for PGO")

View File

@ -3,7 +3,6 @@ from test.support.script_helper import assert_python_ok, assert_python_failure
import builtins import builtins
import codecs import codecs
import gc import gc
import io
import locale import locale
import operator import operator
import os import os

View File

@ -7,7 +7,6 @@ from unittest import TestCase, mock
from unittest import mock from unittest import mock
import errno import errno
import os import os
import sys
import tabnanny import tabnanny
import tokenize import tokenize
import tempfile import tempfile

View File

@ -15,7 +15,7 @@ import threading
import unittest import unittest
from unittest import mock from unittest import mock
from test.support import ( from test.support import (
verbose, import_module, run_unittest, TESTFN, reap_threads, verbose, run_unittest, TESTFN, reap_threads,
forget, unlink, rmtree, start_threads) forget, unlink, rmtree, start_threads)
def task(N, done, done_tasks, errors): def task(N, done, done_tasks, errors):

View File

@ -13,19 +13,22 @@ quickly. Guido reports needing to boost FILES_PER_THREAD to 500 before
provoking a 2.0 failure under Linux. provoking a 2.0 failure under Linux.
""" """
NUM_THREADS = 20
FILES_PER_THREAD = 50
import tempfile import tempfile
from test.support import start_threads, import_module from test.support import start_threads
import unittest import unittest
import io import io
import threading import threading
from traceback import print_exc from traceback import print_exc
NUM_THREADS = 20
FILES_PER_THREAD = 50
startEvent = threading.Event() startEvent = threading.Event()
class TempFileGreedy(threading.Thread): class TempFileGreedy(threading.Thread):
error_count = 0 error_count = 0
ok_count = 0 ok_count = 0

View File

@ -4,9 +4,7 @@ import io
import os import os
import pathlib import pathlib
import posixpath import posixpath
import shutil
import struct import struct
import tempfile
import time import time
import unittest import unittest
import zipfile import zipfile