Fixed #131 : Implement ExprToConditions

Fixed #130 : ArithmeticOperatorParser
Fixed #129 : python_wrapper : create_namespace
Fixed #128 : ExpressionParser: Cannot parse func(x) infixed concept 'xxx'
This commit is contained in:
2021-10-13 16:06:57 +02:00
parent a61a1c0d2b
commit 89e1f20975
76 changed files with 5867 additions and 3206 deletions
+9 -3
View File
@@ -7,10 +7,11 @@ from core.rule import Rule, ACTION_TYPE_EXEC
from core.sheerka.Sheerka import RECOGNIZED_BY_ID, RECOGNIZED_BY_NAME
from core.sheerka.services.SheerkaEvaluateRules import SheerkaEvaluateRules, LOW_PRIORITY_RULES, DISABLED_RULES
from core.sheerka.services.SheerkaExecute import ParserInput
from core.sheerka.services.SheerkaRuleManager import SheerkaRuleManager, CompiledCondition, PythonConditionExprVisitor
from core.sheerka.services.SheerkaRuleManager import SheerkaRuleManager, CompiledCondition
from evaluators.PythonEvaluator import PythonEvaluator
from parsers.ExpressionParser import ExpressionParser
from parsers.PythonParser import PythonParser
from sheerkapython.ExprToConditions import ExprToConditionsVisitor
from sheerkapython.python_wrapper import Expando
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
@@ -114,6 +115,7 @@ class TestSheerkaEvaluateRules(TestUsingMemoryBasedSheerka):
res = service.evaluate_rules(context, [r1, r2, r3], {}, set())
assert res == {True: [r1, r3], False: [r2]}
@pytest.mark.skip("recognize is not supported yet")
@pytest.mark.parametrize("predicate", [
"recognize(__ret.body, greetings)",
"recognize(__ret.body, c:|1001:)",
@@ -134,6 +136,7 @@ class TestSheerkaEvaluateRules(TestUsingMemoryBasedSheerka):
res = service.evaluate_rules(context, [rule], {"__ret": ret}, set())
assert res == {True: [rule]}
@pytest.mark.skip("recognize is not supported yet")
@pytest.mark.parametrize("recognized_by", [
RECOGNIZED_BY_ID,
RECOGNIZED_BY_NAME,
@@ -157,6 +160,7 @@ class TestSheerkaEvaluateRules(TestUsingMemoryBasedSheerka):
res = service.evaluate_rules(context, [rule], {"__ret": ret}, set())
assert res == {True: [rule]}
@pytest.mark.skip("recognize is not supported yet")
@pytest.mark.parametrize("recognized_by", [
RECOGNIZED_BY_ID,
RECOGNIZED_BY_NAME,
@@ -180,6 +184,7 @@ class TestSheerkaEvaluateRules(TestUsingMemoryBasedSheerka):
res = service.evaluate_rules(context, [rule], {"__ret": ret}, set())
assert res == {True: [rule]}
@pytest.mark.skip("recognize is not supported yet")
def test_i_can_evaluate_concept_rules_when_variable_is_an_expando(self):
sheerka, context, greetings, rule = self.init_test().with_concepts(
Concept("greetings", definition="hello a", definition_type=DEFINITION_TYPE_DEF).def_var("a"),
@@ -208,6 +213,7 @@ class TestSheerkaEvaluateRules(TestUsingMemoryBasedSheerka):
res = service.evaluate_rules(context, [rule], {"__ret": ret2}, set())
assert res == {True: [rule]}
@pytest.mark.skip("recognize is not supported yet")
def test_i_can_evaluate_concept_rule_with_the_same_name_when_the_second_concept_is_declared_after(self):
sheerka, context, g1, rule, g2 = self.init_test().with_concepts(
Concept("greetings", definition="hello a", definition_type=DEFINITION_TYPE_DEF).def_var("a"),
@@ -255,11 +261,11 @@ class TestSheerkaEvaluateRules(TestUsingMemoryBasedSheerka):
sheerka, context = self.init_test().unpack()
expression = "isinstance(a, int)"
parser = ExpressionParser()
parser = ExpressionParser(auto_compile=False)
ret_val = parser.parse(context, ParserInput(expression))
parsed = ret_val.body.body
visitor = PythonConditionExprVisitor(context)
visitor = ExprToConditionsVisitor(context)
conditions = visitor.get_conditions(parsed)
missing_vars = set()