summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-03-17 21:20:12 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-03-17 21:20:12 (GMT)
commit2a6053468ea318acc2b382808f858d853cf3a89a (patch)
treeef0e1205d66869e3092c4bdb17047168f2c3bb6f /Lib/test/test_descr.py
parentdf813791db32867634c86c33714995dfeb651099 (diff)
downloadcpython-2a6053468ea318acc2b382808f858d853cf3a89a.zip
cpython-2a6053468ea318acc2b382808f858d853cf3a89a.tar.gz
cpython-2a6053468ea318acc2b382808f858d853cf3a89a.tar.bz2
move SharedKeyTests to test_descr
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 71d8609..8bb7d6a 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4974,11 +4974,33 @@ class PicklingTests(unittest.TestCase):
self._assert_is_copy(obj, objcopy2)
+class SharedKeyTests(unittest.TestCase):
+
+ @support.cpython_only
+ def test_subclasses(self):
+ # Verify that subclasses can share keys (per PEP 412)
+ class A:
+ pass
+ class B(A):
+ pass
+
+ a, b = A(), B()
+ self.assertEqual(sys.getsizeof(vars(a)), sys.getsizeof(vars(b)))
+ self.assertLess(sys.getsizeof(vars(a)), sys.getsizeof({}))
+ a.x, a.y, a.z, a.w = range(4)
+ self.assertNotEqual(sys.getsizeof(vars(a)), sys.getsizeof(vars(b)))
+ a2 = A()
+ self.assertEqual(sys.getsizeof(vars(a)), sys.getsizeof(vars(a2)))
+ self.assertLess(sys.getsizeof(vars(a)), sys.getsizeof({}))
+ b.u, b.v, b.w, b.t = range(4)
+ self.assertLess(sys.getsizeof(vars(b)), sys.getsizeof({}))
+
+
def test_main():
# Run all local test cases, with PTypesLongInitTest first.
support.run_unittest(PTypesLongInitTest, OperatorsTest,
ClassPropertiesAndMethods, DictProxyTests,
- MiscTests, PicklingTests)
+ MiscTests, PicklingTests, SharedKeyTests)
if __name__ == "__main__":
test_main()