merge 3.4

This commit is contained in:
Benjamin Peterson 2014-03-17 16:20:50 -05:00
commit d7483993fe
2 changed files with 25 additions and 25 deletions

View File

@ -4974,11 +4974,33 @@ class PicklingTests(unittest.TestCase):
self._assert_is_copy(obj, objcopy2) 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(): def test_main():
# Run all local test cases, with PTypesLongInitTest first. # Run all local test cases, with PTypesLongInitTest first.
support.run_unittest(PTypesLongInitTest, OperatorsTest, support.run_unittest(PTypesLongInitTest, OperatorsTest,
ClassPropertiesAndMethods, DictProxyTests, ClassPropertiesAndMethods, DictProxyTests,
MiscTests, PicklingTests) MiscTests, PicklingTests, SharedKeyTests)
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()

View File

@ -1,6 +1,6 @@
# Python test set -- part 6, built-in types # Python test set -- part 6, built-in types
from test.support import run_unittest, run_with_locale, cpython_only from test.support import run_unittest, run_with_locale
import collections import collections
import pickle import pickle
import locale import locale
@ -1170,31 +1170,9 @@ class SimpleNamespaceTests(unittest.TestCase):
self.assertEqual(ns, ns_roundtrip, pname) self.assertEqual(ns, ns_roundtrip, pname)
class SharedKeyTests(unittest.TestCase):
@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(): def test_main():
run_unittest(TypesTests, MappingProxyTests, ClassCreationTests, run_unittest(TypesTests, MappingProxyTests, ClassCreationTests,
SimpleNamespaceTests, SharedKeyTests) SimpleNamespaceTests)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()