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

Method test_too_large_long_binput

Lib/test/pickletester.py:1087–1106  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1085 self.assertEqual(self.loads(data(idx)), ([],)*2)
1086
1087 def test_too_large_long_binput(self):
1088 # Test that LONG_BINPUT with large id does not cause allocation of
1089 # too large memo table. The C implementation uses a dict-based memo
1090 # for sparse indices (when idx > memo_len * 2) instead of allocating
1091 # a massive array. This test verifies large sparse indices work without
1092 # causing memory exhaustion.
1093 #
1094 # The following simple pickle creates an empty list, memoizes it
1095 # using a large index, then loads it back on the stack, builds
1096 # a tuple containing 2 identical empty lists and returns it.
1097 data = lambda n: (b'(]r' + struct.pack('<I', n) +
1098 b'j' + struct.pack('<I', n) + b't.')
1099 # 0: ( MARK
1100 # 1: ] EMPTY_LIST
1101 # 2: r LONG_BINPUT 4294967295
1102 # 7: j LONG_BINGET 4294967295
1103 # 12: t TUPLE (MARK at 0)
1104 # 13: . STOP
1105 for idx in itersize(1 << 20, min(sys.maxsize, (1 << 32) - 1)):
1106 self.assertEqual(self.loads(data(idx)), ([],)*2)
1107
1108 def _test_truncated_data(self, dumped, expected_error=None):
1109 # Test that instructions to read large data without providing

Callers

nothing calls this directly

Calls 4

loadsMethod · 0.95
itersizeFunction · 0.85
packMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected