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

Method test_loads_recursion

Lib/test/test_marshal.py:273–290  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

271 pass
272
273 def test_loads_recursion(self):
274 def run_tests(N, check):
275 # (((...None...),),)
276 check(b')\x01' * N + b'N')
277 check(b'(\x01\x00\x00\x00' * N + b'N')
278 # [[[...None...]]]
279 check(b'[\x01\x00\x00\x00' * N + b'N')
280 # {None: {None: {None: ...None...}}}
281 check(b'{N' * N + b'N' + b'0' * N)
282 # frozenset([frozenset([frozenset([...None...])])])
283 check(b'>\x01\x00\x00\x00' * N + b'N')
284 # Check that the generated marshal data is valid and marshal.loads()
285 # works for moderately deep nesting
286 run_tests(100, marshal.loads)
287 # Very deeply nested structure shouldn't blow the stack
288 def check(s):
289 self.assertRaises(ValueError, marshal.loads, s)
290 run_tests(2**20, check)
291
292 def test_recursion_limit(self):
293 # Create a deeply nested structure.

Callers

nothing calls this directly

Calls 1

run_testsFunction · 0.85

Tested by

no test coverage detected