MCPcopy Index your code
hub / github.com/python/cpython / deep_nested_struct

Method deep_nested_struct

Lib/test/pickletester.py:4597–4620  ·  view source on GitHub ↗
(self, create_nested,
                           minprotocol=0, compare_equal=True,
                           depth=FAST_NESTING_LIMIT * 2)

Source from the content-addressed store, hash-verified

4595 self.fast_save_enter(lambda i: {"key": i})
4596
4597 def deep_nested_struct(self, create_nested,
4598 minprotocol=0, compare_equal=True,
4599 depth=FAST_NESTING_LIMIT * 2):
4600 # gh-146059: Check that fast_save_leave() is called when
4601 # fast_save_enter() is called.
4602 if not hasattr(self, "pickler"):
4603 self.skipTest("need Pickler class")
4604
4605 data = None
4606 for i in range(depth):
4607 data = create_nested(data)
4608 protocols = range(minprotocol, pickle.HIGHEST_PROTOCOL + 1)
4609 for proto in protocols:
4610 with self.subTest(proto=proto):
4611 buf = io.BytesIO()
4612 pickler = self.pickler(buf, protocol=proto)
4613 # Enable fast mode (disables memo, enables cycle detection)
4614 pickler.fast = 1
4615 pickler.dump(data)
4616
4617 buf.seek(0)
4618 data2 = self.unpickler(buf).load()
4619 if compare_equal:
4620 self.assertEqual(data2, data)
4621
4622 def test_deep_nested_struct_tuple(self):
4623 self.deep_nested_struct(lambda data: (data,))

Calls 6

seekMethod · 0.95
skipTestMethod · 0.80
subTestMethod · 0.45
dumpMethod · 0.45
loadMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected