Fixed #48 : RelationalExpressionParser: Implement relational operator parser
Fixed #49 : ExpressionParser: Implement ExpressionParser Fixed #50 : Implement ReteConditionExprVisitor Fixed #51 : Implement PythonConditionExprVisitor Fixed #52 : SheerkaConceptManager: I can get and set concept property
This commit is contained in:
@@ -3,7 +3,7 @@ import pytest
|
||||
from core.builtin_concepts_ids import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.sheerka.services.SheerkaRuleManager import RuleCompiledPredicate, FormatAstNode
|
||||
from core.sheerka.services.SheerkaRuleManager import FormatAstNode, CompiledCondition
|
||||
from core.tokenizer import Tokenizer, Keywords
|
||||
from core.utils import tokens_are_matching
|
||||
from parsers.BaseCustomGrammarParser import KeywordNotFound, NameNode, SyntaxErrorNode
|
||||
@@ -80,9 +80,9 @@ class TestDefRuleParser(TestUsingMemoryBasedSheerka):
|
||||
assert len(parsed.tokens) == 2
|
||||
assert tokens_are_matching(parsed.tokens[Keywords.WHEN], Tokenizer("when True"))
|
||||
assert tokens_are_matching(parsed.tokens[Keywords.THEN], Tokenizer("then answer('that is true')"))
|
||||
assert isinstance(parsed.when, list)
|
||||
assert len(parsed.when) == 1
|
||||
assert isinstance(parsed.when[0], RuleCompiledPredicate)
|
||||
assert isinstance(parsed.python, list)
|
||||
assert len(parsed.python) == 1
|
||||
assert isinstance(parsed.python[0], CompiledCondition)
|
||||
assert sheerka.isinstance(parsed.then, BuiltinConcepts.RETURN_VALUE)
|
||||
|
||||
def test_i_can_parse_simple_format_rule_definition(self):
|
||||
@@ -100,9 +100,9 @@ class TestDefRuleParser(TestUsingMemoryBasedSheerka):
|
||||
assert len(parsed.tokens) == 2
|
||||
assert tokens_are_matching(parsed.tokens[Keywords.WHEN], Tokenizer("when True"))
|
||||
assert tokens_are_matching(parsed.tokens[Keywords.PRINT], Tokenizer("print hello world!"))
|
||||
assert isinstance(parsed.when, list)
|
||||
assert len(parsed.when) == 1
|
||||
assert isinstance(parsed.when[0], RuleCompiledPredicate)
|
||||
assert isinstance(parsed.python, list)
|
||||
assert len(parsed.python) == 1
|
||||
assert isinstance(parsed.python[0], CompiledCondition)
|
||||
assert isinstance(parsed.print, FormatAstNode)
|
||||
|
||||
def test_i_can_parse_exec_rule_with_name(self):
|
||||
@@ -121,36 +121,38 @@ class TestDefRuleParser(TestUsingMemoryBasedSheerka):
|
||||
assert len(parsed.tokens) == 2
|
||||
assert tokens_are_matching(parsed.tokens[Keywords.WHEN], Tokenizer("when True"))
|
||||
assert tokens_are_matching(parsed.tokens[Keywords.THEN], Tokenizer("then answer('that is true')"))
|
||||
assert isinstance(parsed.when, list)
|
||||
assert len(parsed.when) == 1
|
||||
assert isinstance(parsed.when[0], RuleCompiledPredicate)
|
||||
assert isinstance(parsed.python, list)
|
||||
assert len(parsed.python) == 1
|
||||
assert isinstance(parsed.python[0], CompiledCondition)
|
||||
assert sheerka.isinstance(parsed.then, BuiltinConcepts.RETURN_VALUE)
|
||||
|
||||
@pytest.mark.skip("Not ready for that")
|
||||
def test_when_is_parsed_in_the_context_of_a_question(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
text = "when foo is a bar print hello world"
|
||||
res = parser.parse(context, ParserInput(text))
|
||||
format_rule = res.body.body
|
||||
rules = format_rule.when
|
||||
rules = format_rule.python
|
||||
|
||||
assert res.status
|
||||
assert len(rules) == 1
|
||||
assert isinstance(rules[0], RuleCompiledPredicate)
|
||||
assert rules[0].predicate.body.body.get_metadata().pre == "is_question()"
|
||||
assert isinstance(rules[0], CompiledCondition)
|
||||
assert rules[0].return_value.body.body.get_metadata().pre == "is_question()"
|
||||
|
||||
@pytest.mark.skip("Not ready for that")
|
||||
def test_when_can_support_multiple_possibilities_when_question_only(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
text = "when foo is good print hello world"
|
||||
res = parser.parse(context, ParserInput(text))
|
||||
format_rule = res.body.body
|
||||
rules = format_rule.when
|
||||
rules = format_rule.python
|
||||
|
||||
assert res.status
|
||||
assert len(rules) == 2
|
||||
assert rules[0].predicate.body.body.get_metadata().name == "a is good"
|
||||
assert rules[1].predicate.body.body.get_metadata().name == "b is good"
|
||||
assert rules[0].return_value.body.body.get_metadata().name == "a is good"
|
||||
assert rules[1].return_value.body.body.get_metadata().name == "b is good"
|
||||
|
||||
@pytest.mark.parametrize("text, error", [
|
||||
("def", [KeywordNotFound(None, keywords=['rule'])]),
|
||||
@@ -175,7 +177,7 @@ class TestDefRuleParser(TestUsingMemoryBasedSheerka):
|
||||
assert not_for_me.reason == error
|
||||
|
||||
@pytest.mark.parametrize("text, expected_error", [
|
||||
("when x x print 'hello world'", BuiltinConcepts.TOO_MANY_ERRORS),
|
||||
("when x x = False print 'hello world'", BuiltinConcepts.ERROR),
|
||||
|
||||
])
|
||||
def test_i_can_detect_errors(self, text, expected_error):
|
||||
|
||||
Reference in New Issue
Block a user