bpo-29919: Remove unused imports found by pyflakes (#137)

Make also minor PEP8 coding style fixes on modified imports.
diff --git a/Lib/test/ssl_servers.py b/Lib/test/ssl_servers.py
index b99ea45..8146467 100644
--- a/Lib/test/ssl_servers.py
+++ b/Lib/test/ssl_servers.py
@@ -2,7 +2,6 @@
 import sys
 import ssl
 import pprint
-import socket
 import urllib.parse
 # Rename HTTPServer to _HTTPServer so as to avoid confusion with HTTPSServer.
 from http.server import (HTTPServer as _HTTPServer,
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
index 4bc8382..e20e033 100644
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -4,7 +4,6 @@
 """Unit tests for abc.py."""
 
 import unittest
-from test import support
 
 import abc
 from inspect import isabstract
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py
index 2b7c5d0..8c69d2b 100644
--- a/Lib/test/test_asyncgen.py
+++ b/Lib/test/test_asyncgen.py
@@ -2,8 +2,6 @@
 import types
 import unittest
 
-from unittest import mock
-
 from test.support import import_module
 asyncio = import_module("asyncio")
 
diff --git a/Lib/test/test_asyncio/test_pep492.py b/Lib/test/test_asyncio/test_pep492.py
index d5b8522..77eb7cd 100644
--- a/Lib/test/test_asyncio/test_pep492.py
+++ b/Lib/test/test_asyncio/test_pep492.py
@@ -1,6 +1,5 @@
 """Tests support for new syntax introduced by PEP 492."""
 
-import collections.abc
 import types
 import unittest
 
diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py
index 3ed018e..4f5b8a8 100644
--- a/Lib/test/test_binop.py
+++ b/Lib/test/test_binop.py
@@ -1,7 +1,6 @@
 """Tests for binary operators on subtypes of built-in types."""
 
 import unittest
-from test import support
 from operator import eq, le, ne
 from abc import ABCMeta
 
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 416316c..d2420e9 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -18,7 +18,7 @@
 import unittest
 import warnings
 from operator import neg
-from test.support import TESTFN, unlink,  run_unittest, check_warnings
+from test.support import TESTFN, unlink, check_warnings
 from test.support.script_helper import assert_python_ok
 try:
     import pty, signal
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 87c6978..3bf1578 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -3,7 +3,6 @@
 import collections
 import copy
 import doctest
-import inspect
 import keyword
 import operator
 import pickle
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 48360d1..53f71ca 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -34,7 +34,7 @@
 import locale
 from test.support import (run_unittest, run_doctest, is_resource_enabled,
                           requires_IEEE_754, requires_docstrings)
-from test.support import (check_warnings, import_fresh_module, TestFailed,
+from test.support import (import_fresh_module, TestFailed,
                           run_with_locale, cpython_only)
 import random
 import inspect
@@ -1170,7 +1170,6 @@
     @run_with_locale('LC_ALL', 'ps_AF')
     def test_wide_char_separator_decimal_point(self):
         # locale with wide char separator and decimal point
-        import locale
         Decimal = self.decimal.Decimal
 
         decimal_point = locale.localeconv()['decimal_point']
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index ce517b5..e895c3c 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -5,7 +5,6 @@
 import weakref
 import copy
 import pickle
-from io import StringIO
 import random
 import struct
 
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index f81c82f..7956bdd 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -6,7 +6,6 @@
 import warnings
 import weakref
 import inspect
-import types
 
 from test import support
 
diff --git a/Lib/test/test_http_cookies.py b/Lib/test/test_http_cookies.py
index ca21476..2ff6902 100644
--- a/Lib/test/test_http_cookies.py
+++ b/Lib/test/test_http_cookies.py
@@ -1,11 +1,11 @@
 # Simple test suite for http/cookies.py
 
 import copy
-from test.support import run_unittest, run_doctest, check_warnings
+from test.support import run_unittest, run_doctest
 import unittest
 from http import cookies
 import pickle
-import warnings
+
 
 class CookieTests(unittest.TestCase):
 
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py
index fac6b57..5ef9512 100644
--- a/Lib/test/test_imaplib.py
+++ b/Lib/test/test_imaplib.py
@@ -10,7 +10,6 @@
 import socketserver
 import time
 import calendar
-import inspect
 
 from test.support import (reap_threads, verbose, transient_internet,
                           run_with_tz, run_with_locale)
diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py
index 7e568be..d84ef7d 100644
--- a/Lib/test/test_json/test_decode.py
+++ b/Lib/test/test_json/test_decode.py
@@ -1,5 +1,5 @@
 import decimal
-from io import StringIO, BytesIO
+from io import StringIO
 from collections import OrderedDict
 from test.test_json import PyTest, CTest
 
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index ed438d5..6813d15 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -1,6 +1,5 @@
 import os
 import sys
-import builtins
 import contextlib
 import importlib.util
 import inspect
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 1d7fb76..a1fddfb 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -1,5 +1,5 @@
-from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G, \
-        cpython_only, captured_stdout
+from test.support import (gc_collect, bigmemtest, _2G,
+                          cpython_only, captured_stdout)
 import locale
 import re
 import sre_compile
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 3688eae..c7f7d1d 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -11,7 +11,6 @@
 import errno
 import functools
 import subprocess
-from contextlib import ExitStack
 from shutil import (make_archive,
                     register_archive_format, unregister_archive_format,
                     get_archive_formats, Error, unpack_archive,
@@ -22,8 +21,7 @@
 import zipfile
 
 from test import support
-from test.support import (TESTFN, check_warnings, captured_stdout,
-                          android_not_root)
+from test.support import TESTFN, android_not_root
 
 TESTFN2 = TESTFN + "2"
 
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index 8a404ef..22715cf 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -1,12 +1,11 @@
-import unittest
-from test import support
-from contextlib import closing
-import select
+import os
 import signal
 import socket
-import struct
 import subprocess
-import sys, os, time, errno
+import sys
+import time
+import unittest
+from test import support
 from test.support.script_helper import assert_python_ok, spawn_python
 try:
     import threading
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 9aeb28a..748445e 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -9,7 +9,6 @@
 import codecs
 import gc
 import sysconfig
-import platform
 import locale
 
 # count the number of test runs, used to create unique
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index f70504c..506f071 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -10,7 +10,6 @@
 import itertools
 import operator
 import struct
-import string
 import sys
 import unittest
 import warnings
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index f3d9936..47436e5 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -16,7 +16,7 @@
 from test.support import script_helper
 from test.support import (TESTFN, findfile, unlink, rmtree, temp_dir, temp_cwd,
                           requires_zlib, requires_bz2, requires_lzma,
-                          captured_stdout, check_warnings)
+                          captured_stdout)
 
 TESTFN2 = TESTFN + "2"
 TESTFNDIR = TESTFN + "d"
diff --git a/Lib/test/test_zipfile64.py b/Lib/test/test_zipfile64.py
index c29bd8d..ae29545 100644
--- a/Lib/test/test_zipfile64.py
+++ b/Lib/test/test_zipfile64.py
@@ -15,7 +15,6 @@
 import time
 import sys
 
-from io import StringIO
 from tempfile import TemporaryFile
 
 from test.support import TESTFN, requires_zlib