MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_subclasses

Method test_subclasses

Lib/test/test_descr.py:5758–5778  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5756
5757 @support.cpython_only
5758 def test_subclasses(self):
5759 # Verify that subclasses can share keys (per PEP 412)
5760 class A:
5761 pass
5762 class B(A):
5763 pass
5764
5765 #Shrink keys by repeatedly creating instances
5766 [(A(), B()) for _ in range(30)]
5767
5768 a, b = A(), B()
5769 self.assertEqual(sys.getsizeof(vars(a)), sys.getsizeof(vars(b)))
5770 self.assertLess(sys.getsizeof(vars(a)), sys.getsizeof({"a":1}))
5771 # Initial hash table can contain only one or two elements.
5772 # Set 6 attributes to cause internal resizing.
5773 a.x, a.y, a.z, a.w, a.v, a.u = range(6)
5774 self.assertNotEqual(sys.getsizeof(vars(a)), sys.getsizeof(vars(b)))
5775 a2 = A()
5776 self.assertGreater(sys.getsizeof(vars(a)), sys.getsizeof(vars(a2)))
5777 self.assertLess(sys.getsizeof(vars(a2)), sys.getsizeof({"a":1}))
5778 self.assertLess(sys.getsizeof(vars(b)), sys.getsizeof({"a":1}))
5779
5780
5781class DebugHelperMeta(type):

Callers

nothing calls this directly

Calls 7

varsFunction · 0.85
assertNotEqualMethod · 0.80
assertGreaterMethod · 0.80
AClass · 0.70
BClass · 0.70
assertEqualMethod · 0.45
assertLessMethod · 0.45

Tested by

no test coverage detected