Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pyflow/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Le,
Lt,
Mod,
Mul,
Ne,
Sub,
expression_from_json,
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down
24 changes: 20 additions & 4 deletions pyflow/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
24 changes: 13 additions & 11 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Loading