summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-11-14 19:50:14 (GMT)
committerGuido van Rossum <guido@python.org>2002-11-14 19:50:14 (GMT)
commit9a81892100fe14f74629f5e9cefddda631c6a5ee (patch)
treea1c24ddf99cec11c7aa106e3d88349eb100f54c8 /Lib/test/test_descr.py
parent1f1213120e40e1d1cb58348ada03da27471e9f5e (diff)
downloadcpython-9a81892100fe14f74629f5e9cefddda631c6a5ee.zip
cpython-9a81892100fe14f74629f5e9cefddda631c6a5ee.tar.gz
cpython-9a81892100fe14f74629f5e9cefddda631c6a5ee.tar.bz2
Fix or disable some tests that were affected by the new C3 MRO
algorithm, and add some new tests for the C3 algorithm.
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py99
1 files changed, 79 insertions, 20 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 7573bfd..2e1f5af 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -932,27 +932,25 @@ def multi():
def all_method(self):
return "D b"
- class M2(object, D):
+ class M2(D, object):
def m2method(self):
return "M2 a"
def all_method(self):
return "M2 b"
- vereq(M2.__mro__, (M2, object, D, C))
+ vereq(M2.__mro__, (M2, D, C, object))
m = M2()
vereq(m.cmethod(), "C a")
vereq(m.dmethod(), "D a")
vereq(m.m2method(), "M2 a")
vereq(m.all_method(), "M2 b")
- class M3(M1, object, M2):
+ class M3(M1, M2, object):
def m3method(self):
return "M3 a"
def all_method(self):
return "M3 b"
- # XXX Expected this (the commented-out result):
- # vereq(M3.__mro__, (M3, M1, M2, object, D, C))
- vereq(M3.__mro__, (M3, M1, M2, D, C, object)) # XXX ?
+ vereq(M3.__mro__, (M3, M1, M2, D, C, object))
m = M3()
vereq(m.cmethod(), "C a")
vereq(m.dmethod(), "D a")
@@ -993,14 +991,69 @@ def diamond():
vereq(E().spam(), "B")
vereq(E().boo(), "C")
vereq(E.__mro__, (E, C, B, A, object))
- class F(D, E): pass
- vereq(F().spam(), "B")
- vereq(F().boo(), "B")
- vereq(F.__mro__, (F, D, E, B, C, A, object))
- class G(E, D): pass
- vereq(G().spam(), "B")
- vereq(G().boo(), "C")
- vereq(G.__mro__, (G, E, D, C, B, A, object))
+ # MRO order disagreement
+ try:
+ class F(D, E): pass
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "expected MRO order disagreement (F)"
+ try:
+ class G(E, D): pass
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "expected MRO order disagreement (G)"
+
+
+# see thread python-dev/2002-October/029035.html
+def ex5():
+ if verbose: print "Testing ex5 from C3 switch discussion..."
+ class A(object): pass
+ class B(object): pass
+ class C(object): pass
+ class X(A): pass
+ class Y(A): pass
+ class Z(X,B,Y,C): pass
+ vereq(Z.__mro__, (Z, X, B, Y, A, C, object))
+
+# see "A Monotonic Superclass Linearization for Dylan",
+# by Kim Barrett et al. (OOPSLA 1996)
+def monotonicity():
+ if verbose: print "Testing MRO monotonicity..."
+ class Boat(object): pass
+ class DayBoat(Boat): pass
+ class WheelBoat(Boat): pass
+ class EngineLess(DayBoat): pass
+ class SmallMultihull(DayBoat): pass
+ class PedalWheelBoat(EngineLess,WheelBoat): pass
+ class SmallCatamaran(SmallMultihull): pass
+ class Pedalo(PedalWheelBoat,SmallCatamaran): pass
+
+ vereq(PedalWheelBoat.__mro__,
+ (PedalWheelBoat, EngineLess, DayBoat, WheelBoat, Boat,
+ object))
+ vereq(SmallCatamaran.__mro__,
+ (SmallCatamaran, SmallMultihull, DayBoat, Boat, object))
+
+ vereq(Pedalo.__mro__,
+ (Pedalo, PedalWheelBoat, EngineLess, SmallCatamaran,
+ SmallMultihull, DayBoat, WheelBoat, Boat, object))
+
+# see "A Monotonic Superclass Linearization for Dylan",
+# by Kim Barrett et al. (OOPSLA 1996)
+def consistency_with_epg():
+ if verbose: print "Testing consistentcy with EPG..."
+ class Pane(object): pass
+ class ScrollingMixin(object): pass
+ class EditingMixin(object): pass
+ class ScrollablePane(Pane,ScrollingMixin): pass
+ class EditablePane(Pane,EditingMixin): pass
+ class EditableScrollablePane(ScrollablePane,EditablePane): pass
+
+ vereq(EditableScrollablePane.__mro__,
+ (EditableScrollablePane, ScrollablePane, EditablePane,
+ Pane, ScrollingMixin, EditingMixin, object))
def objects():
if verbose: print "Testing object class..."
@@ -1214,11 +1267,13 @@ def slotspecials():
a.foo = 42
vereq(a.__dict__, {"foo": 42})
- class C3(C1, C2):
- __slots__ = []
-
- class C4(C2, C1):
- __slots__ = []
+# MRO order disagreement
+#
+# class C3(C1, C2):
+# __slots__ = []
+#
+# class C4(C2, C1):
+# __slots__ = []
def dynamics():
if verbose: print "Testing class attribute propagation..."
@@ -1505,12 +1560,13 @@ def altmro():
vereq(D.mro(), [D, B, C, A, object])
vereq(D.__mro__, (D, B, C, A, object))
vereq(D().f(), "C")
+
class PerverseMetaType(type):
def mro(cls):
L = type.mro(cls)
L.reverse()
return L
- class X(A,B,C,D):
+ class X(D,B,C,A):
__metaclass__ = PerverseMetaType
vereq(X.__mro__, (object, A, C, B, D, X))
vereq(X().f(), "A")
@@ -3368,6 +3424,9 @@ def test_main():
pymods()
multi()
diamond()
+ ex5()
+ monotonicity()
+ consistency_with_epg()
objects()
slots()
slotspecials()