mirror of
https://github.com/python/cpython.git
synced 2025-10-01 12:52:18 +00:00
Issue #25665: Test pickling with all protocols in test_typing.
This commit is contained in:
commit
9e788af7cc
1 changed files with 10 additions and 8 deletions
|
@ -602,11 +602,12 @@ class GenericTests(TestCase):
|
||||||
c = C()
|
c = C()
|
||||||
c.foo = 42
|
c.foo = 42
|
||||||
c.bar = 'abc'
|
c.bar = 'abc'
|
||||||
z = pickle.dumps(c)
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
x = pickle.loads(z)
|
z = pickle.dumps(c, proto)
|
||||||
self.assertEqual(x.foo, 42)
|
x = pickle.loads(z)
|
||||||
self.assertEqual(x.bar, 'abc')
|
self.assertEqual(x.foo, 42)
|
||||||
self.assertEqual(x.__dict__, {'foo': 42, 'bar': 'abc'})
|
self.assertEqual(x.bar, 'abc')
|
||||||
|
self.assertEqual(x.__dict__, {'foo': 42, 'bar': 'abc'})
|
||||||
|
|
||||||
def test_errors(self):
|
def test_errors(self):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
|
@ -1167,9 +1168,10 @@ class NamedTupleTests(TestCase):
|
||||||
global Emp # pickle wants to reference the class by name
|
global Emp # pickle wants to reference the class by name
|
||||||
Emp = NamedTuple('Emp', [('name', str), ('id', int)])
|
Emp = NamedTuple('Emp', [('name', str), ('id', int)])
|
||||||
jane = Emp('jane', 37)
|
jane = Emp('jane', 37)
|
||||||
z = pickle.dumps(jane)
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
jane2 = pickle.loads(z)
|
z = pickle.dumps(jane, proto)
|
||||||
assert jane == jane2
|
jane2 = pickle.loads(z)
|
||||||
|
self.assertEqual(jane2, jane)
|
||||||
|
|
||||||
|
|
||||||
class IOTests(TestCase):
|
class IOTests(TestCase):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue