diff options
author | Guido van Rossum <guido@python.org> | 2001-01-18 15:55:59 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-01-18 15:55:59 (GMT) |
commit | 9710bd5deb67e59205c861191331697f7b61f16a (patch) | |
tree | b49ea8f7ddf9780f325fa5000111163445f6bc59 /Lib/test/test_richcmp.py | |
parent | c4a6e8b65a9c55b41c4aee2c542e5dda5ae96e57 (diff) | |
download | cpython-9710bd5deb67e59205c861191331697f7b61f16a.zip cpython-9710bd5deb67e59205c861191331697f7b61f16a.tar.gz cpython-9710bd5deb67e59205c861191331697f7b61f16a.tar.bz2 |
Add test for misbehaving rich comparisons (always returning 0) --
these fall back to __cmp__.
Diffstat (limited to 'Lib/test/test_richcmp.py')
-rw-r--r-- | Lib/test/test_richcmp.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py index 9c05e98..83cb72b 100644 --- a/Lib/test/test_richcmp.py +++ b/Lib/test/test_richcmp.py @@ -1,6 +1,6 @@ # 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() |