Issue #23277: Remove unused imports in tests.

This commit is contained in:
Serhiy Storchaka 2016-04-24 21:41:02 +03:00
parent 597d15afe4
commit e437a10d15
79 changed files with 23 additions and 117 deletions

View File

@ -49,7 +49,7 @@ class SimpleTypesTestCase(unittest.TestCase):
# XXX Replace by c_char_p tests
def test_cstrings(self):
from ctypes import c_char_p, byref
from ctypes import c_char_p
# c_char_p.from_param on a Python String packs the string
# into a cparam object
@ -68,7 +68,7 @@ class SimpleTypesTestCase(unittest.TestCase):
@need_symbol('c_wchar_p')
def test_cw_strings(self):
from ctypes import byref, c_wchar_p
from ctypes import c_wchar_p
c_wchar_p.from_param("123")
@ -98,7 +98,7 @@ class SimpleTypesTestCase(unittest.TestCase):
def test_byref_pointer(self):
# The from_param class method of POINTER(typ) classes accepts what is
# returned by byref(obj), it type(obj) == typ
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
from ctypes import c_short, c_uint, c_int, c_long, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))

View File

@ -3,16 +3,12 @@
import unittest
import sys
import os
import tempfile
import shutil
from test.support import run_unittest
from distutils.core import Distribution
from distutils.command.bdist_rpm import bdist_rpm
from distutils.tests import support
from distutils.spawn import find_executable
from distutils import spawn
from distutils.errors import DistutilsExecError
SETUP_PY = """\
from distutils.core import setup

View File

@ -166,7 +166,6 @@ class BuildExtTestCase(TempdirManager,
cmd = self.build_ext(dist)
cmd.finalize_options()
from distutils import sysconfig
py_include = sysconfig.get_python_inc()
self.assertIn(py_include, cmd.include_dirs)

View File

@ -1,7 +1,6 @@
"""Tests for distutils.command.clean."""
import os
import unittest
import getpass
from distutils.command.clean import clean
from distutils.tests import support

View File

@ -1,7 +1,6 @@
"""Tests for distutils.pypirc.pypirc."""
import os
import unittest
import tempfile
from distutils.core import PyPIRCCommand
from distutils.core import Distribution

View File

@ -3,11 +3,10 @@ import unittest
import sys
import os
from io import BytesIO
import subprocess
from test.support import run_unittest
from distutils import cygwinccompiler
from distutils.cygwinccompiler import (CygwinCCompiler, check_config_h,
from distutils.cygwinccompiler import (check_config_h,
CONFIG_H_OK, CONFIG_H_NOTOK,
CONFIG_H_UNCERTAIN, get_versions,
get_msvcr)

View File

@ -1,7 +1,6 @@
"""Tests for distutils.dep_util."""
import unittest
import os
import time
from distutils.dep_util import newer, newer_pairwise, newer_group
from distutils.errors import DistutilsFileError

View File

@ -1,7 +1,6 @@
"""Tests for distutils.file_util."""
import unittest
import os
import shutil
import errno
from unittest.mock import patch

View File

@ -1,7 +1,6 @@
"""Tests for distutils.command.install_data."""
import os
import unittest
import getpass
from distutils.command.install_data import install_data
from distutils.tests import support

View File

@ -1,7 +1,6 @@
"""Tests for distutils.command.install_headers."""
import os
import unittest
import getpass
from distutils.command.install_headers import install_headers
from distutils.tests import support

View File

@ -1,11 +1,10 @@
"""Tests for distutils.spawn."""
import unittest
import os
import time
from test.support import captured_stdout, run_unittest
from test.support import run_unittest
from distutils.spawn import _nt_quote_args
from distutils.spawn import spawn, find_executable
from distutils.spawn import spawn
from distutils.errors import DistutilsExecError
from distutils.tests import support

View File

@ -10,7 +10,6 @@ import unittest
import test.support
# Local imports
from lib2to3 import refactor
from . import support

View File

@ -2,12 +2,11 @@
# Python imports
import os
import unittest
from itertools import chain
from operator import itemgetter
# Local imports
from lib2to3 import pygram, pytree, refactor, fixer_util
from lib2to3 import pygram, fixer_util
from lib2to3.tests import support

View File

@ -10,7 +10,7 @@ from __future__ import with_statement
# Testing imports
from . import support
from .support import driver, test_dir
from .support import driver
from test.support import verbose
# Python imports

View File

@ -11,8 +11,6 @@ especially when debugging a test.
from __future__ import with_statement
import warnings
# Testing imports
from . import support

View File

@ -7,18 +7,14 @@ from __future__ import with_statement
import sys
import os
import codecs
import operator
import io
import tempfile
import shutil
import unittest
import warnings
from lib2to3 import refactor, pygram, fixer_base
from lib2to3.pgen2 import token
from . import support
TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
FIXER_DIR = os.path.join(TEST_DATA_DIR, "fixers")

View File

@ -1,5 +1,4 @@
from test.support import findfile, TESTFN, unlink
import unittest
import array
import io
import pickle

View File

@ -4,7 +4,6 @@ try:
except ImportError:
nl_langinfo = None
import codecs
import locale
import sys
import unittest

View File

@ -4,7 +4,6 @@ Test suite for _osx_support: shared OS X support functions.
import os
import platform
import shutil
import stat
import sys
import unittest

View File

@ -7,8 +7,6 @@ from test import support
import weakref
import pickle
import operator
import io
import math
import struct
import sys
import warnings

View File

@ -12,7 +12,6 @@ import socket
import sys
import time
import unittest
import warnings
import unittest.mock
try:
import threading

View File

@ -14,7 +14,6 @@ from test.support import bigmemtest, _1G, _2G, _4G
import unittest
import operator
import sys
import functools
# These tests all use one of the bigmemtest decorators to indicate how much
# memory they use and how much memory they need to be even meaningful. The

View File

@ -2,7 +2,7 @@
import unittest
from test import support
from operator import eq, ne, lt, gt, le, ge
from operator import eq, le
from abc import ABCMeta
def gcd(a, b):

View File

@ -16,7 +16,6 @@ import unittest
from test import support
from itertools import permutations, product
from random import randrange, sample, choice
from sysconfig import get_config_var
import warnings
import sys, array, io
from decimal import Decimal

View File

@ -4,7 +4,6 @@ import sys
import test.support
import unicodedata
import unittest
import warnings
class PosReturn:
# this can be used for configurable callbacks

View File

@ -4,7 +4,6 @@ import io
import locale
import sys
import unittest
import warnings
import encodings
from test import support

View File

@ -6,7 +6,7 @@ from test.support import run_unittest, TESTFN, unlink
# rip off all interesting stuff from test_profile
import cProfile
from test.test_profile import ProfileTest, regenerate_expected_output
from test.profilee import testfunc
class CProfileTest(ProfileTest):
profilerclass = cProfile.Profile

View File

@ -2,7 +2,6 @@
# csv package unit tests
import copy
import io
import sys
import unittest
from io import StringIO
@ -1078,7 +1077,6 @@ class TestUnicode(unittest.TestCase):
"François Pinard"]
def test_unicode_read(self):
import io
with TemporaryFile("w+", newline='', encoding="utf-8") as fileobj:
fileobj.write(",".join(self.names) + "\r\n")
fileobj.seek(0)
@ -1087,7 +1085,6 @@ class TestUnicode(unittest.TestCase):
def test_unicode_write(self):
import io
with TemporaryFile("w+", newline='', encoding="utf-8") as fileobj:
writer = csv.writer(fileobj)
writer.writerow(self.names)

View File

@ -2,7 +2,7 @@ from test import support
gdbm = support.import_module("dbm.gnu") #skip if not supported
import unittest
import os
from test.support import verbose, TESTFN, unlink
from test.support import TESTFN, unlink
filename = TESTFN

View File

@ -1,7 +1,6 @@
from test import support
support.import_module("dbm.ndbm") #skip if not supported
import unittest
import random
import dbm.ndbm
from dbm.ndbm import error

View File

@ -6,7 +6,7 @@ import os
import random
import select
import unittest
from test.support import TESTFN, run_unittest, cpython_only
from test.support import run_unittest, cpython_only
if not hasattr(select, 'devpoll') :
raise unittest.SkipTest('test works only on Solaris OS family')

View File

@ -1876,7 +1876,6 @@ if not hasattr(sys, 'gettrace') or not sys.gettrace():
To demonstrate this, we'll create a fake standard input that
captures our debugger input:
>>> import tempfile
>>> real_stdin = sys.stdin
>>> sys.stdin = _FakeInput([
... 'print(x)', # print data defined by the example
@ -1917,7 +1916,7 @@ if not hasattr(sys, 'gettrace') or not sys.gettrace():
... finally:
... sys.stdin = real_stdin
--Return--
> <doctest test.test_doctest.test_pdb_set_trace[8]>(3)calls_set_trace()->None
> <doctest test.test_doctest.test_pdb_set_trace[7]>(3)calls_set_trace()->None
-> import pdb; pdb.set_trace()
(Pdb) print(y)
2
@ -2804,7 +2803,6 @@ text files).
... _ = f.write(" 'abc def'\n")
... _ = f.write("\n")
... _ = f.write(' \"\"\"\n')
... import shutil
... rc1, out1, err1 = script_helper.assert_python_failure(
... '-m', 'doctest', fn, fn2, TERM='')
... rc2, out2, err2 = script_helper.assert_python_ok(

View File

@ -1,7 +1,6 @@
# Test the most dynamic corner cases of Python's runtime semantics.
import builtins
import contextlib
import unittest
from test.support import swap_item, swap_attr

View File

@ -3421,7 +3421,6 @@ Do you like this message?
class TestFeedParsers(TestEmailBase):
def parse(self, chunks):
from email.feedparser import FeedParser
feedparser = FeedParser()
for chunk in chunks:
feedparser.feed(chunk)

View File

@ -1,7 +1,6 @@
import datetime
import textwrap
import unittest
import types
from email import errors
from email import policy
from email.message import Message

View File

@ -1,6 +1,5 @@
import fractions
import math
import operator
import os
import random

View File

@ -5,7 +5,6 @@
import os
import re
import pprint
import subprocess
import sys
import sysconfig

View File

@ -1,6 +1,5 @@
import os
import base64
import shutil
import gettext
import unittest

View File

@ -1,5 +1,4 @@
import unittest
from test import support
from test.support import import_module
# Skip test if _thread or _tkinter wasn't built or idlelib was deleted.

View File

@ -2,7 +2,6 @@ from .. import util
machinery = util.import_importlib('importlib.machinery')
import collections
import unittest

View File

@ -1,7 +1,6 @@
from .. import util
import sys
import unittest
import importlib
from test import support

View File

@ -3,7 +3,6 @@ from . import util as test_util
init = test_util.import_importlib('importlib')
import sys
import time
import unittest
import weakref

View File

@ -1,9 +1,6 @@
import contextlib
import importlib.abc
import importlib.machinery
import os
import sys
import types
import unittest
from test.test_importlib import util

View File

@ -7,17 +7,12 @@ import email
import email.message
import re
import io
import shutil
import tempfile
from test import support
import unittest
import textwrap
import mailbox
import glob
try:
import fcntl
except ImportError:
pass
class TestBase:

View File

@ -1,6 +1,5 @@
import mailcap
import os
import shutil
import test.support
import unittest

View File

@ -6,7 +6,6 @@ from test import support
import unittest
import math
import os
import platform
import sys
import struct
import sysconfig

View File

@ -6,7 +6,6 @@ support.import_module('_multiprocessing')
import importlib
import importlib.machinery
import zipimport
import unittest
import sys
import os
@ -15,7 +14,7 @@ import py_compile
from test.support.script_helper import (
make_pkg, make_script, make_zip_pkg, make_zip_script,
assert_python_ok, assert_python_failure, spawn_python, kill_python)
assert_python_ok)
# Look up which start methods are available to test
import multiprocessing

View File

@ -558,7 +558,6 @@ def test_pdb_continue_in_bottomframe():
def pdb_invoke(method, arg):
"""Run pdb.method(arg)."""
import pdb
getattr(pdb.Pdb(nosigint=True), method)(arg)

View File

@ -1,6 +1,5 @@
import unittest
import builtins
import warnings
import os
from platform import system as platform_system

View File

@ -1,4 +1,3 @@
import struct
import pickle
import pickletools
from test import support

View File

@ -7,7 +7,6 @@ import datetime
import codecs
import binascii
import collections
import struct
from test import support
from io import BytesIO

View File

@ -8,7 +8,6 @@ import asyncore
import asynchat
import socket
import os
import time
import errno
from unittest import TestCase, skipUnless

View File

@ -11,7 +11,6 @@ import time
import os
import platform
import pwd
import shutil
import stat
import tempfile
import unittest

View File

@ -1,4 +1,3 @@
import itertools
import os
import posixpath
import unittest

View File

@ -4,10 +4,8 @@ Tests of regrtest.py.
Note: test_regrtest cannot be run twice in parallel.
"""
import argparse
import contextlib
import faulthandler
import getopt
import io
import os.path
import platform

View File

@ -2,8 +2,6 @@ import io
import unittest
import urllib.robotparser
from collections import namedtuple
from urllib.error import URLError, HTTPError
from urllib.request import urlopen
from test import support
from http.server import BaseHTTPRequestHandler, HTTPServer
try:

View File

@ -13,7 +13,6 @@ import queue
import sys
import os
import array
import platform
import contextlib
from weakref import proxy
import signal

View File

@ -7,8 +7,6 @@ import os
import select
import signal
import socket
import select
import errno
import tempfile
import unittest
import socketserver

View File

@ -5,15 +5,12 @@ import subprocess
import sys
import signal
import io
import locale
import os
import errno
import tempfile
import time
import re
import selectors
import sysconfig
import warnings
import select
import shutil
import gc

View File

@ -1,4 +1,3 @@
from test.support import TESTFN
import unittest
from test import audiotests
from audioop import byteswap

View File

@ -1,7 +1,6 @@
import socket
import selectors
import telnetlib
import time
import contextlib
from test import support

View File

@ -3,7 +3,7 @@ Tests for the threading module.
"""
import test.support
from test.support import verbose, strip_python_stderr, import_module, cpython_only
from test.support import verbose, import_module, cpython_only
from test.support.script_helper import assert_python_ok, assert_python_failure
import random

View File

@ -2,12 +2,11 @@
import os
import sys
import importlib
import unittest
from unittest import mock
import tempfile
from test.test_tools import scriptsdir, skip_if_missing, import_tool
from test.test_tools import skip_if_missing, import_tool
skip_if_missing()

View File

@ -5,7 +5,7 @@ import unittest
from test import support
from test.support.script_helper import assert_python_ok, assert_python_failure
from test.test_tools import scriptsdir, import_tool, skip_if_missing
from test.test_tools import scriptsdir, skip_if_missing
skip_if_missing()

View File

@ -4,7 +4,7 @@ import os
import unittest
import tempfile
from test.test_tools import scriptsdir, skip_if_missing, import_tool
from test.test_tools import skip_if_missing, import_tool
skip_if_missing()

View File

@ -462,7 +462,7 @@ class MockHTTPHandler(urllib.request.BaseHandler):
self.requests = []
def http_open(self, req):
import email, http.client, copy
import email, copy
self.requests.append(copy.deepcopy(req))
if self._count == 0:
self._count = self._count + 1

View File

@ -1,7 +1,6 @@
# UserString is a wrapper around the native builtin string type.
# UserString instances should behave similar to builtin string objects.
import string
import unittest
from test import string_tests

View File

@ -8,7 +8,6 @@ from test import support
import sys, os
import uu
from io import BytesIO
import io
plaintext = b"The smooth-scaled python crept over the sleeping dog\n"

View File

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

View File

@ -1,4 +1,3 @@
from test.support import TESTFN
import unittest
from test import audiotests
from test import support

View File

@ -1,11 +1,6 @@
import unittest
from weakref import proxy, ref, WeakSet
import operator
import copy
from weakref import WeakSet
import string
from random import randrange, shuffle
import warnings
import collections
from collections import UserString as ustr
import gc
import contextlib

View File

@ -108,7 +108,7 @@ class SizeofTest(unittest.TestCase):
struct.calcsize('8P'))
def test_main():
from test import test_xml_etree, test_xml_etree_c
from test import test_xml_etree
# Run the tests specific to the C implementation
support.run_unittest(

View File

@ -1132,7 +1132,6 @@ def captured_stdout(encoding='utf-8'):
"""A variation on support.captured_stdout() which gives a text stream
having a `buffer` attribute.
"""
import io
orig_stdout = sys.stdout
sys.stdout = io.TextIOWrapper(io.BytesIO(), encoding=encoding)
try:

View File

@ -1,6 +1,4 @@
import collections.abc
import errno
import socket
import unittest
from test import support

View File

@ -12,7 +12,6 @@ import zipimport
import doctest
import inspect
import linecache
import pdb
import unittest
from test.support.script_helper import (spawn_python, kill_python, assert_python_ok,
make_script, make_zip_script)

View File

@ -7,7 +7,6 @@ Extensions also should live in packages following the same rule as above.
"""
import os
import unittest
import importlib
import test.support

View File

@ -1,6 +1,5 @@
# -*- encoding: utf-8 -*-
import unittest
import tkinter
from tkinter import ttk
class MockTkApp:

View File

@ -1,5 +1,4 @@
import unittest
import inspect
import sys
from unittest.mock import Mock, MagicMock, _magics

View File

@ -10,9 +10,9 @@ from unittest.test.testmock import support
from unittest.test.testmock.support import SomeClass, is_instance
from unittest.mock import (
NonCallableMock, CallableMixin, patch, sentinel,
NonCallableMock, CallableMixin, sentinel,
MagicMock, Mock, NonCallableMagicMock, patch, _patch,
DEFAULT, call, _get_target, _patch
DEFAULT, call, _get_target
)