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

Method test_unpickler

Lib/test/test_pickle.py:526–570  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

524 0) # Write buffer is cleared after every dump().
525
526 def test_unpickler(self):
527 basesize = support.calcobjsize('2P2n3P 2P2n2i5P 2P3n8P2n3i')
528 unpickler = _pickle.Unpickler
529 P = struct.calcsize('P') # Size of memo table entry.
530 n = struct.calcsize('n') # Size of mark table entry.
531 check = self.check_sizeof
532 for encoding in 'ASCII', 'UTF-16', 'latin-1':
533 for errors in 'strict', 'replace':
534 u = unpickler(io.BytesIO(),
535 encoding=encoding, errors=errors)
536 self.assertEqual(object.__sizeof__(u), basesize)
537 check(u, basesize +
538 32 * P + # Minimal memo table size.
539 len(encoding) + 1 + len(errors) + 1)
540
541 stdsize = basesize + len('ASCII') + 1 + len('strict') + 1
542 def check_unpickler(data, memo_size, marks_size):
543 dump = pickle.dumps(data)
544 u = unpickler(io.BytesIO(dump),
545 encoding='ASCII', errors='strict')
546 u.load()
547 check(u, stdsize + memo_size * P + marks_size * n)
548
549 check_unpickler(0, 32, 0)
550 # 20 is minimal non-empty mark stack size.
551 check_unpickler([0] * 100, 32, 20)
552 # 128 is memo table size required to save references to 100 objects.
553 check_unpickler([chr(i) for i in range(100)], 128, 20)
554 def recurse(deep):
555 data = 0
556 for i in range(deep):
557 data = [data, data]
558 return data
559 check_unpickler(recurse(0), 32, 0)
560 check_unpickler(recurse(1), 32, 20)
561 check_unpickler(recurse(20), 32, 20)
562 check_unpickler(recurse(50), 64, 60)
563 if not (support.is_wasi and support.Py_DEBUG):
564 # stack depth too shallow in pydebug WASI.
565 check_unpickler(recurse(100), 128, 140)
566
567 u = unpickler(io.BytesIO(pickle.dumps('a', 0)),
568 encoding='ASCII', errors='strict')
569 u.load()
570 check(u, stdsize + 32 * P + 2 + 1)
571
572
573ALT_IMPORT_MAPPING = {

Callers

nothing calls this directly

Calls 5

checkFunction · 0.70
assertEqualMethod · 0.45
__sizeof__Method · 0.45
dumpsMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected