Commits

Georg Brandl committed 70e115c

Remove unused imports in test modules.

Comments (0)

Files changed (74)

Lib/test/regrtest.py

 
 import cStringIO
 import getopt
-import itertools
 import json
 import os
 import random
 
     if use_mp:
         from threading import Thread
-        from Queue import Queue, Empty
-        from subprocess import Popen, PIPE, STDOUT
+        from Queue import Queue
+        from subprocess import Popen, PIPE
         from collections import deque
         debug_output_pat = re.compile(r"\[\d+ refs\]$")
         pending = deque()

Lib/test/test__locale.py

-from test.test_support import verbose, run_unittest
+from test.test_support import run_unittest
 from _locale import (setlocale, LC_NUMERIC, localeconv, Error)
 try:
     from _locale import (RADIXCHAR, THOUSEP, nl_langinfo)

Lib/test/test_abstract_numbers.py

 """Unit tests for numbers.py."""
 
 import math
-import operator
 import unittest
 from numbers import Complex, Real, Rational, Integral
-from numbers import Number
 from test import test_support
 
 class TestNumbers(unittest.TestCase):

Lib/test/test_applesingle.py

 
 MacOS = test_support.import_module('MacOS')
 # The following should exist if MacOS does.
-import macostools
 import applesingle
-import Carbon.File
 
 AS_MAGIC=0x00051600
 AS_VERSION=0x00020000

Lib/test/test_bsddb.py

    Adapted to unittest format and expanded scope by Raymond Hettinger
 """
 import os, sys
-import copy
 import unittest
 from test import test_support
 

Lib/test/test_builtin.py

 # Python test set -- built-in functions
 
 import platform
-import test.test_support, unittest
+import unittest
 from test.test_support import fcmp, have_unicode, TESTFN, unlink, \
-                              run_unittest, run_with_locale
+                              run_unittest
 from operator import neg
 
-import sys, warnings, cStringIO, random, fractions, UserDict
+import sys, warnings, cStringIO, random, UserDict
 warnings.filterwarnings("ignore", "hex../oct.. of negative int",
                         FutureWarning, __name__)
 warnings.filterwarnings("ignore", "integer argument expected",

Lib/test/test_cmath.py

 from test.test_support import run_unittest
 from test.test_math import parse_testfile, test_file
 import unittest
-import os, sys
 import cmath, math
 from cmath import phase, polar, rect, pi
 

Lib/test/test_cmd_line.py

 # All tests are executed with environment variables ignored
 # See test_cmd_line_script.py for testing of script execution
 
-import os
 import test.test_support, unittest
 import sys
 from test.script_helper import spawn_python, kill_python, python_exit_code

Lib/test/test_cmd_line_script.py

 import unittest
 import os
 import os.path
-import sys
 import test.test_support
-from test.script_helper import (spawn_python, kill_python, run_python,
+from test.script_helper import (run_python,
                                 temp_dir, make_script, compile_script,
                                 make_pkg, make_zip_script, make_zip_pkg)
 

Lib/test/test_collections.py

 from test import mapping_tests
 import pickle, cPickle, copy
 from random import randrange, shuffle
-import operator
 import keyword
 import re
 from collections import Hashable, Iterable, Iterator
         d = self._empty_mapping()
         self.assertRaises(KeyError, d.popitem)
 
-import doctest, collections
+import collections
 
 def test_main(verbose=None):
     NamedTupleDocs = doctest.DocTestSuite(module=collections)

Lib/test/test_commands.py

 from test.test_support import run_unittest, reap_children, import_module
 
 # Silence Py3k warning
-import_module('commands', deprecated=True)
-from commands import *
+commands = import_module('commands', deprecated=True)
 
 # The module says:
 #   "NB This only works (and is only relevant) for UNIX."
 class CommandTests(unittest.TestCase):
 
     def test_getoutput(self):
-        self.assertEquals(getoutput('echo xyzzy'), 'xyzzy')
-        self.assertEquals(getstatusoutput('echo xyzzy'), (0, 'xyzzy'))
+        self.assertEquals(commands.getoutput('echo xyzzy'), 'xyzzy')
+        self.assertEquals(commands.getstatusoutput('echo xyzzy'), (0, 'xyzzy'))
 
         # we use mkdtemp in the next line to create an empty directory
         # under our exclusive control; from that, we can invent a pathname
             dir = tempfile.mkdtemp()
             name = os.path.join(dir, "foo")
 
-            status, output = getstatusoutput('cat ' + name)
+            status, output = commands.getstatusoutput('cat ' + name)
             self.assertNotEquals(status, 0)
         finally:
             if dir is not None:
                   /\.          # and end with the name of the file.
                '''
 
-        self.assertTrue(re.match(pat, getstatus("/."), re.VERBOSE))
+        self.assertTrue(re.match(pat, commands.getstatus("/."), re.VERBOSE))
 
 
 def test_main():

Lib/test/test_compileall.py

 import py_compile
 import shutil
 import struct
-import sys
 import tempfile
-import time
 from test import test_support
 import unittest
 

Lib/test/test_contextlib.py

 """Unit tests for contextlib.py, and other context managers."""
 
 
-import sys
 import os
-import decimal
 import tempfile
 import unittest
 import threading
             self.fail("Didn't raise ZeroDivisionError")
 
     def test_nested_right_exception(self):
-        state = []
         @contextmanager
         def a():
             yield 1

Lib/test/test_cookielib.py

 
 
 def test_main(verbose=None):
-    from test import test_sets
     test_support.run_unittest(
         DateTimeTests,
         HeaderTests,

Lib/test/test_copy.py

 import copy
 import copy_reg
 import weakref
-import operator
 
 import unittest
 from test import test_support

Lib/test/test_decimal.py

 with the corresponding argument.
 """
 
-import glob
 import math
 import os, sys
 import pickle, copy

Lib/test/test_deque.py

 import copy
 import cPickle as pickle
 import random
-import os
 
 BIG = 100000
 

Lib/test/test_descr.py

             pass
         else:
             self.fail("NotImplemented should have caused TypeError")
-        import sys
         try:
             C(sys.maxint+1)
         except OverflowError:
     def test_module_subclasses(self):
         # Testing Python subclass of module...
         log = []
-        import types, sys
         MT = type(sys)
         class MM(MT):
             def __init__(self, name):
         # Test cyclical leaks [SF bug 519621]
         class F(object):
             __slots__ = ['a', 'b']
-        log = []
         s = F()
         s.a = [Counted(), s]
         self.assertEqual(Counted.counter, 1)
         self.assertEqual(Counted.counter, 0)
 
         # Test lookup leaks [SF bug 572567]
-        import sys,gc
+        import gc
         if hasattr(gc, 'get_objects'):
             class G(object):
                 def __cmp__(self, other):
                     return 'EPS'
                 return self
         # sys.stdout needs to be the original to trigger the recursion bug
-        import sys
         test_stdout = sys.stdout
         sys.stdout = test_support.get_original_stdout()
         try:
         self.assertIn('im_self', dir(a.Amethod))
 
         # Try a module subclass.
-        import sys
         class M(type(sys)):
             pass
         minstance = M("m")
             self.fail("d.foo should be undefined now")
 
         # Test a nasty bug in recurse_down_subclasses()
-        import gc
         class A(object):
             pass
         class B(A):
 
     def test_file_fault(self):
         # Testing sys.stdout is changed in getattr...
-        import sys
         test_stdout = sys.stdout
         class StdoutGuard:
             def __getattr__(self, attr):
     def test_not_implemented(self):
         # Testing NotImplemented...
         # all binary methods should be able to return a NotImplemented
-        import sys
-        import types
         import operator
 
         def specialmethod(self, other):

Lib/test/test_dircache.py

 """
 
 import unittest
-from test.test_support import run_unittest, TESTFN, import_module
+from test.test_support import run_unittest, import_module
 dircache = import_module('dircache', deprecated=True)
 import os, time, sys, tempfile
 

Lib/test/test_docxmlrpc.py

 import time
 import socket
 import unittest
-import xmlrpclib
 
 PORT = None
 

Lib/test/test_epoll.py

 """
 Tests for epoll wrapper.
 """
-import os
 import socket
 import errno
 import time
 import select
-import tempfile
 import unittest
 
 from test import test_support

Lib/test/test_file.py

 import io
 import _pyio as pyio
 
-from test.test_support import TESTFN, findfile, run_unittest
+from test.test_support import TESTFN, run_unittest
 from UserList import UserList
 
 class AutoFileTests(unittest.TestCase):

Lib/test/test_file2k.py

 from weakref import proxy
 
 from test import test_support
-from test.test_support import TESTFN, findfile, run_unittest
+from test.test_support import TESTFN, run_unittest
 from UserList import UserList
 
 class AutoFileTests(unittest.TestCase):

Lib/test/test_filecmp.py

 
-import os, filecmp, shutil, tempfile, shutil
+import os, filecmp, shutil, tempfile
 import unittest
 from test import test_support
 

Lib/test/test_fileio.py

 from weakref import proxy
 from functools import wraps
 
-from test.test_support import (TESTFN, findfile, check_warnings, run_unittest,
-                               make_bad_fd)
+from test.test_support import TESTFN, check_warnings, run_unittest, make_bad_fd
 from test.test_support import py3k_bytes as bytes
 
 from _io import FileIO as _FileIO

Lib/test/test_float.py

 
     if float.__getformat__("double").startswith("IEEE"):
         def test_negative_zero(self):
-            import math
             def pos_pos():
                 return 0.0, math.atan2(0.0, -1)
             def pos_neg():
 
     if float.__getformat__("double").startswith("IEEE"):
         def test_underflow_sign(self):
-            import math
             # check that -1e-1000 gives -0.0, not 0.0
             self.assertEquals(math.atan2(-1e-1000, -1), math.atan2(-0.0, -1))
             self.assertEquals(math.atan2(float('-1e-1000'), -1),

Lib/test/test_fork1.py

 """This test checks for correct fork() behavior.
 """
 
-import errno
 import imp
 import os
 import signal

Lib/test/test_frozen.py

 
 from test.test_support import captured_stdout, run_unittest
 import unittest
-import sys, os
+import sys
 
 class FrozenTests(unittest.TestCase):
     def test_frozen(self):

Lib/test/test_future_builtins.py

 
 # we're testing the behavior of these future builtins:
 from future_builtins import hex, oct, map, zip, filter
-from test import test_support
 
 class BuiltinTest(unittest.TestCase):
     def test_hex(self):

Lib/test/test_gdbm.py

 import unittest
 import os
-from test.test_support import (verbose, TESTFN, run_unittest, unlink,
-    import_module)
+from test.test_support import TESTFN, run_unittest, unlink, import_module
 gdbm = import_module('gdbm')
 
 

Lib/test/test_getopt.py

 import unittest
 
 import getopt
-import os
 
 sentinel = object()
 

Lib/test/test_hashlib.py

 
 import array
 import hashlib
-import StringIO
 import itertools
 import sys
 try:

Lib/test/test_heapq.py

 
 
 def test_main(verbose=None):
-    from types import BuiltinFunctionType
-
     test_classes = [TestHeapPython, TestHeapC, TestErrorHandling]
     test_support.run_unittest(*test_classes)
 

Lib/test/test_imaplib.py

 from contextlib import contextmanager
 import imaplib
 import os.path
-import select
-import socket
 import SocketServer
-import sys
 import time
 
 from test_support import reap_threads, verbose

Lib/test/test_inspect.py

 import inspect
 import datetime
 
-from test.test_support import TESTFN, run_unittest
+from test.test_support import run_unittest
 
 from test import inspect_fodder as mod
 from test import inspect_fodder2 as mod2

Lib/test/test_io.py

 import unittest
 import warnings
 import weakref
-import gc
 import abc
-from itertools import chain, cycle, count
+from itertools import cycle, count
 from collections import deque
 from test import test_support as support
 

Lib/test/test_logging.py

      find_unused_port
 import textwrap
 import threading
-import time
 import unittest
 import warnings
 import weakref

Lib/test/test_long.py

 # ----------------------------------- tests of auto int->long conversion
 
     def test_auto_overflow(self):
-        import math, sys
-
         special = [0, 1, 2, 3, sys.maxint-1, sys.maxint, sys.maxint+1]
         sqrt = int(math.sqrt(sys.maxint))
         special.extend([sqrt-1, sqrt, sqrt+1])
             self.assertEqual(long(float(x)), y)
 
     def test_float_overflow(self):
-        import math
-
         for x in -2.0, -1.0, 0.0, 1.0, 2.0:
             self.assertEqual(float(long(x)), x)
 
                 "float(shuge) should not equal int(shuge)")
 
     def test_logs(self):
-        import math
-
         LOG10E = math.log10(math.e)
 
         for exp in range(10) + [100, 1000, 10000]:
 
     def test_mixed_compares(self):
         eq = self.assertEqual
-        import math
 
         # We're mostly concerned with that mixing floats and longs does the
         # right stuff, even when longs are too large to fit in a float.

Lib/test/test_macos.py

 import subprocess
 
 MacOS = test_support.import_module('MacOS')
-#The following should exist if MacOS exists.
-import Carbon.File
 
 TESTFN2 = test_support.TESTFN + '2'
 

Lib/test/test_memoryio.py

 
 import io
 import _pyio as pyio
-import sys
 import pickle
 
 class MemorySeekTestMixin:

Lib/test/test_multibytecodec.py

 #
 
 from test import test_support
-from test import test_multibytecodec_support
 from test.test_support import TESTFN
 import unittest, StringIO, codecs, sys, os
 import _multibytecodec

Lib/test/test_ntpath.py

 import ntpath
 import os
-from test.test_support import verbose, TestFailed
+from test.test_support import TestFailed
 import test.test_support as test_support
 import unittest
 

Lib/test/test_optparse.py

 from test import test_support
 
 
-from optparse import make_option, Option, IndentedHelpFormatter, \
-     TitledHelpFormatter, OptionParser, OptionContainer, OptionGroup, \
-     SUPPRESS_HELP, SUPPRESS_USAGE, OptionError, OptionConflictError, \
+from optparse import make_option, Option, \
+     TitledHelpFormatter, OptionParser, OptionGroup, \
+     SUPPRESS_USAGE, OptionError, OptionConflictError, \
      BadOptionError, OptionValueError, Values
 from optparse import _match_abbrev
 from optparse import _parse_num
 
     def variable_args(self, option, opt, value, parser):
         self.assertTrue(value is None)
-        done = 0
         value = []
         rargs = parser.rargs
         while rargs:

Lib/test/test_os.py

         self.assertTrue(s == "foobar")
 
     def test_tmpnam(self):
-        import sys
         if not hasattr(os, "tmpnam"):
             return
         warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning,
         self.assertEquals(result[stat.ST_SIZE], 3)
         self.assertEquals(result.st_size, 3)
 
-        import sys
-
         # Make sure all the attributes are there
         members = dir(result)
         for name in dir(stat):

Lib/test/test_parser.py

 import parser
-import os
 import unittest
 import sys
 from test import test_support

Lib/test/test_pdb.py

 # specified test modules (RFE #5142).
 
 import imp
-import os
 import sys
-import doctest
-import tempfile
 
 from test import test_support
 # This little helper class is essential for testing pdb under doctest.

Lib/test/test_print.py

 import unittest
 from test import test_support
 
-import sys
 from StringIO import StringIO
 
 NotDefined = object()

Lib/test/test_profile.py

 """Test suite for the profile module."""
 
-import os
 import sys
 import pstats
 import unittest

Lib/test/test_pyexpat.py

 import StringIO, sys
 import unittest
 
-import pyexpat
 from xml.parsers import expat
 
 from test.test_support import sortdict, run_unittest

Lib/test/test_queue.py

 # Some simple queue module tests, plus some failure conditions
 # to ensure the Queue locks remain stable.
 import Queue
-import sys
 import threading
 import time
 import unittest

Lib/test/test_random.py

 import time
 import pickle
 import warnings
-from math import log, exp, sqrt, pi, fsum, sin
+from math import log, exp, pi, fsum, sin
 from functools import reduce
 from test import test_support
 

Lib/test/test_re.py

 from test.test_support import verbose, run_unittest
 import re
 from re import Scanner
-import sys, os, traceback
+import sys, traceback
 from weakref import proxy
 
 # Misc tests from Tim Peters' re.doc
         self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow])
 
 def run_re_tests():
-    from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
+    from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
     if verbose:
         print 'Running re_tests test suite'
     else:

Lib/test/test_set.py

 import operator
 import copy
 import pickle
-import os
 from random import randrange, shuffle
 import sys
 import collections
 #==============================================================================
 
 def test_main(verbose=None):
-    from test import test_sets
     test_classes = (
         TestSet,
         TestSetSubclass,

Lib/test/test_socketserver.py

 """
 
 import contextlib
-import errno
 import imp
 import os
 import select
 import socket
 import tempfile
 import threading
-import time
 import unittest
 import SocketServer
 
 import test.test_support
 from test.test_support import reap_children, reap_threads, verbose
-from test.test_support import TESTFN as TEST_FILE
 
 test.test_support.requires("network")
 

Lib/test/test_sqlite.py

-import unittest
 from test.test_support import run_unittest, import_module
 
 # Skip test if _sqlite3 module was not built.

Lib/test/test_ssl.py

 import asyncore
 import socket
 import select
-import errno
-import subprocess
 import time
 import os
 import pprint
 import urllib, urlparse
-import shutil
 import traceback
 
 from BaseHTTPServer import HTTPServer

Lib/test/test_strftime.py

 
 import calendar
 import sys
-import os
 import re
 from test import test_support
 import time

Lib/test/test_struct.py

                         DeprecationWarning)
 
 from functools import wraps
-from test.test_support import TestFailed, verbose, run_unittest
+from test.test_support import run_unittest
 
 import sys
 ISBIGENDIAN = sys.byteorder == "big"

Lib/test/test_structmembers.py

     LONG_MAX, LONG_MIN, ULONG_MAX, \
     LLONG_MAX, LLONG_MIN, ULLONG_MAX
 
-import warnings, exceptions, unittest, sys
+import unittest
 from test import test_support
 
 ts=test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,

Lib/test/test_sys.py

 # -*- coding: iso-8859-1 -*-
 import unittest, test.test_support
-import sys, cStringIO, os
+import sys, os, cStringIO
 import struct
 import operator
 
         sys._clear_type_cache()
 
     def test_ioencoding(self):
-        import subprocess,os
+        import subprocess
         env = dict(os.environ)
 
         # Test character: cent sign, encoded as 0x4A (ASCII J) in CP424,

Lib/test/test_sysconfig.py

 """
 import unittest
 import sys
-import test
 import os
 import shutil
 from copy import copy, deepcopy
         return self._uname
 
     def _cleanup_testfn(self):
-        path = test.test_support.TESTFN
+        path = TESTFN
         if os.path.isfile(path):
             os.remove(path)
         elif os.path.isdir(path):

Lib/test/test_tarfile.py

 import sys
 import os
 import shutil
-import tempfile
 import StringIO
 from hashlib import md5
 import errno

Lib/test/test_tempfile.py

 import os
 import sys
 import re
-import errno
 import warnings
 
 import unittest

Lib/test/test_tk.py

 import os
-import sys
 import unittest
 from test import test_support
 

Lib/test/test_tokenize.py

 
 
 from test import test_support
-from tokenize import (tokenize, untokenize, generate_tokens, NUMBER, NAME, OP,
+from tokenize import (untokenize, generate_tokens, NUMBER, NAME, OP,
                      STRING, ENDMARKER, tok_name)
 from StringIO import StringIO
 import os

Lib/test/test_traceback.py

         self.assertTrue(err[1].find("2") == err[2].find("^"))
 
     def test_bug737473(self):
-        import sys, os, tempfile, time
+        import os, tempfile, time
 
         savedpath = sys.path[:]
         testdir = tempfile.mkdtemp()

Lib/test/test_ttk_guionly.py

 import os
-import sys
 import unittest
 from test import test_support
 

Lib/test/test_ttk_textonly.py

 import os
-import sys
 from test import test_support
 
 # Skip this test if _tkinter does not exist.

Lib/test/test_types.py

         if not {'x': 1}: self.fail('{\'x\': 1} is false instead of true')
         def f(): pass
         class C: pass
-        import sys
         x = C()
         if not f: self.fail('f is false instead of true')
         if not C: self.fail('C is false instead of true')

Lib/test/test_undocumented_details.py

-from test.test_support import run_unittest, have_unicode
+from test.test_support import run_unittest
 import unittest
-import sys
 
 class TestImplementationComparisons(unittest.TestCase):
 

Lib/test/test_urllib2net.py

 
 import socket
 import urllib2
-import sys
 import os
-import mimetools
 
 
 def _retry_thrice(func, exc, *args, **kwargs):
 class CloseSocketTest(unittest.TestCase):
 
     def test_close(self):
-        import socket, httplib, gc
+        import httplib
 
         # calling .close() on urllib2's response objects should close the
         # underlying socket
 ##             self._test_urls(urls, self._extra_handlers()+[bauth, dauth])
 
     def _test_urls(self, urls, handlers, retry=True):
-        import socket
         import time
         import logging
         debug = logging.getLogger("test_urllib2").debug

Lib/test/test_xml_etree.py

 # all included components work as they should.  For a more extensive
 # test suite, see the selftest script in the ElementTree distribution.
 
-import doctest
 import sys
 
 from test import test_support

Lib/test/test_xml_etree_c.py

 # xml.etree test for cElementTree
 
-import doctest
 import sys
 
 from test import test_support

Lib/test/test_zipimport_support.py

 # for working with modules located inside zipfiles
 # The tests are centralised in this fashion to make it easy to drop them
 # if a platform doesn't support zipimport
-import unittest
 import test.test_support
 import os
 import os.path
 import linecache
 import pdb
 from test.script_helper import (spawn_python, kill_python, run_python,
-                                temp_dir, make_script, compile_script,
-                                make_pkg, make_zip_script, make_zip_pkg)
+                                temp_dir, make_script, make_zip_script)
 
 verbose = test.test_support.verbose