summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_class.py34
-rw-r--r--Lib/test/test_descr.py15
2 files changed, 48 insertions, 1 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index 92c220e..6c91deb 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -368,3 +368,37 @@ except AttributeError, x:
pass
else:
print "attribute error for I.__init__ got masked"
+
+
+# Test comparison and hash of methods
+class A:
+ def __init__(self, x):
+ self.x = x
+ def f(self):
+ pass
+ def g(self):
+ pass
+ def __eq__(self, other):
+ return self.x == other.x
+ def __hash__(self):
+ return self.x
+class B(A):
+ pass
+
+a1 = A(1)
+a2 = A(2)
+assert a1.f == a1.f
+assert a1.f != a2.f
+assert a1.f != a1.g
+assert a1.f == A(1).f
+assert hash(a1.f) == hash(a1.f)
+assert hash(a1.f) == hash(A(1).f)
+
+assert A.f != a1.f
+assert A.f != A.g
+assert B.f == A.f
+assert hash(B.f) == hash(A.f)
+
+# the following triggers a SystemError in 2.4
+a = A(hash(A.f.im_func)^(-1))
+hash(a.f)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 32796bf..ca91042 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4014,11 +4014,24 @@ def methodwrapper():
l = []
vereq(l.__add__, l.__add__)
- verify(l.__add__ != [].__add__)
+ vereq(l.__add__, [].__add__)
+ verify(l.__add__ != [5].__add__)
+ verify(l.__add__ != l.__mul__)
verify(l.__add__.__name__ == '__add__')
verify(l.__add__.__self__ is l)
verify(l.__add__.__objclass__ is list)
vereq(l.__add__.__doc__, list.__add__.__doc__)
+ try:
+ hash(l.__add__)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed("no TypeError from hash([].__add__)")
+
+ t = ()
+ t += (7,)
+ vereq(t.__add__, (7,).__add__)
+ vereq(hash(t.__add__), hash((7,).__add__))
def notimplemented():
# all binary methods should be able to return a NotImplemented