本文整理汇总了Python中operator.__le__方法的典型用法代码示例。如果您正苦于以下问题:Python operator.__le__方法的具体用法?Python operator.__le__怎么用?Python operator.__le__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.__le__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __le__ [as 别名]
def __init__(self, attribute, value=None, op=None, probability=1, **kwargs):
super(self.__class__, self).__init__(kwargs)
self.__available_operators = {"==": operator.__eq__, "<": operator.__lt__,
">": operator.__gt__, "<=": operator.__le__,
">=": operator.__ge__, "!=": operator.__ne__,
"IN": (operator.__ge__, operator.__le__)}
self.attribute = attribute
self.attribute_range = value
self.probability = probability
self.operator = op
if self.attribute_range is None:
raise ValueError("A valid attribute value must be provided")
if self.operator is not None and self.operator in self.__available_operators:
if self.operator == "IN":
if not isinstance(self.attribute_range, list) or self.attribute_range[1] < self.attribute_range[0]:
raise ValueError("A range list is required to test IN condition")
else:
if not isinstance(self.attribute_range, int):
if not isinstance(self.attribute_range, float):
raise ValueError("A numeric value is required to test the selected condition")
else:
raise ValueError("The operator provided '%s' is not valid" % operator)
示例2: __le__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __le__ [as 别名]
def __le__(self, other):
return self.x <= other
示例3: __le__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __le__ [as 别名]
def __le__(self, other):
return self.__comparator__(other, operator.__le__)
示例4: test_misbehavin
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __le__ [as 别名]
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
def __cmp__(self_, other): raise RuntimeError, "expected"
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
self.assertRaises(RuntimeError, cmp, a, b)
示例5: __le__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __le__ [as 别名]
def __le__(self, other):
return self._compare(other, operator.__le__)
示例6: assert_array_less_equal
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __le__ [as 别名]
def assert_array_less_equal(x, y, err_msg='', verbose=True):
assert_array_compare(operator.__le__, x, y, err_msg=err_msg,
verbose=verbose,
header='Arrays are not greater-ordered')
示例7: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __le__ [as 别名]
def __init__(self, attribute, value=None, op=None, triggering_status=None, probability=1, **kwargs):
super(self.__class__, self).__init__(kwargs)
self.__available_operators = {"==": operator.__eq__, "<": operator.__lt__,
">": operator.__gt__, "<=": operator.__le__,
">=": operator.__ge__, "!=": operator.__ne__,
"IN": (operator.__ge__, operator.__le__)}
self.attribute = attribute
self.trigger = triggering_status
self.attribute_range = value
self.probability = probability
self.operator = op
if self.attribute_range is None:
raise ValueError("A valid attribute value must be provided")
if self.operator is not None and self.operator in self.__available_operators:
if self.operator == "IN":
if not isinstance(self.attribute_range, list) or self.attribute_range[1] < self.attribute_range[0]:
raise ValueError("A range list is required to test IN condition")
else:
if not isinstance(self.attribute_range, int):
if not isinstance(self.attribute_range, float):
raise ValueError("A numeric value is required to test the selected condition")
else:
raise ValueError("The operator provided '%s' is not valid" % operator)
示例8: test_misbehavin
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __le__ [as 别名]
def test_misbehavin(self):
class Misb:
def __lt__(self_, other): return 0
def __gt__(self_, other): return 0
def __eq__(self_, other): return 0
def __le__(self_, other): self.fail("This shouldn't happen")
def __ge__(self_, other): self.fail("This shouldn't happen")
def __ne__(self_, other): self.fail("This shouldn't happen")
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
示例9: __le__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import __le__ [as 别名]
def __le__(self, other):
return self._operation(other, operator.__le__)