MCPcopy Index your code
hub / github.com/RustPython/RustPython / testHashComparisonOfMethods

Method testHashComparisonOfMethods

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected