diff --git a/pyflow/attributes.py b/pyflow/attributes.py index 90c5c25..559ceb4 100644 --- a/pyflow/attributes.py +++ b/pyflow/attributes.py @@ -19,6 +19,7 @@ Le, Lt, Mod, + Mul, Ne, Sub, expression_from_json, @@ -428,6 +429,9 @@ def __add__(self, other): def __sub__(self, other): return Sub(self, other) + def __mul__(self, other): + return Mul(self, other) + class RepeatEnumerated(Repeat): """ @@ -460,6 +464,9 @@ def __add__(self, other): def __sub__(self, other): return Sub(self, other) + def __mul__(self, other): + return Mul(self, other) + class RepeatDateList(Repeat): """ @@ -537,6 +544,9 @@ def __add__(self, other): def __sub__(self, other): return Sub(self, other) + def __mul__(self, other): + return Mul(self, other) + class RepeatDate(Repeat): """ diff --git a/pyflow/expressions.py b/pyflow/expressions.py index 8793329..a8ee24f 100644 --- a/pyflow/expressions.py +++ b/pyflow/expressions.py @@ -265,6 +265,17 @@ def simplify(self): return self._simplify() +class BinMatOp(BinOp): + def __mul__(self, other): + return Mul(self, other) + + def __add__(self, other): + return Add(self, other) + + def __sub__(self, other): + return Sub(self, other) + + class Ne(BinOp): def __init__(self, left, right): super().__init__("ne", left, right, 1) @@ -349,26 +360,31 @@ def _simplify(self): return self -class Sub(BinOp): +class Sub(BinMatOp): def __init__(self, left, right): super().__init__("-", left, right, 2) -class Add(BinOp): +class Add(BinMatOp): def __init__(self, left, right): super().__init__("+", left, right, 2) -class Mod(BinOp): +class Mod(BinMatOp): def __init__(self, left, right): super().__init__("%", left, right, 3) -class Div(BinOp): +class Div(BinMatOp): def __init__(self, left, right): super().__init__("/", left, right, 3) +class Mul(BinMatOp): + def __init__(self, left, right): + super().__init__("*", left, right, 3) + + class Atom(Expression): _priority = 99 diff --git a/tests/test_attributes.py b/tests/test_attributes.py index 5b72ceb..594eac9 100644 --- a/tests/test_attributes.py +++ b/tests/test_attributes.py @@ -296,13 +296,15 @@ def test_string_repeat(self): t1 = pyflow.Task("t1") t1.triggers = (f1.STRING_REPEAT == "7") & (f1.STRING_REPEAT == 3) - t1.triggers |= (f1.STRING_REPEAT + 2 == 7) & (f1.STRING_REPEAT - 1 == 6) + t1.triggers |= (f1.STRING_REPEAT + 2 + 1 == 7) & ( + f1.STRING_REPEAT * 2 - 1 == 6 + ) assert ( str(t1.triggers.value) == "(((/s/f1:STRING_REPEAT eq 2)" " and (/s/f1:STRING_REPEAT eq 3))" - " or (((/s/f1:STRING_REPEAT + 2) eq 7)" - " and ((/s/f1:STRING_REPEAT - 1) eq 6)))" + " or ((((/s/f1:STRING_REPEAT + 2) + 1) eq 7)" + " and (((/s/f1:STRING_REPEAT * 2) - 1) eq 6)))" ) s.check_definition() @@ -329,15 +331,15 @@ def test_enumerated_repeat(self): t2.triggers = (f2.ENUMERATED_REPEAT == "7") & ( f2.ENUMERATED_REPEAT == 3 ) - t2.triggers |= (f2.ENUMERATED_REPEAT + 2 == 7) & ( - f2.ENUMERATED_REPEAT - 1 == 6 + t2.triggers |= (f2.ENUMERATED_REPEAT + 2 + 1 == 7) & ( + f2.ENUMERATED_REPEAT * 2 - 1 == 6 ) assert ( str(t2.triggers.value) == "(((/s/f2:ENUMERATED_REPEAT eq 7) and " "(/s/f2:ENUMERATED_REPEAT eq 3)) or " - "(((/s/f2:ENUMERATED_REPEAT + 2) eq 7) and " - "((/s/f2:ENUMERATED_REPEAT - 1) eq 6)))" + "((((/s/f2:ENUMERATED_REPEAT + 2) + 1) eq 7) and " + "(((/s/f2:ENUMERATED_REPEAT * 2) - 1) eq 6)))" ) s.check_definition() @@ -363,15 +365,15 @@ def test_integer_repeat(self): t3 = pyflow.Task("t3") t3.triggers = (f3.INTEGER_REPEAT == "7") & (f3.INTEGER_REPEAT == 3) - t3.triggers |= (f3.INTEGER_REPEAT + 2 == 7) & ( - f3.INTEGER_REPEAT - 1 == 6 + t3.triggers |= (f3.INTEGER_REPEAT + 2 + 1 == 7) & ( + f3.INTEGER_REPEAT * 2 - 1 == 6 ) assert ( str(t3.triggers.value) == "(((/s/f3:INTEGER_REPEAT eq 7) and " "(/s/f3:INTEGER_REPEAT eq 3)) or " - "(((/s/f3:INTEGER_REPEAT + 2) eq 7) and " - "((/s/f3:INTEGER_REPEAT - 1) eq 6)))" + "((((/s/f3:INTEGER_REPEAT + 2) + 1) eq 7) and " + "(((/s/f3:INTEGER_REPEAT * 2) - 1) eq 6)))" ) s.check_definition()