Fixed #32 : concept groups are not correctly updated
Fixed #35 : Refactor test helper class (CNC, CC, CIO) Fixed #36 : Concept values are not used when declared with variable expression Fixed #37 : Objects in memory lose their values are restart Fixed #38 : func(a=b, c) (which is not allowed) raise an exception
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, PROPERTIES_TO_SERIALIZE, simplec, CMV, CC
|
||||
from core.concept import Concept, PROPERTIES_TO_SERIALIZE
|
||||
from core.global_symbols import NotInit
|
||||
from core.sheerka.services.SheerkaConceptManager import SheerkaConceptManager
|
||||
from evaluators.MutipleSameSuccessEvaluator import MultipleSameSuccessEvaluator
|
||||
@@ -10,6 +10,7 @@ from evaluators.PythonEvaluator import PythonEvalError
|
||||
from parsers.BnfNodeParser import Sequence, StrMatch, OrderedChoice, Optional, ConceptExpression
|
||||
from tests.TestUsingFileBasedSheerka import TestUsingFileBasedSheerka
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
from tests.parsers.parsers_utils import CMV, CC, compare_with_test_object, CB
|
||||
|
||||
|
||||
class TestSheerkaNonRegMemory(TestUsingMemoryBasedSheerka):
|
||||
@@ -40,7 +41,7 @@ class TestSheerkaNonRegMemory(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# sanity check
|
||||
evaluated = sheerka.evaluate_concept(self.get_context(eval_body=True), res[0].value)
|
||||
assert evaluated == simplec("one", 1)
|
||||
compare_with_test_object(evaluated, CB("one", 1))
|
||||
|
||||
def test_i_can_recognize_concept_with_concept_body(self):
|
||||
sheerka, context, concept_one, concept_un = self.init_concepts("one", Concept(name="un", body="one"))
|
||||
@@ -53,7 +54,7 @@ class TestSheerkaNonRegMemory(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# sanity check
|
||||
evaluated = sheerka.evaluate_concept(self.get_context(eval_body=True), return_value)
|
||||
assert evaluated == simplec("un", simplec("one", NotInit))
|
||||
compare_with_test_object(evaluated, CB("un", CB("one", NotInit)))
|
||||
|
||||
def test_i_can_recognize_concept_with_no_body(self):
|
||||
sheerka = self.get_sheerka()
|
||||
@@ -212,7 +213,7 @@ as:
|
||||
evaluated = sheerka.evaluate_concept(self.get_context(eval_body=True), res[0].value)
|
||||
assert evaluated.body == "hello foo"
|
||||
assert evaluated.get_metadata().is_evaluated
|
||||
assert evaluated.get_value("a") == simplec("foo", "foo")
|
||||
compare_with_test_object(evaluated.get_value("a"), CB("foo", "foo"))
|
||||
assert evaluated.get_value("a").get_metadata().is_evaluated
|
||||
|
||||
def test_i_can_recognize_duplicate_concepts_with_same_value(self):
|
||||
@@ -889,7 +890,7 @@ as:
|
||||
expression = "c:one: < c:two:"
|
||||
res = sheerka.evaluate_user_input(expression)
|
||||
assert res[0].status
|
||||
assert res[0].body == CMV(is_less_than, a="c:one:", b="c:two:")
|
||||
compare_with_test_object(res[0].body, CMV(is_less_than, a="c:one:", b="c:two:"))
|
||||
assert res[0].body.a == NotInit # concept is not evaluated
|
||||
assert res[0].body.b == NotInit # concept is not evaluated
|
||||
|
||||
@@ -985,7 +986,7 @@ as:
|
||||
assert isinstance(plus, Concept)
|
||||
assert plus.name == "plus"
|
||||
assert plus.get_compiled()["a"] == sheerka.new("one")
|
||||
assert plus.get_compiled()["b"] == CC(the, a=sheerka.new("one"))
|
||||
compare_with_test_object(plus.get_compiled()["b"], CC(the, a=sheerka.new("one")))
|
||||
|
||||
res = sheerka.evaluate_user_input("eval one plus the one")
|
||||
assert res[0].status
|
||||
@@ -1249,6 +1250,55 @@ as:
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].body, "binary")
|
||||
|
||||
def test_parsing_expression_are_dynamic(self):
|
||||
init = [
|
||||
"def concept two",
|
||||
"def concept number",
|
||||
"def concept nb times from bnf number 'times'",
|
||||
"set_isa(two, number)",
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
|
||||
res = sheerka.evaluate_user_input("two times")
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].body, "nb times")
|
||||
|
||||
def test_i_can_evaluate_when_body_is_a_function_that_references_inner_variables(self):
|
||||
init = [
|
||||
"def concept two as 2",
|
||||
"def concept number",
|
||||
"set_isa(two, number)",
|
||||
"def concept cars",
|
||||
"def concept quantify x from bnf number x as set_attr(x, 'qty', number) ret x"
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
|
||||
res = sheerka.evaluate_user_input("eval two cars")
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
|
||||
assert sheerka.objvalue(res[0].body.get_value("qty")) == 2
|
||||
|
||||
def test_i_can_evaluate_when_body_is_a_function_that_references_inner_variables_using_alias(self):
|
||||
init = [
|
||||
"def concept two as 2",
|
||||
"def concept number",
|
||||
"set_isa(two, number)",
|
||||
"def concept cars",
|
||||
"def concept quantify x from bnf number=n1 x as set_attr(x, 'qty', n1) ret x"
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
|
||||
res = sheerka.evaluate_user_input("eval two cars")
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
|
||||
assert sheerka.objvalue(res[0].body.get_value("qty")) == 2
|
||||
|
||||
|
||||
class TestSheerkaNonRegFile(TestUsingFileBasedSheerka):
|
||||
def test_i_can_def_several_concepts(self):
|
||||
|
||||
Reference in New Issue
Block a user