(self, defs, mod, *, fail=False)
| 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) |
no test coverage detected