Revert "Remove unused imports in tests (GH-14518) (GH-14522)" (GH-14555)

This reverts commit e34b5f4d64.
This commit is contained in:
Victor Stinner 2019-07-02 14:42:39 +02:00 committed by GitHub
parent c53173aa00
commit 19b8d903b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 73 additions and 22 deletions

View File

@ -587,6 +587,7 @@ 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

@ -5,6 +5,7 @@ if __name__ != 'test.support':
import collections.abc import collections.abc
import contextlib import contextlib
import datetime
import errno import errno
import faulthandler import faulthandler
import fnmatch import fnmatch
@ -12,6 +13,7 @@ import functools
import gc import gc
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

@ -7,6 +7,7 @@ import io
import sys import sys
import struct import struct
import aifc import aifc
import warnings
class AifcTest(audiotests.AudioWriteTests, class AifcTest(audiotests.AudioWriteTests,

View File

@ -1,5 +1,6 @@
# 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,6 +7,7 @@ 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

@ -4,6 +4,7 @@ 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

@ -15,6 +15,7 @@ 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,6 +22,7 @@ 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 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,6 +2,7 @@
import locale import locale
import os import os
import shutil
import subprocess import subprocess
import sys import sys
import sysconfig import sysconfig
@ -9,8 +10,10 @@ import unittest
from collections import namedtuple from collections import namedtuple
import test.support 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 # 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,6 +8,7 @@ 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

@ -5,6 +5,7 @@
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

@ -3,9 +3,11 @@
import collections import collections
import copy import copy
import doctest import doctest
import keyword
import operator import operator
import pickle import pickle
from random import choice, randrange from random import choice, randrange
import re
import string import string
import sys import sys
from test import support from test import support

View File

@ -1,5 +1,6 @@
"""Unit tests for contextlib.py, and other context managers.""" """Unit tests for contextlib.py, and other context managers."""
import asyncio
import io import io
import sys import sys
import tempfile import tempfile

View File

@ -2,6 +2,7 @@ import contextlib
import copy import copy
import inspect import inspect
import pickle import pickle
import re
import sys import sys
import types import types
import unittest import unittest

View File

@ -2,6 +2,7 @@ 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,4 +1,5 @@
import io import io
import sys
import types import types
import textwrap import textwrap
import unittest import unittest

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, check_warnings, cpython_only, gc_collect, run_unittest,
no_tracing, unlink, import_module, script_helper, no_tracing, unlink, import_module, script_helper,
SuppressCrashReport) SuppressCrashReport)
class NaiveException(Exception): class NaiveException(Exception):

View File

@ -9,6 +9,7 @@ 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,7 +10,8 @@ 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, verbose from test.support import (reap_children, get_attribute,
import_module, verbose)
# Skip test if fork does not exist. # Skip test if fork does not exist.

View File

@ -13,6 +13,7 @@
import sys import sys
import unittest import unittest
from test.support import captured_stdout from test.support import captured_stdout
from importlib import util
class TestFrozen(unittest.TestCase): class TestFrozen(unittest.TestCase):

View File

@ -3,6 +3,7 @@
# The code for testing gdb was adapted from similar work in Unladen Swallow's # The code for testing gdb was adapted from similar work in Unladen Swallow's
# Lib/test/test_jit_gdb.py # Lib/test/test_jit_gdb.py
import locale
import os import os
import platform import platform
import re import re

View File

@ -3,6 +3,7 @@ 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

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

View File

@ -4,6 +4,7 @@
from test.support import check_syntax_error from test.support import check_syntax_error
import inspect import inspect
import unittest import unittest
import sys
# testing import * # testing import *
from sys import * from sys import *
@ -11,6 +12,7 @@ from sys import *
# with import machinery # with import machinery
import test.ann_module as ann_module import test.ann_module as ann_module
import typing import typing
from collections import ChainMap
from test import ann_module2 from test import ann_module2
import test import test

View File

@ -1,6 +1,7 @@
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,6 +5,7 @@ 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 stat import stat
@ -19,9 +20,9 @@ import contextlib
import test.support import test.support
from test.support import ( from test.support import (
TESTFN, forget, is_jython, EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython,
make_legacy_pyc, rmtree, swap_attr, swap_item, temp_umask, make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask,
unlink, unload, cpython_only, TESTFN_UNENCODABLE, unlink, unload, create_empty_file, 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,6 +4,7 @@ init = test_util.import_importlib('importlib')
import sys import sys
import threading import threading
import unittest
import weakref import weakref
from test import support from test import support

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

@ -1,4 +1,5 @@
import netrc, os, unittest, sys, tempfile, textwrap import netrc, os, unittest, sys, tempfile, textwrap
from unittest import mock
from test import support from test import support

View File

@ -9,6 +9,7 @@ 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,6 +1,7 @@
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
@ -11,7 +12,6 @@ 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,11 +3,14 @@
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 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,6 +21,7 @@ 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

@ -1,8 +1,10 @@
# Some simple queue module tests, plus some failure conditions # Some simple queue module tests, plus some failure conditions
# to ensure the Queue locks remain stable. # to ensure the Queue locks remain stable.
import collections
import itertools import itertools
import queue import queue
import random import random
import sys
import threading import threading
import time import time
import unittest import unittest

View File

@ -1,5 +1,6 @@
import contextlib import contextlib
import sys import sys
import os
import unittest import unittest
from test import support from test import support
import time import time

View File

@ -11,7 +11,8 @@ 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 make_script, make_zip_script from test.support.script_helper import (
make_pkg, make_script, make_zip_pkg, make_zip_script)
import runpy import runpy

View File

@ -17,6 +17,7 @@ from xml.sax.handler import feature_namespaces, feature_external_ges
from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
from io import BytesIO, StringIO from io import BytesIO, StringIO
import codecs import codecs
import gc
import os.path import os.path
import shutil import shutil
from urllib.error import URLError from urllib.error import URLError

View File

@ -5,6 +5,7 @@ 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 from test.support import HOST, HOSTv4, HOSTv6
from unittest.mock import Mock from unittest.mock import Mock

View File

@ -3,6 +3,7 @@ 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
@ -19,12 +20,18 @@ 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

@ -4,6 +4,7 @@ import random
from test import support from test import support
import _thread as thread import _thread as thread
import time import time
import sys
import weakref import weakref
from test import lock_tests from test import lock_tests

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, run_unittest, TESTFN, reap_threads, verbose, import_module, 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,22 +13,19 @@ 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 from test.support import start_threads, import_module
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

@ -9,6 +9,7 @@ import sysconfig
import time import time
import threading import threading
import unittest import unittest
import warnings
try: try:
import _testcapi import _testcapi
except ImportError: except ImportError:

View File

@ -1,7 +1,7 @@
from test import support from test import support
from tokenize import (tokenize, _tokenize, untokenize, NUMBER, NAME, OP, from tokenize import (tokenize, _tokenize, untokenize, NUMBER, NAME, OP,
STRING, ENDMARKER, ENCODING, tok_name, detect_encoding, STRING, ENDMARKER, ENCODING, tok_name, detect_encoding,
open as tokenize_open, Untokenizer, open as tokenize_open, Untokenizer, generate_tokens,
NEWLINE) NEWLINE)
from io import BytesIO from io import BytesIO
import unittest import unittest

View File

@ -110,7 +110,7 @@ class TracebackCases(unittest.TestCase):
# Test that tracebacks are correctly printed for encoded source files: # Test that tracebacks are correctly printed for encoded source files:
# - correct line number (Issue2384) # - correct line number (Issue2384)
# - respect file encoding (Issue3975) # - respect file encoding (Issue3975)
import sys, subprocess import tempfile, sys, subprocess, os
# The spawned subprocess has its stdout redirected to a PIPE, and its # The spawned subprocess has its stdout redirected to a PIPE, and its
# encoding may be different from the current interpreter, on Windows # encoding may be different from the current interpreter, on Windows

View File

@ -3,6 +3,7 @@ Test the implementation of the PEP 540: the UTF-8 Mode.
""" """
import locale import locale
import os
import sys import sys
import textwrap import textwrap
import unittest import unittest

View File

@ -15,6 +15,7 @@ import sys
import tempfile import tempfile
from test.support import (captured_stdout, captured_stderr, requires_zlib, from test.support import (captured_stdout, captured_stderr, requires_zlib,
can_symlink, EnvironmentVarGuard, rmtree) can_symlink, EnvironmentVarGuard, rmtree)
import threading
import unittest import unittest
import venv import venv