summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorCharles-François Natali <cf.natali@gmail.com>2014-07-25 17:45:02 (GMT)
committerCharles-François Natali <cf.natali@gmail.com>2014-07-25 17:45:02 (GMT)
commite396c363cbacce68d7750a7963af4d7cd3bf30e7 (patch)
tree40f9f102e9d7908e6bf4349128d42419e8735fec /Lib/test
parent65708cf510277492660420efa13bd2de163cd21b (diff)
parent2955a0bf06807d4e00ad053a7e2acb516939859e (diff)
downloadcpython-e396c363cbacce68d7750a7963af4d7cd3bf30e7.zip
cpython-e396c363cbacce68d7750a7963af4d7cd3bf30e7.tar.gz
cpython-e396c363cbacce68d7750a7963af4d7cd3bf30e7.tar.bz2
Merge.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/support/__init__.py21
-rw-r--r--Lib/test/test_asynchat.py17
-rw-r--r--Lib/test/test_asyncio/__init__.py25
-rw-r--r--Lib/test/test_asyncio/__main__.py7
-rw-r--r--Lib/test/test_asyncio/test_selector_events.py4
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py4
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py17
-rw-r--r--Lib/test/test_asyncio/test_windows_events.py36
-rw-r--r--Lib/test/test_email/__init__.py23
-rw-r--r--Lib/test/test_email/__main__.py5
-rw-r--r--Lib/test/test_gettext.py2
-rw-r--r--Lib/test/test_importlib/__init__.py34
-rw-r--r--Lib/test/test_importlib/__main__.py11
-rw-r--r--Lib/test/test_importlib/builtin/__init__.py13
-rw-r--r--Lib/test/test_importlib/builtin/__main__.py4
-rw-r--r--Lib/test/test_importlib/extension/__init__.py16
-rw-r--r--Lib/test/test_importlib/extension/__main__.py4
-rw-r--r--Lib/test/test_importlib/frozen/__init__.py16
-rw-r--r--Lib/test/test_importlib/frozen/__main__.py4
-rw-r--r--Lib/test/test_importlib/import_/__init__.py16
-rw-r--r--Lib/test/test_importlib/import_/__main__.py4
-rw-r--r--Lib/test/test_importlib/source/__init__.py16
-rw-r--r--Lib/test/test_importlib/source/__main__.py4
-rw-r--r--Lib/test/test_json/__init__.py19
-rw-r--r--Lib/test/test_plistlib.py5
-rw-r--r--Lib/test/test_readline.py23
-rw-r--r--Lib/test/test_tools/__init__.py10
27 files changed, 160 insertions, 200 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 9ec4e7c..f2c1a92 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -85,7 +85,7 @@ __all__ = [
"skip_unless_symlink", "requires_gzip", "requires_bz2", "requires_lzma",
"bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute",
"requires_IEEE_754", "skip_unless_xattr", "requires_zlib",
- "anticipate_failure",
+ "anticipate_failure", "load_package_tests",
# sys
"is_jython", "check_impl_detail",
# network
@@ -188,6 +188,25 @@ def anticipate_failure(condition):
return unittest.expectedFailure
return lambda f: f
+def load_package_tests(pkg_dir, loader, standard_tests, pattern):
+ """Generic load_tests implementation for simple test packages.
+
+ Most packages can implement load_tests using this function as follows:
+
+ def load_tests(*args):
+ return load_package_tests(os.path.dirname(__file__), *args)
+ """
+ if pattern is None:
+ pattern = "test*"
+ top_dir = os.path.dirname( # Lib
+ os.path.dirname( # test
+ os.path.dirname(__file__))) # support
+ package_tests = loader.discover(start_dir=pkg_dir,
+ top_level_dir=top_dir,
+ pattern=pattern)
+ standard_tests.addTests(package_tests)
+ return standard_tests
+
def import_fresh_module(name, fresh=(), blocked=(), deprecated=False):
"""Import and return a module, deliberately bypassing sys.modules.
diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py
index 84867ec..2dc9d0c 100644
--- a/Lib/test/test_asynchat.py
+++ b/Lib/test/test_asynchat.py
@@ -7,10 +7,12 @@ thread = support.import_module('_thread')
import asynchat
import asyncore
+import errno
import socket
import sys
import time
import unittest
+import unittest.mock
try:
import threading
except ImportError:
@@ -273,6 +275,21 @@ class TestAsynchat_WithPoll(TestAsynchat):
usepoll = True
+class TestAsynchatMocked(unittest.TestCase):
+ def test_blockingioerror(self):
+ # Issue #16133: handle_read() must ignore BlockingIOError
+ sock = unittest.mock.Mock()
+ sock.recv.side_effect = BlockingIOError(errno.EAGAIN)
+
+ dispatcher = asynchat.async_chat()
+ dispatcher.set_socket(sock)
+ self.addCleanup(dispatcher.del_channel)
+
+ with unittest.mock.patch.object(dispatcher, 'handle_error') as error:
+ dispatcher.handle_read()
+ self.assertFalse(error.called)
+
+
class TestHelperFunctions(unittest.TestCase):
def test_find_prefix_at_end(self):
self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1)
diff --git a/Lib/test/test_asyncio/__init__.py b/Lib/test/test_asyncio/__init__.py
index 82158af..80a9eea 100644
--- a/Lib/test/test_asyncio/__init__.py
+++ b/Lib/test/test_asyncio/__init__.py
@@ -1,29 +1,10 @@
import os
-import sys
-import unittest
-from test.support import run_unittest, import_module
+from test.support import load_package_tests, import_module
# Skip tests if we don't have threading.
import_module('threading')
# Skip tests if we don't have concurrent.futures.
import_module('concurrent.futures')
-
-def suite():
- tests = unittest.TestSuite()
- loader = unittest.TestLoader()
- for fn in os.listdir(os.path.dirname(__file__)):
- if fn.startswith("test") and fn.endswith(".py"):
- mod_name = 'test.test_asyncio.' + fn[:-3]
- try:
- __import__(mod_name)
- except unittest.SkipTest:
- pass
- else:
- mod = sys.modules[mod_name]
- tests.addTests(loader.loadTestsFromModule(mod))
- return tests
-
-
-def test_main():
- run_unittest(suite())
+def load_tests(*args):
+ return load_package_tests(os.path.dirname(__file__), *args)
diff --git a/Lib/test/test_asyncio/__main__.py b/Lib/test/test_asyncio/__main__.py
index b549492..40a23a2 100644
--- a/Lib/test/test_asyncio/__main__.py
+++ b/Lib/test/test_asyncio/__main__.py
@@ -1,5 +1,4 @@
-from . import test_main
+from . import load_tests
+import unittest
-
-if __name__ == '__main__':
- test_main()
+unittest.main()
diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py
index c0f388d..bd6c2f2 100644
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -672,6 +672,8 @@ class SelectorTransportTests(test_utils.TestCase):
def test_connection_lost(self):
exc = OSError()
tr = _SelectorTransport(self.loop, self.sock, self.protocol, None)
+ self.assertIsNotNone(tr._protocol)
+ self.assertIsNotNone(tr._loop)
tr._call_connection_lost(exc)
self.protocol.connection_lost.assert_called_with(exc)
@@ -679,8 +681,6 @@ class SelectorTransportTests(test_utils.TestCase):
self.assertIsNone(tr._sock)
self.assertIsNone(tr._protocol)
- self.assertEqual(2, sys.getrefcount(self.protocol),
- pprint.pformat(gc.get_referrers(self.protocol)))
self.assertIsNone(tr._loop)
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index a4e9df2..b5b1012 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -42,7 +42,7 @@ class SubprocessMixin:
return (exitcode, data)
task = run(b'some data')
- task = asyncio.wait_for(task, 10.0, loop=self.loop)
+ task = asyncio.wait_for(task, 60.0, loop=self.loop)
exitcode, stdout = self.loop.run_until_complete(task)
self.assertEqual(exitcode, 0)
self.assertEqual(stdout, b'some data')
@@ -61,7 +61,7 @@ class SubprocessMixin:
return proc.returncode, stdout
task = run(b'some data')
- task = asyncio.wait_for(task, 10.0, loop=self.loop)
+ task = asyncio.wait_for(task, 60.0, loop=self.loop)
exitcode, stdout = self.loop.run_until_complete(task)
self.assertEqual(exitcode, 0)
self.assertEqual(stdout, b'some data')
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index d355def..099d4d5 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -435,6 +435,8 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
def test__call_connection_lost(self):
tr = unix_events._UnixReadPipeTransport(
self.loop, self.pipe, self.protocol)
+ self.assertIsNotNone(tr._protocol)
+ self.assertIsNotNone(tr._loop)
err = None
tr._call_connection_lost(err)
@@ -442,13 +444,13 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
self.pipe.close.assert_called_with()
self.assertIsNone(tr._protocol)
- self.assertEqual(2, sys.getrefcount(self.protocol),
- pprint.pformat(gc.get_referrers(self.protocol)))
self.assertIsNone(tr._loop)
def test__call_connection_lost_with_err(self):
tr = unix_events._UnixReadPipeTransport(
self.loop, self.pipe, self.protocol)
+ self.assertIsNotNone(tr._protocol)
+ self.assertIsNotNone(tr._loop)
err = OSError()
tr._call_connection_lost(err)
@@ -456,9 +458,6 @@ class UnixReadPipeTransportTests(test_utils.TestCase):
self.pipe.close.assert_called_with()
self.assertIsNone(tr._protocol)
-
- self.assertEqual(2, sys.getrefcount(self.protocol),
- pprint.pformat(gc.get_referrers(self.protocol)))
self.assertIsNone(tr._loop)
@@ -717,6 +716,8 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
def test__call_connection_lost(self):
tr = unix_events._UnixWritePipeTransport(
self.loop, self.pipe, self.protocol)
+ self.assertIsNotNone(tr._protocol)
+ self.assertIsNotNone(tr._loop)
err = None
tr._call_connection_lost(err)
@@ -724,13 +725,13 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
self.pipe.close.assert_called_with()
self.assertIsNone(tr._protocol)
- self.assertEqual(2, sys.getrefcount(self.protocol),
- pprint.pformat(gc.get_referrers(self.protocol)))
self.assertIsNone(tr._loop)
def test__call_connection_lost_with_err(self):
tr = unix_events._UnixWritePipeTransport(
self.loop, self.pipe, self.protocol)
+ self.assertIsNotNone(tr._protocol)
+ self.assertIsNotNone(tr._loop)
err = OSError()
tr._call_connection_lost(err)
@@ -738,8 +739,6 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
self.pipe.close.assert_called_with()
self.assertIsNone(tr._protocol)
- self.assertEqual(2, sys.getrefcount(self.protocol),
- pprint.pformat(gc.get_referrers(self.protocol)))
self.assertIsNone(tr._loop)
def test_close(self):
diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py
index 4ab56e6..85d9669 100644
--- a/Lib/test/test_asyncio/test_windows_events.py
+++ b/Lib/test/test_asyncio/test_windows_events.py
@@ -94,38 +94,48 @@ class ProactorTests(test_utils.TestCase):
event = _overlapped.CreateEvent(None, True, False, None)
self.addCleanup(_winapi.CloseHandle, event)
- # Wait for unset event with 0.2s timeout;
+ # Wait for unset event with 0.5s timeout;
# result should be False at timeout
- f = self.loop._proactor.wait_for_handle(event, 0.2)
+ fut = self.loop._proactor.wait_for_handle(event, 0.5)
start = self.loop.time()
- self.loop.run_until_complete(f)
+ self.loop.run_until_complete(fut)
elapsed = self.loop.time() - start
- self.assertFalse(f.result())
- self.assertTrue(0.18 < elapsed < 0.9, elapsed)
+ self.assertFalse(fut.result())
+ self.assertTrue(0.48 < elapsed < 0.9, elapsed)
_overlapped.SetEvent(event)
# Wait for for set event;
# result should be True immediately
- f = self.loop._proactor.wait_for_handle(event, 10)
+ fut = self.loop._proactor.wait_for_handle(event, 10)
start = self.loop.time()
- self.loop.run_until_complete(f)
+ self.loop.run_until_complete(fut)
elapsed = self.loop.time() - start
- self.assertTrue(f.result())
- self.assertTrue(0 <= elapsed < 0.1, elapsed)
+ self.assertTrue(fut.result())
+ self.assertTrue(0 <= elapsed < 0.3, elapsed)
- _overlapped.ResetEvent(event)
+ # Tulip issue #195: cancelling a done _WaitHandleFuture must not crash
+ fut.cancel()
+
+ def test_wait_for_handle_cancel(self):
+ event = _overlapped.CreateEvent(None, True, False, None)
+ self.addCleanup(_winapi.CloseHandle, event)
# Wait for unset event with a cancelled future;
# CancelledError should be raised immediately
- f = self.loop._proactor.wait_for_handle(event, 10)
- f.cancel()
+ fut = self.loop._proactor.wait_for_handle(event, 10)
+ fut.cancel()
start = self.loop.time()
with self.assertRaises(asyncio.CancelledError):
- self.loop.run_until_complete(f)
+ self.loop.run_until_complete(fut)
elapsed = self.loop.time() - start
self.assertTrue(0 <= elapsed < 0.1, elapsed)
+ # Tulip issue #195: cancelling a _WaitHandleFuture twice must not crash
+ fut = self.loop._proactor.wait_for_handle(event)
+ fut.cancel()
+ fut.cancel()
+
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/test/test_email/__init__.py b/Lib/test/test_email/__init__.py
index d8896ee..a59775c 100644
--- a/Lib/test/test_email/__init__.py
+++ b/Lib/test/test_email/__init__.py
@@ -1,31 +1,16 @@
import os
import sys
import unittest
-import test.support
import collections
import email
from email.message import Message
from email._policybase import compat32
+from test.support import load_package_tests
from test.test_email import __file__ as landmark
-# Run all tests in package for '-m unittest test.test_email'
-def load_tests(loader, standard_tests, pattern):
- this_dir = os.path.dirname(__file__)
- if pattern is None:
- pattern = "test*"
- package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
- standard_tests.addTests(package_tests)
- return standard_tests
-
-
-# used by regrtest and __main__.
-def test_main():
- here = os.path.dirname(__file__)
- # Unittest mucks with the path, so we have to save and restore
- # it to keep regrtest happy.
- savepath = sys.path[:]
- test.support._run_suite(unittest.defaultTestLoader.discover(here))
- sys.path[:] = savepath
+# Load all tests in package
+def load_tests(*args):
+ return load_package_tests(os.path.dirname(__file__), *args)
# helper code used by a number of test modules.
diff --git a/Lib/test/test_email/__main__.py b/Lib/test/test_email/__main__.py
index 98af9ec..4b14f77 100644
--- a/Lib/test/test_email/__main__.py
+++ b/Lib/test/test_email/__main__.py
@@ -1,3 +1,4 @@
-from test.test_email import test_main
+from test.test_email import load_tests
+import unittest
-test_main()
+unittest.main()
diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py
index 5456948..abb312f 100644
--- a/Lib/test/test_gettext.py
+++ b/Lib/test/test_gettext.py
@@ -77,7 +77,7 @@ class GettextBaseTest(unittest.TestCase):
def tearDown(self):
self.env.__exit__()
del self.env
- shutil.rmtree(os.path.split(LOCALEDIR)[0])
+ support.rmtree(os.path.split(LOCALEDIR)[0])
class GettextTestCase1(GettextBaseTest):
diff --git a/Lib/test/test_importlib/__init__.py b/Lib/test/test_importlib/__init__.py
index 0e345cd..4b16ecc 100644
--- a/Lib/test/test_importlib/__init__.py
+++ b/Lib/test/test_importlib/__init__.py
@@ -1,33 +1,5 @@
import os
-import sys
-from test import support
-import unittest
+from test.support import load_package_tests
-def test_suite(package=__package__, directory=os.path.dirname(__file__)):
- suite = unittest.TestSuite()
- for name in os.listdir(directory):
- if name.startswith(('.', '__')):
- continue
- path = os.path.join(directory, name)
- if (os.path.isfile(path) and name.startswith('test_') and
- name.endswith('.py')):
- submodule_name = os.path.splitext(name)[0]
- module_name = "{0}.{1}".format(package, submodule_name)
- __import__(module_name, level=0)
- module_tests = unittest.findTestCases(sys.modules[module_name])
- suite.addTest(module_tests)
- elif os.path.isdir(path):
- package_name = "{0}.{1}".format(package, name)
- __import__(package_name, level=0)
- package_tests = getattr(sys.modules[package_name], 'test_suite')()
- suite.addTest(package_tests)
- else:
- continue
- return suite
-
-
-def test_main():
- start_dir = os.path.dirname(__file__)
- top_dir = os.path.dirname(os.path.dirname(start_dir))
- test_loader = unittest.TestLoader()
- support.run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir))
+def load_tests(*args):
+ return load_package_tests(os.path.dirname(__file__), *args)
diff --git a/Lib/test/test_importlib/__main__.py b/Lib/test/test_importlib/__main__.py
index 14bd5bc..40a23a2 100644
--- a/Lib/test/test_importlib/__main__.py
+++ b/Lib/test/test_importlib/__main__.py
@@ -1,9 +1,4 @@
-"""Run importlib's test suite.
+from . import load_tests
+import unittest
-Specifying the ``--builtin`` flag will run tests, where applicable, with
-builtins.__import__ instead of importlib.__import__.
-
-"""
-if __name__ == '__main__':
- from . import test_main
- test_main()
+unittest.main()
diff --git a/Lib/test/test_importlib/builtin/__init__.py b/Lib/test/test_importlib/builtin/__init__.py
index 15c0ade..4b16ecc 100644
--- a/Lib/test/test_importlib/builtin/__init__.py
+++ b/Lib/test/test_importlib/builtin/__init__.py
@@ -1,12 +1,5 @@
-from .. import test_suite
import os
+from test.support import load_package_tests
-
-def test_suite():
- directory = os.path.dirname(__file__)
- return test_suite('importlib.test.builtin', directory)
-
-
-if __name__ == '__main__':
- from test.support import run_unittest
- run_unittest(test_suite())
+def load_tests(*args):
+ return load_package_tests(os.path.dirname(__file__), *args)
diff --git a/Lib/test/test_importlib/builtin/__main__.py b/Lib/test/test_importlib/builtin/__main__.py
new file mode 100644
index 0000000..40a23a2
--- /dev/null
+++ b/Lib/test/test_importlib/builtin/__main__.py
@@ -0,0 +1,4 @@
+from . import load_tests
+import unittest
+
+unittest.main()
diff --git a/Lib/test/test_importlib/extension/__init__.py b/Lib/test/test_importlib/extension/__init__.py
index c033923..4b16ecc 100644
--- a/Lib/test/test_importlib/extension/__init__.py
+++ b/Lib/test/test_importlib/extension/__init__.py
@@ -1,13 +1,5 @@
-from .. import test_suite
-import os.path
-import unittest
+import os
+from test.support import load_package_tests
-
-def test_suite():
- directory = os.path.dirname(__file__)
- return test_suite('importlib.test.extension', directory)
-
-
-if __name__ == '__main__':
- from test.support import run_unittest
- run_unittest(test_suite())
+def load_tests(*args):
+ return load_package_tests(os.path.dirname(__file__), *args)
diff --git a/Lib/test/test_importlib/extension/__main__.py b/Lib/test/test_importlib/extension/__main__.py
new file mode 100644
index 0000000..40a23a2
--- /dev/null
+++ b/Lib/test/test_importlib/extension/__main__.py
@@ -0,0 +1,4 @@
+from . import load_tests
+import unittest
+
+unittest.main()
diff --git a/Lib/test/test_importlib/frozen/__init__.py b/Lib/test/test_importlib/frozen/__init__.py
index 9ef103b..4b16ecc 100644
--- a/Lib/test/test_importlib/frozen/__init__.py
+++ b/Lib/test/test_importlib/frozen/__init__.py
@@ -1,13 +1,5 @@
-from .. import test_suite
-import os.path
-import unittest
+import os
+from test.support import load_package_tests
-
-def test_suite():
- directory = os.path.dirname(__file__)
- return test_suite('importlib.test.frozen', directory)
-
-
-if __name__ == '__main__':
- from test.support import run_unittest
- run_unittest(test_suite())
+def load_tests(*args):
+ return load_package_tests(os.path.dirname(__file__), *args)
diff --git a/Lib/test/test_importlib/frozen/__main__.py b/Lib/test/test_importlib/frozen/__main__.py
new file mode 100644
index 0000000..40a23a2
--- /dev/null
+++ b/Lib/test/test_importlib/frozen/__main__.py
@@ -0,0 +1,4 @@
+from . import load_tests
+import unittest
+
+unittest.main()
diff --git a/Lib/test/test_importlib/import_/__init__.py b/Lib/test/test_importlib/import_/__init__.py
index 366e531..4b16ecc 100644
--- a/Lib/test/test_importlib/import_/__init__.py
+++ b/Lib/test/test_importlib/import_/__init__.py
@@ -1,13 +1,5 @@
-from .. import test_suite
-import os.path
-import unittest
+import os
+from test.support import load_package_tests
-
-def test_suite():
- directory = os.path.dirname(__file__)
- return test_suite('importlib.test.import_', directory)
-
-
-if __name__ == '__main__':
- from test.support import run_unittest
- run_unittest(test_suite())
+def load_tests(*args):
+ return load_package_tests(os.path.dirname(__file__), *args)
diff --git a/Lib/test/test_importlib/import_/__main__.py b/Lib/test/test_importlib/import_/__main__.py
new file mode 100644
index 0000000..40a23a2
--- /dev/null
+++ b/Lib/test/test_importlib/import_/__main__.py
@@ -0,0 +1,4 @@
+from . import load_tests
+import unittest
+
+unittest.main()
diff --git a/Lib/test/test_importlib/source/__init__.py b/Lib/test/test_importlib/source/__init__.py
index 3ef97f3..4b16ecc 100644
--- a/Lib/test/test_importlib/source/__init__.py
+++ b/Lib/test/test_importlib/source/__init__.py
@@ -1,13 +1,5 @@
-from .. import test_suite
-import os.path
-import unittest
+import os
+from test.support import load_package_tests
-
-def test_suite():
- directory = os.path.dirname(__file__)
- return test.test_suite('importlib.test.source', directory)
-
-
-if __name__ == '__main__':
- from test.support import run_unittest
- run_unittest(test_suite())
+def load_tests(*args):
+ return load_package_tests(os.path.dirname(__file__), *args)
diff --git a/Lib/test/test_importlib/source/__main__.py b/Lib/test/test_importlib/source/__main__.py
new file mode 100644
index 0000000..40a23a2
--- /dev/null
+++ b/Lib/test/test_importlib/source/__main__.py
@@ -0,0 +1,4 @@
+from . import load_tests
+import unittest
+
+unittest.main()
diff --git a/Lib/test/test_json/__init__.py b/Lib/test/test_json/__init__.py
index f994f9b..2cf1032 100644
--- a/Lib/test/test_json/__init__.py
+++ b/Lib/test/test_json/__init__.py
@@ -42,23 +42,12 @@ class TestCTest(CTest):
'_json')
-here = os.path.dirname(__file__)
-
-def load_tests(*args):
- suite = additional_tests()
- loader = unittest.TestLoader()
- for fn in os.listdir(here):
- if fn.startswith("test") and fn.endswith(".py"):
- modname = "test.test_json." + fn[:-3]
- __import__(modname)
- module = sys.modules[modname]
- suite.addTests(loader.loadTestsFromModule(module))
- return suite
-
-def additional_tests():
+def load_tests(loader, _, pattern):
suite = unittest.TestSuite()
for mod in (json, json.encoder, json.decoder):
suite.addTest(doctest.DocTestSuite(mod))
suite.addTest(TestPyTest('test_pyjson'))
suite.addTest(TestCTest('test_cjson'))
- return suite
+
+ pkg_dir = os.path.dirname(__file__)
+ return support.load_package_tests(pkg_dir, loader, suite, pattern)
diff --git a/Lib/test/test_plistlib.py b/Lib/test/test_plistlib.py
index dc2fdf6..fef9f39 100644
--- a/Lib/test/test_plistlib.py
+++ b/Lib/test/test_plistlib.py
@@ -207,6 +207,9 @@ class TestPlistlib(unittest.TestCase):
for fmt in ALL_FORMATS:
with self.subTest(fmt=fmt):
pl = self._create(fmt=fmt)
+ pl2 = plistlib.loads(TESTDATA[fmt], fmt=fmt)
+ self.assertEqual(dict(pl), dict(pl2),
+ "generated data was not identical to Apple's output")
pl2 = plistlib.loads(TESTDATA[fmt])
self.assertEqual(dict(pl), dict(pl2),
"generated data was not identical to Apple's output")
@@ -217,6 +220,8 @@ class TestPlistlib(unittest.TestCase):
b = BytesIO()
pl = self._create(fmt=fmt)
plistlib.dump(pl, b, fmt=fmt)
+ pl2 = plistlib.load(BytesIO(b.getvalue()), fmt=fmt)
+ self.assertEqual(dict(pl), dict(pl2))
pl2 = plistlib.load(BytesIO(b.getvalue()))
self.assertEqual(dict(pl), dict(pl2))
diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py
index 5483dd3..8b77818 100644
--- a/Lib/test/test_readline.py
+++ b/Lib/test/test_readline.py
@@ -1,17 +1,20 @@
"""
Very minimal unittests for parts of the readline module.
-
-These tests were added to check that the libedit emulation on OSX and
-the "real" readline have the same interface for history manipulation. That's
-why the tests cover only a small subset of the interface.
"""
+import os
import unittest
from test.support import run_unittest, import_module
+from test.script_helper import assert_python_ok
# Skip tests if there is no readline module
readline = import_module('readline')
class TestHistoryManipulation (unittest.TestCase):
+ """
+ These tests were added to check that the libedit emulation on OSX and the
+ "real" readline have the same interface for history manipulation. That's
+ why the tests cover only a small subset of the interface.
+ """
@unittest.skipIf(not hasattr(readline, 'clear_history'),
"The history update test cannot be run because the "
@@ -40,8 +43,18 @@ class TestHistoryManipulation (unittest.TestCase):
self.assertEqual(readline.get_current_history_length(), 1)
+class TestReadline(unittest.TestCase):
+ def test_init(self):
+ # Issue #19884: Ensure that the ANSI sequence "\033[1034h" is not
+ # written into stdout when the readline module is imported and stdout
+ # is redirected to a pipe.
+ rc, stdout, stderr = assert_python_ok('-c', 'import readline',
+ TERM='xterm-256color')
+ self.assertEqual(stdout, b'')
+
+
def test_main():
- run_unittest(TestHistoryManipulation)
+ run_unittest(TestHistoryManipulation, TestReadline)
if __name__ == "__main__":
test_main()
diff --git a/Lib/test/test_tools/__init__.py b/Lib/test/test_tools/__init__.py
index 9b94cb4..04c8726 100644
--- a/Lib/test/test_tools/__init__.py
+++ b/Lib/test/test_tools/__init__.py
@@ -21,11 +21,5 @@ def import_tool(toolname):
with support.DirsOnSysPath(scriptsdir):
return importlib.import_module(toolname)
-def load_tests(loader, standard_tests, pattern):
- this_dir = os.path.dirname(__file__)
- if pattern is None:
- pattern = "test*"
- with support.DirsOnSysPath():
- package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
- standard_tests.addTests(package_tests)
- return standard_tests
+def load_tests(*args):
+ return support.load_package_tests(os.path.dirname(__file__), *args)