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