[Python-checkins] cpython (merge 3.5 -> default): Issue #25665: Test pickling with all protocols in test_typing.

serhiy.storchaka python-checkins at python.org
Fri Nov 20 11:49:38 EST 2015


https://hg.python.org/cpython/rev/9e65015582a5
changeset:   99228:9e65015582a5
parent:      99226:14a3cfc477c6
parent:      99227:4f30b0d47c24
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Fri Nov 20 18:33:33 2015 +0200
summary:
  Issue #25665: Test pickling with all protocols in test_typing.

files:
  Lib/test/test_typing.py |  18 ++++++++++--------
  1 files changed, 10 insertions(+), 8 deletions(-)


diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -602,11 +602,12 @@
         c = C()
         c.foo = 42
         c.bar = 'abc'
-        z = pickle.dumps(c)
-        x = pickle.loads(z)
-        self.assertEqual(x.foo, 42)
-        self.assertEqual(x.bar, 'abc')
-        self.assertEqual(x.__dict__, {'foo': 42, 'bar': 'abc'})
+        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+            z = pickle.dumps(c, proto)
+            x = pickle.loads(z)
+            self.assertEqual(x.foo, 42)
+            self.assertEqual(x.bar, 'abc')
+            self.assertEqual(x.__dict__, {'foo': 42, 'bar': 'abc'})
 
     def test_errors(self):
         with self.assertRaises(TypeError):
@@ -1167,9 +1168,10 @@
         global Emp  # pickle wants to reference the class by name
         Emp = NamedTuple('Emp', [('name', str), ('id', int)])
         jane = Emp('jane', 37)
-        z = pickle.dumps(jane)
-        jane2 = pickle.loads(z)
-        assert jane == jane2
+        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+            z = pickle.dumps(jane, proto)
+            jane2 = pickle.loads(z)
+            self.assertEqual(jane2, jane)
 
 
 class IOTests(TestCase):

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list