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

Method test_Struct_reinitialization

Lib/test/test_struct.py:604–634  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

602 self.assertRaises(struct.error, struct.unpack_from, '14s42', store, 0)
603
604 def test_Struct_reinitialization(self):
605 # Issue 9422: there was a memory leak when reinitializing a
606 # Struct instance. This test can be used to detect the leak
607 # when running with regrtest -L.
608 s = struct.Struct('>h')
609 msg = 'Re-initialization .* will not work'
610 with self.assertWarnsRegex(FutureWarning, msg):
611 s.__init__('>hh')
612 self.assertEqual(s.format, '>hh')
613 packed = b'\x00\x01\x00\x02'
614 self.assertEqual(s.pack(1, 2), packed)
615 self.assertEqual(s.unpack(packed), (1, 2))
616
617 s.__init__('>hh') # same format
618 self.assertEqual(s.format, '>hh')
619 self.assertEqual(s.pack(1, 2), packed)
620 self.assertEqual(s.unpack(packed), (1, 2))
621
622 with self.assertWarnsRegex(FutureWarning, msg):
623 with self.assertRaises(ValueError):
624 s.__init__('\udc00')
625 self.assertEqual(s.format, '>hh')
626 self.assertEqual(s.pack(1, 2), packed)
627 self.assertEqual(s.unpack(packed), (1, 2))
628
629 with self.assertWarnsRegex(FutureWarning, msg):
630 with self.assertRaises(struct.error):
631 s.__init__('$')
632 self.assertEqual(s.format, '>hh')
633 self.assertEqual(s.pack(1, 2), packed)
634 self.assertEqual(s.unpack(packed), (1, 2))
635
636 def check_sizeof(self, format_str, number_of_codes):
637 # The size of 'PyStructObject'

Callers

nothing calls this directly

Calls 6

assertWarnsRegexMethod · 0.80
unpackMethod · 0.80
__init__Method · 0.45
assertEqualMethod · 0.45
packMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected