MCPcopy Index your code
hub / github.com/python/cpython / testHashComparisonOfMethods

Method testHashComparisonOfMethods

Lib/test/test_class.py:615–653  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

613 a >= b
614
615 def testHashComparisonOfMethods(self):
616 # Test comparison and hash of methods
617 class A:
618 def __init__(self, x):
619 self.x = x
620 def f(self):
621 pass
622 def g(self):
623 pass
624 def __eq__(self, other):
625 return True
626 def __hash__(self):
627 raise TypeError
628 class B(A):
629 pass
630
631 a1 = A(1)
632 a2 = A(1)
633 self.assertTrue(a1.f == a1.f)
634 self.assertFalse(a1.f != a1.f)
635 self.assertFalse(a1.f == a2.f)
636 self.assertTrue(a1.f != a2.f)
637 self.assertFalse(a1.f == a1.g)
638 self.assertTrue(a1.f != a1.g)
639 self.assertNotOrderable(a1.f, a1.f)
640 self.assertEqual(hash(a1.f), hash(a1.f))
641
642 self.assertFalse(A.f == a1.f)
643 self.assertTrue(A.f != a1.f)
644 self.assertFalse(A.f == A.g)
645 self.assertTrue(A.f != A.g)
646 self.assertTrue(B.f == A.f)
647 self.assertFalse(B.f != A.f)
648 self.assertNotOrderable(A.f, A.f)
649 self.assertEqual(hash(B.f), hash(A.f))
650
651 # the following triggers a SystemError in 2.4
652 a = A(hash(A.f)^(-1))
653 hash(a.f)
654
655 @cpython_only
656 def testSetattrWrapperNameIntern(self):

Callers

nothing calls this directly

Calls 5

assertNotOrderableMethod · 0.95
assertTrueMethod · 0.80
assertFalseMethod · 0.80
AClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected