Fixed RET functionnality misbehaviour
This commit is contained in:
@@ -17,7 +17,7 @@ class Obj:
|
||||
@dataclass
|
||||
class ObjWithAsBag:
|
||||
prop1: str
|
||||
prop2: str
|
||||
prop2: object
|
||||
|
||||
def as_bag(self):
|
||||
return {
|
||||
@@ -227,3 +227,7 @@ class TestSheerkaFilter(TestUsingMemoryBasedSheerka):
|
||||
res = lst | Pipe(filter_service.pipe_inspect)("second_prop")
|
||||
|
||||
assert list(res) == ["b", "d"]
|
||||
|
||||
lst = [ObjWithAsBag("a", ObjWithAsBag("b", ObjWithAsBag("c", "d")))]
|
||||
res = lst | Pipe(filter_service.pipe_inspect)("second_prop.second_prop.second_prop")
|
||||
assert list(res) == ["d"]
|
||||
|
||||
@@ -66,6 +66,7 @@ class TestAddConceptEvaluator(TestUsingMemoryBasedSheerka):
|
||||
def_concept.post = self.get_concept_part(post)
|
||||
if ret:
|
||||
def_concept.ret = self.get_concept_part(ret)
|
||||
|
||||
if bnf_def:
|
||||
def_concept.definition = bnf_def
|
||||
def_concept.definition_type = DEFINITION_TYPE_BNF
|
||||
@@ -174,6 +175,15 @@ class TestAddConceptEvaluator(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert AddConceptEvaluator.get_variables(context.sheerka, ret_val, ["a", "b"]) == ["a"]
|
||||
|
||||
def test_i_can_get_variables_when_keywords(self):
|
||||
sheerka, context = self.init_concepts()
|
||||
|
||||
def_concept = self.get_def_concept("condition pre").value.value
|
||||
name_to_use = AddConceptEvaluator.get_name_to_use(def_concept)
|
||||
concept_part = self.get_concept_part("pre")
|
||||
|
||||
assert AddConceptEvaluator.get_variables(context.sheerka, concept_part, name_to_use) == ["pre"]
|
||||
|
||||
def test_i_cannot_get_variables_from_python_node_when_name_has_only_one_token(self):
|
||||
ret_val = self.get_concept_part("isinstance(a, str)")
|
||||
context = self.get_context()
|
||||
|
||||
@@ -44,3 +44,4 @@ class TestRetEvaluator(TestUsingMemoryBasedSheerka):
|
||||
res = RetEvaluator().eval(context, ret_value)
|
||||
assert res.status
|
||||
assert sheerka.isinstance(res.body, expected)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, PROPERTIES_TO_SERIALIZE, simplec, CMV, NotInit
|
||||
from core.concept import Concept, PROPERTIES_TO_SERIALIZE, simplec, CMV, NotInit, CC
|
||||
from evaluators.MutipleSameSuccessEvaluator import MultipleSameSuccessEvaluator
|
||||
from evaluators.PythonEvaluator import PythonEvalError
|
||||
from parsers.BaseNodeParser import SyaAssociativity
|
||||
@@ -976,6 +976,28 @@ as:
|
||||
assert res[0].status
|
||||
assert sheerka.isa(sheerka.new("one"), sheerka.new("number"))
|
||||
|
||||
def test_i_can_evaluate_sya_and_ret_concepts(self):
|
||||
init = [
|
||||
"def concept one as 1",
|
||||
"def concept plus from a plus b as a + b",
|
||||
"def concept the a ret a"
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
the = sheerka.get_by_name("the a")
|
||||
|
||||
# res = sheerka.evaluate_user_input("one plus the one")
|
||||
# assert res[0].status
|
||||
# plus = res[0].body
|
||||
# assert isinstance(plus, Concept)
|
||||
# assert plus.name == "plus"
|
||||
# assert plus.compiled["a"] == sheerka.new("one")
|
||||
# assert plus.compiled["b"] == CC(the, a=sheerka.new("one"))
|
||||
|
||||
res = sheerka.evaluate_user_input("eval one plus the one")
|
||||
assert res[0].status
|
||||
assert res[0].body == 2
|
||||
|
||||
|
||||
class TestSheerkaNonRegFile(TestUsingFileBasedSheerka):
|
||||
def test_i_can_def_several_concepts(self):
|
||||
|
||||
Reference in New Issue
Block a user