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

Method validate_comparison

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

Source from the content-addressed store, hash-verified

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

Callers 2

test_SetMethod · 0.80
test_MappingMethod · 0.80

Calls 5

getattrFunction · 0.85
hasattrFunction · 0.85
assertTrueMethod · 0.80
OtherClass · 0.70
itemsMethod · 0.45

Tested by

no test coverage detected