summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-01-18 23:47:15 (GMT)
committerGuido van Rossum <guido@python.org>2001-01-18 23:47:15 (GMT)
commit2312024eb734a82bd9f190d21a18f693c5815725 (patch)
treef042283f63b7701a6d10a268f913ecad8a75c50f /Lib/test
parent65e8bd7fd5af5de8e6354832d5c00e7cc9dff7ab (diff)
downloadcpython-2312024eb734a82bd9f190d21a18f693c5815725.zip
cpython-2312024eb734a82bd9f190d21a18f693c5815725.tar.gz
cpython-2312024eb734a82bd9f190d21a18f693c5815725.tar.bz2
Add test that ensures hash() of objects defining __cmp__ or __eq__ but
not __hash__ raises TypeError.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_class.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index 3bcbf18..b863152 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -1,5 +1,6 @@
"Test the functionality of Python classes implementing operators."
+from test_support import TestFailed
testmeths = [
@@ -216,3 +217,25 @@ testme = ExtraTests()
testme.spam
testme.eggs = "spam, spam, spam and ham"
del testme.cardinal
+
+
+# Test correct errors from hash() on objects with comparisons but no __hash__
+
+class C0:
+ pass
+
+hash(C0()) # This should work; the next two should raise TypeError
+
+class C1:
+ def __cmp__(self, other): return 0
+
+try: hash(C1())
+except TypeError: pass
+else: raise TestFailed, "hash(C1()) should raise an exception"
+
+class C2:
+ def __eq__(self, other): return 1
+
+try: hash(C2())
+except TypeError: pass
+else: raise TestFailed, "hash(C2()) should raise an exception"