diff options
author | Armin Rigo <arigo@tunes.org> | 2007-04-19 14:44:48 (GMT) |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2007-04-19 14:44:48 (GMT) |
commit | c0ba52d3fd6a4d6211d5a1a4ffe96f1b96fffd74 (patch) | |
tree | 283cbfe475c55cd2010acfba4451dd6ec8678c70 /Lib/test/test_descr.py | |
parent | bd53870d899fe3492fd4b1432df3f0ad24d0e287 (diff) | |
download | cpython-c0ba52d3fd6a4d6211d5a1a4ffe96f1b96fffd74.zip cpython-c0ba52d3fd6a4d6211d5a1a4ffe96f1b96fffd74.tar.gz cpython-c0ba52d3fd6a4d6211d5a1a4ffe96f1b96fffd74.tar.bz2 |
Revert r53997 as per
http://mail.python.org/pipermail/python-dev/2007-March/071796.html .
I've kept a couple of still-valid extra tests in test_descr, but didn't
bother to sort through the new comments and refactorings added in r53997
to see if some of them could be kept. If so, they could go in a
follow-up check-in.
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r-- | Lib/test/test_descr.py | 148 |
1 files changed, 61 insertions, 87 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index eda96a6..00a1dea 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1,6 +1,6 @@ # Test enhancements related to descriptors and new-style classes -from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout, run_doctest +from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout from copy import deepcopy import warnings @@ -1466,89 +1466,65 @@ def dynamics(): verify(someclass != object) def errors(): - """Test that type can't be placed after an instance of type in bases. - - >>> class C(list, dict): - ... pass - Traceback (most recent call last): - TypeError: Error when calling the metaclass bases - multiple bases have instance lay-out conflict - - >>> class C(object, None): - ... pass - Traceback (most recent call last): - TypeError: Error when calling the metaclass bases - bases must be types - - >>> class C(type(len)): - ... pass - Traceback (most recent call last): - TypeError: Error when calling the metaclass bases - type 'builtin_function_or_method' is not an acceptable base type - - >>> class Classic: - ... def __init__(*args): pass - >>> class C(object): - ... __metaclass__ = Classic - - >>> class C(object): - ... __slots__ = 1 - Traceback (most recent call last): - TypeError: Error when calling the metaclass bases - 'int' object is not iterable - - >>> class C(object): - ... __slots__ = [1] - Traceback (most recent call last): - TypeError: Error when calling the metaclass bases - __slots__ items must be strings, not 'int' - - >>> class A(object): - ... pass - - >>> class B(A, type): - ... pass - Traceback (most recent call last): - TypeError: Error when calling the metaclass bases - metaclass conflict: type must occur in bases before other non-classic base classes - - Create two different metaclasses in order to setup an error where - there is no inheritance relationship between the metaclass of a class - and the metaclass of its bases. - - >>> class M1(type): - ... pass - >>> class M2(type): - ... pass - >>> class A1(object): - ... __metaclass__ = M1 - >>> class A2(object): - ... __metaclass__ = M2 - >>> class B(A1, A2): - ... pass - Traceback (most recent call last): - TypeError: Error when calling the metaclass bases - metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - >>> class B(A1): - ... pass - - Also check that assignment to bases is safe. - - >>> B.__bases__ = A1, A2 - Traceback (most recent call last): - TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - >>> B.__bases__ = A2, - Traceback (most recent call last): - TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - - >>> class M3(M1): - ... pass - >>> class C(object): - ... __metaclass__ = M3 - >>> B.__bases__ = C, - Traceback (most recent call last): - TypeError: assignment to __bases__ may not change metatype - """ + if verbose: print "Testing errors..." + + try: + class C(list, dict): + pass + except TypeError: + pass + else: + verify(0, "inheritance from both list and dict should be illegal") + + try: + class C(object, None): + pass + except TypeError: + pass + else: + verify(0, "inheritance from non-type should be illegal") + class Classic: + pass + + try: + class C(type(len)): + pass + except TypeError: + pass + else: + verify(0, "inheritance from CFunction should be illegal") + + try: + class C(object): + __slots__ = 1 + except TypeError: + pass + else: + verify(0, "__slots__ = 1 should be illegal") + + try: + class C(object): + __slots__ = [1] + except TypeError: + pass + else: + verify(0, "__slots__ = [1] should be illegal") + + class M1(type): + pass + class M2(type): + pass + class A1(object): + __metaclass__ = M1 + class A2(object): + __metaclass__ = M2 + try: + class B(A1, A2): + pass + except TypeError: + pass + else: + verify(0, "finding the most derived metaclass should have failed") def classmethods(): if verbose: print "Testing class methods..." @@ -4331,6 +4307,7 @@ def test_main(): slots() slotspecials() dynamics() + errors() classmethods() classmethods_in_c() staticmethods() @@ -4399,9 +4376,6 @@ def test_main(): notimplemented() test_assign_slice() - from test import test_descr - run_doctest(test_descr, verbosity=True) - if verbose: print "All OK" if __name__ == "__main__": |