A tweaked version of Jeremy's patch #642489, to produce better error
authorGuido van Rossum <guido@python.org>
Mon, 25 Nov 2002 21:38:52 +0000 (21:38 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 25 Nov 2002 21:38:52 +0000 (21:38 +0000)
messages about MRO conflicts.  (Tweaks here: don't print the message,
but compare it with an expected string.)

Lib/test/test_descr.py

index 56c16628dae50a75dec39df53af2b5e0a06667b7..2c2a42b0c8089ce5ec8defce65946864af16954d 100644 (file)
@@ -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()