def test_can_run_rules(json_rule_can_increment): engine = RuleEngine() number_to_be_incremented = 1 @engine.condition() def is_smaller_than(compared_to: int) -> bool: return number_to_be_incremented < compared_to @engine.action() def increment_number() -> None: nonlocal number_to_be_incremented number_to_be_incremented += 1 engine.run(json_rule_can_increment) assert number_to_be_incremented == 2
@engine.action("The Action") def print_the_equation(lower_number: int = 10, greater_number: int = 20) -> None: """ Prints a statement Asserting that the first number is lower than the second number - lower_number: Number expected to be low - higher_number: Number expected to be high """ print(f"{lower_number} < {greater_number}") rule = { "conditions": [{ "name": "first_condition", "args": { "lower_number": 3, "greater_number": 10 }, }], "actions": [{ "name": "print_the_equation", "args": { "lower_number": 3, "greater_number": 10 }, }], } engine.run(rule)