Fixed #49 : ExpressionParser: Implement ExpressionParser
This commit is contained in:
@@ -65,16 +65,28 @@ class TestReteNetwork(TestUsingMemoryBasedSheerka):
|
||||
assert len(network.pnodes) == 1
|
||||
assert network.pnodes[0].rules == [rule1, rule2]
|
||||
|
||||
def test_i_can_update_conditions_attributes_by_id_when_constraint_on__name__(self):
|
||||
def test_i_can_update_conditions_attributes_by_id_when_constraints(self):
|
||||
network = ReteNetwork()
|
||||
conditions = [Condition(V("x"), "__name__", "fact_name"),
|
||||
Condition(V("x"), "attr1", "value1"),
|
||||
Condition(V("x"), "attr2", "value1")]
|
||||
Condition(V("x"), "body", V("y")),
|
||||
Condition(V("y"), "__is_concept__", True),
|
||||
Condition(V("y"), "name", "SubConcept"),
|
||||
Condition(V("x"), "value", V("z")),
|
||||
Condition(V("z"), "status", False),
|
||||
Condition(V("z"), "body", V("zz")),
|
||||
Condition(V("zz"), "sub_value", "sub_value"),
|
||||
]
|
||||
|
||||
rule = RuleForTestingRete(AndConditions(conditions))
|
||||
network.add_rule(rule)
|
||||
|
||||
assert network.attributes_by_id == {"fact_name": ["__name__", "attr1", "attr2"]}
|
||||
assert network.attributes_by_id == {
|
||||
"fact_name": ["__name__", "attr1", "body", "value"],
|
||||
"fact_name.body": ["__is_concept__", "name"],
|
||||
"fact_name.value": ["status", "body"],
|
||||
"fact_name.value.body": ["sub_value"],
|
||||
}
|
||||
|
||||
def test_adding_obj_when_no_rule_has_no_effect(self):
|
||||
network = ReteNetwork()
|
||||
@@ -193,20 +205,11 @@ class TestReteNetwork(TestUsingMemoryBasedSheerka):
|
||||
WME("f-00000", "__name__", "__ret"),
|
||||
WME("f-00000", "status", True),
|
||||
WME("f-00000", "body", "f-00000.body"),
|
||||
WME("f-00000.body", "id", "1003"),
|
||||
WME("f-00000.body", "name", "greetings"),
|
||||
WME("f-00000.body", "key", "hello __var__0"),
|
||||
WME("f-00000.body", "a", "f-00000.body.a"),
|
||||
WME("f-00000.body", "self", ret.body),
|
||||
WME("f-00000.body.a", "id", "1002"),
|
||||
WME("f-00000.body.a", "name", "the x"),
|
||||
WME("f-00000.body.a", "key", "the __var__0"),
|
||||
WME("f-00000.body.a", "x", "f-00000.body.a.x"),
|
||||
WME("f-00000.body.a", "self", the_boy),
|
||||
WME("f-00000.body.a.x", "id", "1001"),
|
||||
WME("f-00000.body.a.x", "name", "boy"),
|
||||
WME("f-00000.body.a.x", "key", "boy"),
|
||||
WME("f-00000.body.a.x", "self", boy),
|
||||
}
|
||||
|
||||
# sanity check that the WME produced match the condition
|
||||
@@ -649,7 +652,8 @@ class TestReteNetwork(TestUsingMemoryBasedSheerka):
|
||||
assert len(rule.rete_p_nodes) > 0
|
||||
|
||||
def test_format_rule_is_not_added_to_rete_network_when_it_is_created(self):
|
||||
sheerka, context, rule = self.init_test().with_format_rules(("rule_name", "id.attr == 'value'", 'True')).unpack()
|
||||
sheerka, context, rule = self.init_test().with_format_rules(
|
||||
("rule_name", "id.attr == 'value'", 'True')).unpack()
|
||||
evaluation_service = sheerka.services[SheerkaEvaluateRules.NAME]
|
||||
rete_network = evaluation_service.network
|
||||
|
||||
|
||||
Reference in New Issue
Block a user