calc_value: inverse_condition => reverse_condition

This commit is contained in:
Emmanuel Garette 2019-11-20 08:22:12 +01:00
parent d3e99cc9a5
commit 8fa91abefb

View file

@ -160,10 +160,10 @@ class CalcValue:
multi: bool=False, multi: bool=False,
default: Any=undefined, default: Any=undefined,
condition: Any=undefined, condition: Any=undefined,
no_condition_is_invalid: Any=False, no_condition_is_invalid: bool=False,
expected: Any=undefined, expected: Any=undefined,
condition_operator: str='AND', condition_operator: str='AND',
inverse_condition: bool=False, reverse_condition: bool=False,
allow_none: bool=False, allow_none: bool=False,
remove_duplicate_value: bool=False, remove_duplicate_value: bool=False,
join: Optional[str]=None, join: Optional[str]=None,
@ -300,7 +300,7 @@ class CalcValue:
self.condition = condition self.condition = condition
self.expected = expected self.expected = expected
self.condition_operator = condition_operator self.condition_operator = condition_operator
self.inverse_condition = inverse_condition self.reverse_condition = reverse_condition
self.kwargs = kwargs self.kwargs = kwargs
self.no_condition_is_invalid = no_condition_is_invalid self.no_condition_is_invalid = no_condition_is_invalid
value = self.get_value(default, value = self.get_value(default,
@ -386,8 +386,8 @@ class CalcValue:
calculated_expected = self.value_from_kwargs(self.expected, calculated_expected = self.value_from_kwargs(self.expected,
'expected_', 'expected_',
to_dict=True) to_dict=True)
calculated_inverse = self.value_from_kwargs(self.inverse_condition, calculated_reverse = self.value_from_kwargs(self.reverse_condition,
'inverse_condition_', 'reverse_condition_',
to_dict=True, to_dict=True,
empty_test=False) empty_test=False)
for idx, calculated_condition in calculated_conditions.items(): for idx, calculated_condition in calculated_conditions.items():
@ -398,28 +398,28 @@ class CalcValue:
current_matches = calculated_condition in calculated_expected.values() current_matches = calculated_condition in calculated_expected.values()
else: else:
current_matches = calculated_condition == calculated_expected current_matches = calculated_condition == calculated_expected
if isinstance(calculated_inverse, dict) and idx in calculated_inverse: if isinstance(calculated_reverse, dict) and idx in calculated_reverse:
inverse_condition = calculated_inverse[idx] reverse_condition = calculated_reverse[idx]
else: else:
inverse_condition = False reverse_condition = False
if is_matches is None: if is_matches is None:
is_matches = current_matches is_matches = current_matches
if self.condition_operator == 'AND': if self.condition_operator == 'AND':
is_matches = is_matches and current_matches is_matches = is_matches and current_matches
if inverse_condition: if reverse_condition:
is_matches = not is_matches is_matches = not is_matches
if not is_matches: if not is_matches:
break break
elif self.condition_operator == 'OR': elif self.condition_operator == 'OR':
is_matches = is_matches or current_matches is_matches = is_matches or current_matches
if inverse_condition: if reverse_condition:
is_matches = not is_matches is_matches = not is_matches
if is_matches: if is_matches:
break break
else: else:
raise ValueError(_('unexpected {} condition_operator in calc_value').format(self.condition_operator)) raise ValueError(_('unexpected {} condition_operator in calc_value').format(self.condition_operator))
is_matches = is_matches and not self.inverse_condition \ is_matches = is_matches and not self.reverse_condition \
or not is_matches and self.inverse_condition or not is_matches and self.reverse_condition
return is_matches return is_matches
def get_value(self, def get_value(self,
@ -470,12 +470,12 @@ class CalcValuePropertyHelp(CalcValue):
def build_arg(self, name, value): def build_arg(self, name, value):
#if isinstance(option, tuple): #if isinstance(option, tuple):
# if not inverse: # if not reverse:
# msg = _('the calculated value is {0}').format(display_value) # msg = _('the calculated value is {0}').format(display_value)
# else: # else:
# msg = _('the calculated value is not {0}').format(display_value) # msg = _('the calculated value is not {0}').format(display_value)
#else: #else:
if not self.inverse_condition: if not self.reverse_condition:
msg = _('the value of "{0}" is {1}').format(name, value) msg = _('the value of "{0}" is {1}').format(name, value)
else: else:
msg = _('the value of "{0}" is not {1}').format(name, value) msg = _('the value of "{0}" is not {1}').format(name, value)