summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-11-25 21:38:52 (GMT)
committerGuido van Rossum <guido@python.org>2002-11-25 21:38:52 (GMT)
commitd32047f038f2a9132377246013d5c9736ef80605 (patch)
treeaf939234f3447c0e3e64c713537458726ed11a19
parent98f3373a8c1ab076c07c371ffc0e7dfd3da8a0ce (diff)
downloadcpython-d32047f038f2a9132377246013d5c9736ef80605.zip
cpython-d32047f038f2a9132377246013d5c9736ef80605.tar.gz
cpython-d32047f038f2a9132377246013d5c9736ef80605.tar.bz2
A tweaked version of Jeremy's patch #642489, to produce better error
messages about MRO conflicts. (Tweaks here: don't print the message, but compare it with an expected string.)
-rw-r--r--Lib/test/test_descr.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 56c1662..2c2a42b 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1054,6 +1054,36 @@ def consistency_with_epg():
(EditableScrollablePane, ScrollablePane, EditablePane,
Pane, ScrollingMixin, EditingMixin, object))
+def mro_disagreement():
+ if verbose: print "Testing error messages for MRO disagreement..."
+ def raises(exc, expected, callable, *args):
+ try:
+ callable(*args)
+ except exc, msg:
+ if str(msg) != expected:
+ raise TestFailed, "Message %r, expected %r" % (str(msg),
+ expected)
+ else:
+ raise TestFailed, "Expected %s" % exc
+ class A(object): pass
+ class B(A): pass
+ class C(object): pass
+ # Test some very simple errors
+ raises(TypeError, "duplicate base class A",
+ type, "X", (A, A), {})
+ raises(TypeError, "MRO conflict among bases B, A",
+ type, "X", (A, B), {})
+ raises(TypeError, "MRO conflict among bases C, B, A",
+ type, "X", (A, C, B), {})
+ # Test a slightly more complex error
+ class GridLayout(object): pass
+ class HorizontalGrid(GridLayout): pass
+ class VerticalGrid(GridLayout): pass
+ class HVGrid(HorizontalGrid, VerticalGrid): pass
+ class VHGrid(VerticalGrid, HorizontalGrid): pass
+ raises(TypeError, "MRO conflict among bases VerticalGrid, HorizontalGrid",
+ type, "ConfusedGrid", (HVGrid, VHGrid), {})
+
def objects():
if verbose: print "Testing object class..."
a = object()
@@ -3422,6 +3452,7 @@ def test_main():
metaclass()
pymods()
multi()
+ mro_disagreement()
diamond()
ex5()
monotonicity()