diff options
author | Guido van Rossum <guido@python.org> | 2002-08-13 18:26:26 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-08-13 18:26:26 (GMT) |
commit | 8b056da6c8dff3bd2ac79c88690e738c44b80a17 (patch) | |
tree | 488997efb1a4269adfcc6a906e3f2ee397ddc6b6 /Lib | |
parent | b0df6a1afa585c5f4d097aeb68e41996a9fff9d7 (diff) | |
download | cpython-8b056da6c8dff3bd2ac79c88690e738c44b80a17.zip cpython-8b056da6c8dff3bd2ac79c88690e738c44b80a17.tar.gz cpython-8b056da6c8dff3bd2ac79c88690e738c44b80a17.tar.bz2 |
Add tests for including __dict__ and/or __weakref__ in __slots__.
Add some more rigor to slotmultipleinheritance().
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_descr.py | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index bccc912..bedb9d2 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1175,6 +1175,51 @@ def slots(): new_objects = len(gc.get_objects()) vereq(orig_objects, new_objects) +def slotspecials(): + if verbose: print "Testing __dict__ and __weakref__ in __slots__..." + + class D(object): + __slots__ = ["__dict__"] + a = D() + verify(hasattr(a, "__dict__")) + verify(not hasattr(a, "__weakref__")) + a.foo = 42 + vereq(a.__dict__, {"foo": 42}) + + class W(object): + __slots__ = ["__weakref__"] + a = W() + verify(hasattr(a, "__weakref__")) + verify(not hasattr(a, "__dict__")) + try: + a.foo = 42 + except AttributeError: + pass + else: + raise TestFailed, "shouldn't be allowed to set a.foo" + + class C1(W, D): + __slots__ = [] + a = C1() + verify(hasattr(a, "__dict__")) + verify(hasattr(a, "__weakref__")) + a.foo = 42 + vereq(a.__dict__, {"foo": 42}) + + class C2(D, W): + __slots__ = [] + a = C2() + verify(hasattr(a, "__dict__")) + verify(hasattr(a, "__weakref__")) + a.foo = 42 + vereq(a.__dict__, {"foo": 42}) + + class C3(C1, C2): + __slots__ = [] + + class C4(C2, C1): + __slots__ = [] + def dynamics(): if verbose: print "Testing class attribute propagation..." class D(object): @@ -3245,7 +3290,10 @@ def slotmultipleinheritance(): pass class C(A,B) : __slots__=() - C().x=2 + vereq(C.__basicsize__, B.__basicsize__) + verify(hasattr(C, '__dict__')) + verify(hasattr(C, '__weakref__')) + C().x = 2 def testrmul(): # SF patch 592646 @@ -3304,6 +3352,7 @@ def test_main(): diamond() objects() slots() + slotspecials() dynamics() errors() classmethods() |