Moved unpickling tests with prepickled data to separate class.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 29 Sep 2015 12:34:53 +0000 (15:34 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 29 Sep 2015 12:34:53 +0000 (15:34 +0300)
1  2 
Lib/test/pickletester.py
Lib/test/test_pickle.py

index 78b548392812d5d871fa1aec539213bed14b130e,e8f6574aedfb9580bb5c23e3521b748d79538505..55851295bc79c38f96c7f75821260181b0c61285
@@@ -1734,54 -1710,6 +1767,27 @@@ class AbstractPickleTests(unittest.Test
                      self.assertIn(('c%s\n%s' % (mod, name)).encode(), pickled)
                      self.assertIs(type(self.loads(pickled)), type(val))
  
-     def test_compat_unpickle(self):
-         # xrange(1, 7)
-         pickled = b'\x80\x02c__builtin__\nxrange\nK\x01K\x07K\x01\x87R.'
-         unpickled = self.loads(pickled)
-         self.assertIs(type(unpickled), range)
-         self.assertEqual(unpickled, range(1, 7))
-         self.assertEqual(list(unpickled), [1, 2, 3, 4, 5, 6])
-         # reduce
-         pickled = b'\x80\x02c__builtin__\nreduce\n.'
-         self.assertIs(self.loads(pickled), functools.reduce)
-         # whichdb.whichdb
-         pickled = b'\x80\x02cwhichdb\nwhichdb\n.'
-         self.assertIs(self.loads(pickled), dbm.whichdb)
-         # Exception(), StandardError()
-         for name in (b'Exception', b'StandardError'):
-             pickled = (b'\x80\x02cexceptions\n' + name + b'\nU\x03ugh\x85R.')
-             unpickled = self.loads(pickled)
-             self.assertIs(type(unpickled), Exception)
-             self.assertEqual(str(unpickled), 'ugh')
-         # UserDict.UserDict({1: 2}), UserDict.IterableUserDict({1: 2})
-         for name in (b'UserDict', b'IterableUserDict'):
-             pickled = (b'\x80\x02(cUserDict\n' + name +
-                        b'\no}U\x04data}K\x01K\x02ssb.')
-             unpickled = self.loads(pickled)
-             self.assertIs(type(unpickled), collections.UserDict)
-             self.assertEqual(unpickled, collections.UserDict({1: 2}))
 +    def test_local_lookup_error(self):
 +        # Test that whichmodule() errors out cleanly when looking up
 +        # an assumed globally-reachable object fails.
 +        def f():
 +            pass
 +        # Since the function is local, lookup will fail
 +        for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
 +            with self.assertRaises((AttributeError, pickle.PicklingError)):
 +                pickletools.dis(self.dumps(f, proto))
 +        # Same without a __module__ attribute (exercises a different path
 +        # in _pickle.c).
 +        del f.__module__
 +        for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
 +            with self.assertRaises((AttributeError, pickle.PicklingError)):
 +                pickletools.dis(self.dumps(f, proto))
 +        # Yet a different path.
 +        f.__name__ = f.__qualname__
 +        for proto in range(0, pickle.HIGHEST_PROTOCOL + 1):
 +            with self.assertRaises((AttributeError, pickle.PicklingError)):
 +                pickletools.dis(self.dumps(f, proto))
 +
  
  class BigmemPickleTests(unittest.TestCase):
  
Simple merge