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

Method _test_recursive_tuple_and_dict

Lib/test/pickletester.py:2695–2719  ·  view source on GitHub ↗
(self, cls, asdict=identity, minprotocol=0)

Source from the content-addressed store, hash-verified

2693 self._test_recursive_dict(REX_seven, asdict=lambda x: x.table)
2694
2695 def _test_recursive_tuple_and_dict(self, cls, asdict=identity, minprotocol=0):
2696 # Tuple containing a dict containing the original tuple.
2697 t = (cls(),)
2698 t[0][1] = t
2699 for proto in range(minprotocol, pickle.HIGHEST_PROTOCOL + 1):
2700 s = self.dumps(t, proto)
2701 x = self.loads(s)
2702 self.assertIsInstance(x, tuple)
2703 self.assertEqual(len(x), 1)
2704 self.assertIsInstance(x[0], cls)
2705 y = asdict(x[0])
2706 self.assertEqual(list(y), [1])
2707 self.assertIs(y[1], x)
2708
2709 # Dict containing a tuple containing the original dict.
2710 t, = t
2711 for proto in range(minprotocol, pickle.HIGHEST_PROTOCOL + 1):
2712 s = self.dumps(t, proto)
2713 x = self.loads(s)
2714 self.assertIsInstance(x, cls)
2715 y = asdict(x)
2716 self.assertEqual(list(y), [1])
2717 self.assertIsInstance(y[1], tuple)
2718 self.assertEqual(len(y[1]), 1)
2719 self.assertIs(y[1][0], x)
2720
2721 def test_recursive_tuple_and_dict(self):
2722 self._test_recursive_tuple_and_dict(dict)

Calls 8

asdictFunction · 0.85
listClass · 0.85
assertIsInstanceMethod · 0.80
clsClass · 0.50
dumpsMethod · 0.45
loadsMethod · 0.45
assertEqualMethod · 0.45
assertIsMethod · 0.45

Tested by

no test coverage detected