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
def test_can_add_condition_to_engine():
    engine = RuleEngine()

    @engine.condition()
    def is_equal(a: int, b: int) -> bool:
        return a == b

    assert len(engine.conditions) == 1
    assert engine.conditions["is_equal"]["function"](1, 1)
    assert not engine.conditions["is_equal"]["function"](1, 2)
def test_can_add_action_to_engine():
    engine = RuleEngine()

    @engine.action()
    def is_equal(a: int, b: int) -> bool:
        return a == b

    assert len(engine.actions) == 1
    assert hasattr(engine.actions["is_equal"]["function"], "__call__")
    assert engine.actions["is_equal"]["function"](1, 1)
    assert not engine.actions["is_equal"]["function"](1, 2)
import pytest
from sauron_rule_engine.rule_engine import RuleEngine
from enum import Enum

engine = RuleEngine()


class Color(str, Enum):
    red = "R"
    green = "G"
    blue = "B"


@engine.condition("Primeira Condição")
def first_condition(lower_number: int = 10, greater_number: int = 20) -> bool:
    """
    Checks if first number is lower than the first
    - lower_number: Number expected to be low
    - higher_number: Number expected to be high
    """
    return lower_number < greater_number


@engine.condition("é vermelho?")
def is_red(color: Color) -> bool:
    """
    Checks if the color is red
    """
    return color == color.red

예제 #5
0
from sauron_rule_engine.rule_engine import RuleEngine
from enum import Enum

engine = RuleEngine()


@engine.condition("First Condition")
def first_condition(lower_number: int = 10, greater_number: int = 20) -> bool:
    """
    Checks if first number is lower than the first
    - lower_number: Number expected to be low
    - higher_number: Number expected to be high
    """
    return lower_number < greater_number


@engine.condition()
def second_condition():
    """
    Takes no argument and always returns True
    """
    return True


@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
예제 #6
0
from sauron_rule_engine.rule_engine import RuleEngine

engine = RuleEngine()


@engine.condition("First Condition")
def first_condition(lower_number: int = 10, greater_number: int = 20) -> bool:
    """
    Checks if first number is lower than the first
    - lower_number: Number expected to be low
    - higher_number: Number expected to be high
    """
    return lower_number < greater_number


@engine.condition()
def second_condition():
    """
    Takes no argument and always returns True
    """
    return True


@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
    """