def test_rule_chain(): rule_1 = ExampleRule(name="rule_1", param="rule_1") rule_2 = ExampleRule(name="rule_2", param="rule_2") rule_3 = ExampleRule(name="rule_3", param="rule_3") rule_4 = ExampleRule(name="rule_4", param="rule_4") rule_5 = ExampleRule(name="rule_5", param="rule_5") rule_6 = ExampleRule(name="rule_6", param="rule_6") rule_7 = ExampleRule(name="rule_7", param="rule_7") rule_1.pipe = rule_2 rule_1.preconditions = [FAILING_PRECONDITION] rule_1.children = [rule_3, rule_4, rule_7] rule_4.pipe = rule_5 rule_5.children = [rule_6] rule_5.preconditions = [PASSING_PRECONDITION] expected_chain_order = [ FAILING_PRECONDITION, rule_1, rule_2, rule_3, rule_4, PASSING_PRECONDITION, rule_5, rule_6, rule_7, ] chain = rule_1.get_rule_chain(rule_1) assert chain == expected_chain_order
def test_execution_order_no_chain(): rule_1 = ExampleRule(name="rule_1", param="rule_1") rule_1.get_rule_chain = Mock(return_value=[]) expected_execution_order = [rule_1] order = rule_1.get_execution_order() assert order == expected_execution_order assert rule_1.get_rule_chain.called is False
def test_execution_order(): rule_1 = ExampleRule(name="rule_1", param="rule_1") rule_2 = ExampleRule(name="rule_2", param="rule_2") rule_3 = ExampleRule(name="rule_3", param="rule_3") rule_4 = ExampleRule(name="rule_4", param="rule_4") rule_1.pipe = rule_2 rule_1.children = [rule_3, rule_4] rule_1.get_rule_chain = Mock(side_effect=[[rule_2], [rule_3], [rule_4]]) rule_1.preconditions = [PASSING_PRECONDITION] expected_execution_order = [ PASSING_PRECONDITION, rule_1, rule_2, rule_3, rule_4 ] order = rule_1.get_execution_order() assert order == expected_execution_order rule_1.get_rule_chain.assert_has_calls( [call(rule_2), call(rule_3), call(rule_4)])
def test_rule_chain_no_rule(): rule_1 = ExampleRule(name="rule_1", param="rule_1") chain = rule_1.get_rule_chain(rule_1) assert chain == [rule_1]