[Python-checkins] bpo-45229: Make pickle tests discoverable (GH-28467) (GH-28479)

ambv webhook-mailer at python.org
Mon Sep 20 12:19:53 EDT 2021


https://github.com/python/cpython/commit/04dea46dde25d58f242171181805f0e71a042963
commit: 04dea46dde25d58f242171181805f0e71a042963
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-09-20T18:19:49+02:00
summary:

bpo-45229: Make pickle tests discoverable (GH-28467) (GH-28479)

(cherry picked from commit e6ba992288fdbe71aa808cfb6955f6f99da7e349)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
M Lib/test/pickletester.py
M Lib/test/test_pickle.py
M Lib/test/test_pickletools.py

diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 7e279cc736a23..a4ce5cebaebbb 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -824,7 +824,7 @@ def create_data():
     return x
 
 
-class AbstractUnpickleTests(unittest.TestCase):
+class AbstractUnpickleTests:
     # Subclass must define self.loads.
 
     _testdata = create_data()
@@ -1437,7 +1437,7 @@ def t():
 
 
 
-class AbstractPickleTests(unittest.TestCase):
+class AbstractPickleTests:
     # Subclass must define self.dumps, self.loads.
 
     optimized = False
@@ -3020,7 +3020,7 @@ def check_array(arr):
         check_array(arr[::2])
 
 
-class BigmemPickleTests(unittest.TestCase):
+class BigmemPickleTests:
 
     # Binary protocols can serialize longs of up to 2 GiB-1
 
@@ -3293,7 +3293,7 @@ def __getattr__(self, key):
         self.foo
 
 
-class AbstractPickleModuleTests(unittest.TestCase):
+class AbstractPickleModuleTests:
 
     def test_dump_closed_file(self):
         f = open(TESTFN, "wb")
@@ -3400,7 +3400,7 @@ def loads(data, **kwargs):
         self.check_dumps_loads_oob_buffers(dumps, loads)
 
 
-class AbstractPersistentPicklerTests(unittest.TestCase):
+class AbstractPersistentPicklerTests:
 
     # This class defines persistent_id() and persistent_load()
     # functions that should be used by the pickler.  All even integers
@@ -3440,7 +3440,7 @@ def test_persistence(self):
             self.assertEqual(self.load_false_count, 1)
 
 
-class AbstractIdentityPersistentPicklerTests(unittest.TestCase):
+class AbstractIdentityPersistentPicklerTests:
 
     def persistent_id(self, obj):
         return obj
@@ -3469,7 +3469,7 @@ def test_protocol0_is_ascii_only(self):
         self.assertRaises(pickle.UnpicklingError, self.loads, pickled)
 
 
-class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
+class AbstractPicklerUnpicklerObjectTests:
 
     pickler_class = None
     unpickler_class = None
@@ -3683,7 +3683,7 @@ def reducer_override(self, obj):
 
         return NotImplemented
 
-class AbstractHookTests(unittest.TestCase):
+class AbstractHookTests:
     def test_pickler_hook(self):
         # test the ability of a custom, user-defined CPickler subclass to
         # override the default reducing routines of any type using the method
@@ -3749,7 +3749,7 @@ def f():
                 self.assertIsNone(wr())
 
 
-class AbstractDispatchTableTests(unittest.TestCase):
+class AbstractDispatchTableTests:
 
     def test_default_dispatch_table(self):
         # No dispatch_table attribute by default
diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py
index 70672dc19cf4a..60c78b296890c 100644
--- a/Lib/test/test_pickle.py
+++ b/Lib/test/test_pickle.py
@@ -9,6 +9,7 @@
 import warnings
 import weakref
 
+import doctest
 import unittest
 from test import support
 
@@ -30,7 +31,7 @@
     has_c_implementation = False
 
 
-class PyPickleTests(AbstractPickleModuleTests):
+class PyPickleTests(AbstractPickleModuleTests, unittest.TestCase):
     dump = staticmethod(pickle._dump)
     dumps = staticmethod(pickle._dumps)
     load = staticmethod(pickle._load)
@@ -39,7 +40,7 @@ class PyPickleTests(AbstractPickleModuleTests):
     Unpickler = pickle._Unpickler
 
 
-class PyUnpicklerTests(AbstractUnpickleTests):
+class PyUnpicklerTests(AbstractUnpickleTests, unittest.TestCase):
 
     unpickler = pickle._Unpickler
     bad_stack_errors = (IndexError,)
@@ -53,7 +54,7 @@ def loads(self, buf, **kwds):
         return u.load()
 
 
-class PyPicklerTests(AbstractPickleTests):
+class PyPicklerTests(AbstractPickleTests, unittest.TestCase):
 
     pickler = pickle._Pickler
     unpickler = pickle._Unpickler
@@ -72,7 +73,7 @@ def loads(self, buf, **kwds):
 
 
 class InMemoryPickleTests(AbstractPickleTests, AbstractUnpickleTests,
-                          BigmemPickleTests):
+                          BigmemPickleTests, unittest.TestCase):
 
     bad_stack_errors = (pickle.UnpicklingError, IndexError)
     truncated_errors = (pickle.UnpicklingError, EOFError,
@@ -109,14 +110,14 @@ def persistent_load(subself, obj):
 
 
 class PyPersPicklerTests(AbstractPersistentPicklerTests,
-                         PersistentPicklerUnpicklerMixin):
+                         PersistentPicklerUnpicklerMixin, unittest.TestCase):
 
     pickler = pickle._Pickler
     unpickler = pickle._Unpickler
 
 
 class PyIdPersPicklerTests(AbstractIdentityPersistentPicklerTests,
-                           PersistentPicklerUnpicklerMixin):
+                           PersistentPicklerUnpicklerMixin, unittest.TestCase):
 
     pickler = pickle._Pickler
     unpickler = pickle._Unpickler
@@ -182,13 +183,13 @@ def persistent_load(pid):
         check(PersUnpickler)
 
 
-class PyPicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests):
+class PyPicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests, unittest.TestCase):
 
     pickler_class = pickle._Pickler
     unpickler_class = pickle._Unpickler
 
 
-class PyDispatchTableTests(AbstractDispatchTableTests):
+class PyDispatchTableTests(AbstractDispatchTableTests, unittest.TestCase):
 
     pickler_class = pickle._Pickler
 
@@ -196,7 +197,7 @@ def get_dispatch_table(self):
         return pickle.dispatch_table.copy()
 
 
-class PyChainDispatchTableTests(AbstractDispatchTableTests):
+class PyChainDispatchTableTests(AbstractDispatchTableTests, unittest.TestCase):
 
     pickler_class = pickle._Pickler
 
@@ -204,7 +205,7 @@ def get_dispatch_table(self):
         return collections.ChainMap({}, pickle.dispatch_table)
 
 
-class PyPicklerHookTests(AbstractHookTests):
+class PyPicklerHookTests(AbstractHookTests, unittest.TestCase):
     class CustomPyPicklerClass(pickle._Pickler,
                                AbstractCustomPicklerClass):
         pass
@@ -212,7 +213,7 @@ class CustomPyPicklerClass(pickle._Pickler,
 
 
 if has_c_implementation:
-    class CPickleTests(AbstractPickleModuleTests):
+    class CPickleTests(AbstractPickleModuleTests, unittest.TestCase):
         from _pickle import dump, dumps, load, loads, Pickler, Unpickler
 
     class CUnpicklerTests(PyUnpicklerTests):
@@ -240,7 +241,7 @@ class DumpPickle_CLoadPickle(PyPicklerTests):
         pickler = pickle._Pickler
         unpickler = _pickle.Unpickler
 
-    class CPicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests):
+    class CPicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests, unittest.TestCase):
         pickler_class = _pickle.Pickler
         unpickler_class = _pickle.Unpickler
 
@@ -253,17 +254,17 @@ def test_issue18339(self):
                 unpickler.memo = {-1: None}
             unpickler.memo = {1: None}
 
-    class CDispatchTableTests(AbstractDispatchTableTests):
+    class CDispatchTableTests(AbstractDispatchTableTests, unittest.TestCase):
         pickler_class = pickle.Pickler
         def get_dispatch_table(self):
             return pickle.dispatch_table.copy()
 
-    class CChainDispatchTableTests(AbstractDispatchTableTests):
+    class CChainDispatchTableTests(AbstractDispatchTableTests, unittest.TestCase):
         pickler_class = pickle.Pickler
         def get_dispatch_table(self):
             return collections.ChainMap({}, pickle.dispatch_table)
 
-    class CPicklerHookTests(AbstractHookTests):
+    class CPicklerHookTests(AbstractHookTests, unittest.TestCase):
         class CustomCPicklerClass(_pickle.Pickler, AbstractCustomPicklerClass):
             pass
         pickler_class = CustomCPicklerClass
@@ -512,22 +513,10 @@ def test_multiprocessing_exceptions(self):
                                  ('multiprocessing.context', name))
 
 
-def test_main():
-    tests = [PyPickleTests, PyUnpicklerTests, PyPicklerTests,
-             PyPersPicklerTests, PyIdPersPicklerTests,
-             PyDispatchTableTests, PyChainDispatchTableTests,
-             CompatPickleTests, PyPicklerHookTests]
-    if has_c_implementation:
-        tests.extend([CPickleTests, CUnpicklerTests, CPicklerTests,
-                      CPersPicklerTests, CIdPersPicklerTests,
-                      CDumpPickle_LoadPickle, DumpPickle_CLoadPickle,
-                      PyPicklerUnpicklerObjectTests,
-                      CPicklerUnpicklerObjectTests,
-                      CDispatchTableTests, CChainDispatchTableTests,
-                      CPicklerHookTests,
-                      InMemoryPickleTests, SizeofTests])
-    support.run_unittest(*tests)
-    support.run_doctest(pickle)
+def load_tests(loader, tests, pattern):
+    tests.addTest(doctest.DocTestSuite())
+    return tests
+
 
 if __name__ == "__main__":
-    test_main()
+    unittest.main()
diff --git a/Lib/test/test_pickletools.py b/Lib/test/test_pickletools.py
index 8cc6ca58cd04b..376a83d049e89 100644
--- a/Lib/test/test_pickletools.py
+++ b/Lib/test/test_pickletools.py
@@ -2,9 +2,10 @@
 import pickletools
 from test import support
 from test.pickletester import AbstractPickleTests
+import doctest
 import unittest
 
-class OptimizedPickleTests(AbstractPickleTests):
+class OptimizedPickleTests(AbstractPickleTests, unittest.TestCase):
 
     def dumps(self, arg, proto=None, **kwargs):
         return pickletools.optimize(pickle.dumps(arg, proto, **kwargs))
@@ -93,11 +94,10 @@ def test__all__(self):
         support.check__all__(self, pickletools, blacklist=blacklist)
 
 
-def test_main():
-    support.run_unittest(OptimizedPickleTests)
-    support.run_unittest(MiscTestCase)
-    support.run_doctest(pickletools)
+def load_tests(loader, tests, pattern):
+    tests.addTest(doctest.DocTestSuite(pickletools))
+    return tests
 
 
 if __name__ == "__main__":
-    test_main()
+    unittest.main()



More information about the Python-checkins mailing list