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

Method assert_class_defs_other_unpickle

Lib/test/test_crossinterp.py:601–636  ·  view source on GitHub ↗
(self, defs, mod, *, fail=False)

Source from the content-addressed store, hash-verified

599 self.assert_not_shareable(instances)
600
601 def assert_class_defs_other_unpickle(self, defs, mod, *, fail=False):
602 # Unpickle relative to a different module than the original.
603 for cls in defs.TOP_CLASSES:
604 assert not hasattr(mod, cls.__name__), (cls, getattr(mod, cls.__name__))
605
606 instances = []
607 for cls, args in defs.TOP_CLASSES.items():
608 with self.subTest(repr(cls)):
609 setattr(mod, cls.__name__, cls)
610 xid = self.get_xidata(cls)
611 inst = cls(*args)
612 instxid = self.get_xidata(inst)
613 instances.append(
614 (cls, xid, inst, instxid))
615
616 for cls, xid, inst, instxid in instances:
617 with self.subTest(repr(cls)):
618 delattr(mod, cls.__name__)
619 if fail:
620 with self.assertRaises(NotShareableError):
621 _testinternalcapi.restore_crossinterp_data(xid)
622 continue
623 got = _testinternalcapi.restore_crossinterp_data(xid)
624 self.assertIsNot(got, cls)
625 self.assertNotEqual(got, cls)
626
627 gotcls = got
628 got = _testinternalcapi.restore_crossinterp_data(instxid)
629 self.assertIsNot(got, inst)
630 self.assertIs(type(got), gotcls)
631 if cls in defs.CLASSES_WITHOUT_EQUALITY:
632 self.assertNotEqual(got, inst)
633 elif cls in defs.BUILTIN_SUBCLASSES:
634 self.assertEqual(got, inst)
635 else:
636 self.assertNotEqual(got, inst)
637
638 def assert_class_defs_not_shareable(self, defs):
639 self.assert_not_shareable(defs.TOP_CLASSES)

Calls 10

get_xidataMethod · 0.80
assertIsNotMethod · 0.80
assertNotEqualMethod · 0.80
clsClass · 0.50
itemsMethod · 0.45
subTestMethod · 0.45
appendMethod · 0.45
assertRaisesMethod · 0.45
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected