From: Guido van Rossum Date: Thu, 18 Jan 2001 15:55:59 +0000 (+0000) Subject: Add test for misbehaving rich comparisons (always returning 0) -- X-Git-Tag: v2.1a1~159 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9710bd5deb67e59205c861191331697f7b61f16a;p=thirdparty%2FPython%2Fcpython.git Add test for misbehaving rich comparisons (always returning 0) -- these fall back to __cmp__. --- diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py index 9c05e985009b..83cb72b41b8c 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((ab) == 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()