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

Method validate_comparison

Lib/test/test_collections.py:754–783  ·  view source on GitHub ↗
(self, instance)

Source from the content-addressed store, hash-verified

752 self.assertNotIsSubclass(C, abc)
753
754 def validate_comparison(self, instance):
755 ops = ['lt', 'gt', 'le', 'ge', 'ne', 'or', 'and', 'xor', 'sub']
756 operators = {}
757 for op in ops:
758 name = '__' + op + '__'
759 operators[name] = getattr(operator, name)
760
761 class Other:
762 def __init__(self):
763 self.right_side = False
764 def __eq__(self, other):
765 self.right_side = True
766 return True
767 __lt__ = __eq__
768 __gt__ = __eq__
769 __le__ = __eq__
770 __ge__ = __eq__
771 __ne__ = __eq__
772 __ror__ = __eq__
773 __rand__ = __eq__
774 __rxor__ = __eq__
775 __rsub__ = __eq__
776
777 for name, op in operators.items():
778 if not hasattr(instance, name):
779 continue
780 other = Other()
781 op(instance, other)
782 self.assertTrue(other.right_side,'Right side not called for %s.%s'
783 % (type(instance), name))
784
785def _test_gen():
786 yield

Callers 2

test_SetMethod · 0.80
test_MappingMethod · 0.80

Calls 3

assertTrueMethod · 0.80
OtherClass · 0.70
itemsMethod · 0.45

Tested by

no test coverage detected