Commit dc794027 authored by Guido van Rossum's avatar Guido van Rossum

Add test for misbehaving rich comparisons (always returning 0) --

these fall back to __cmp__.
parent af38d0d2
# Tests for rich comparisons
from test_support import TestFailed
from test_support import TestFailed, verify
class Number:
......@@ -167,11 +167,33 @@ def tabulate(c1=Number, c2=Number):
print
print '*' * 50
def misbehavin():
class Misb:
def __lt__(self, other): return 0
def __gt__(self, other): return 0
def __eq__(self, other): return 0
def __le__(self, other): raise TestFailed, "This shouldn't happen"
def __ge__(self, other): raise TestFailed, "This shouldn't happen"
def __ne__(self, other): raise TestFailed, "This shouldn't happen"
def __cmp__(self, other): raise RuntimeError, "expected"
a = Misb()
b = Misb()
verify((a<b) == 0)
verify((a==b) == 0)
verify((a>b) == 0)
try:
print cmp(a, b)
except RuntimeError:
pass
else:
raise TestFailed, "cmp(Misb(), Misb()) didn't raise RuntimeError"
def main():
basic()
tabulate()
tabulate(c1=int)
tabulate(c2=int)
testvector()
misbehavin()
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment