diff options
author | Guido van Rossum <guido@python.org> | 2001-08-12 03:38:18 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-08-12 03:38:18 (GMT) |
commit | 9d4fe4298ece1acf3401c6b4849d2cb56238d710 (patch) | |
tree | f520d8f0635674d37cd2dad8ca7d61d59ef86d1c /Lib | |
parent | 08a640397344b2cc2bf65b5f6ea2db1cc10a19de (diff) | |
download | cpython-9d4fe4298ece1acf3401c6b4849d2cb56238d710.zip cpython-9d4fe4298ece1acf3401c6b4849d2cb56238d710.tar.gz cpython-9d4fe4298ece1acf3401c6b4849d2cb56238d710.tar.bz2 |
dynamics(): add tests for dynamic *instances* (which are currently
broken). Also fix an invalid reference to C (should be S).
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_descr.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 737fce9..2e934b7 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -550,7 +550,7 @@ def dynamics(): verify(S1.__dynamic__ == 0) class S(object): pass - verify(C.__dynamic__ == 0) + verify(S.__dynamic__ == 0) class D(object): __dynamic__ = 1 verify(D.__dynamic__ == 1) @@ -581,6 +581,25 @@ def dynamics(): pass else: verify(0, "assignment to SS.foo should be illegal") + # Test dynamic instances + class C(object): + __dynamic__ = 1 + foobar = 1 + def __repr__(self): + return "<C object>" + a = C() + verify(not hasattr(a, "spam")) + verify(a.foobar == 1) + C.foobar = 2 + verify(a.foobar == 2) + C.method = lambda self: 42 + verify(a.method() == 42) + verify(repr(a) == "<C object>") + C.__repr__ = lambda self: "C()" + verify(repr(a) == "C()") + # The following test should succeed, but doesn't yet +## C.__int__ = lambda self: 100 +## verify(int(a) == 100) def errors(): if verbose: print "Testing errors..." |