Fixed memory() and RET usage
This commit is contained in:
@@ -8,6 +8,7 @@ from core.tokenizer import Tokenizer
|
||||
from evaluators.PythonEvaluator import PythonEvaluator, PythonEvalError
|
||||
from parsers.BaseNodeParser import SourceCodeNode, SourceCodeWithConceptNode
|
||||
from parsers.PythonParser import PythonNode, PythonParser
|
||||
from parsers.PythonWithConceptsParser import PythonWithConceptsParser
|
||||
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
|
||||
@@ -17,6 +18,15 @@ def get_concept_name(concept):
|
||||
|
||||
|
||||
def get_source_code_node(source_code, concepts=None):
|
||||
if concepts:
|
||||
for concept_name, concept in sorted(concepts.items(), key=lambda kv: len(kv[0]), reverse=True):
|
||||
identifier = "__C__" + PythonWithConceptsParser.sanitize(concept.name)
|
||||
if concept.id:
|
||||
identifier += "__" + concept.id
|
||||
identifier += "__C__"
|
||||
source_code = source_code.replace(concept_name, identifier)
|
||||
concepts[identifier] = concept
|
||||
|
||||
if source_code:
|
||||
python_node = PythonNode(source_code, ast.parse(source_code, f"<source>", 'eval'))
|
||||
else:
|
||||
@@ -32,6 +42,11 @@ def get_source_code_node(source_code, concepts=None):
|
||||
return scwcn
|
||||
|
||||
|
||||
def get_ret_val_from_source_code(context, source_code, concepts):
|
||||
parsed = get_source_code_node(source_code, concepts)
|
||||
return context.sheerka.ret("parsers.??", True, ParserResultConcept(value=parsed))
|
||||
|
||||
|
||||
class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
|
||||
|
||||
@pytest.mark.parametrize("ret_val, expected", [
|
||||
@@ -289,3 +304,14 @@ class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert evaluated.status
|
||||
assert evaluated.value == 11
|
||||
|
||||
def test_i_can_eval_concept_with_ret(self):
|
||||
sheerka, context, one, the = self.init_concepts("one", Concept("the a", ret="a").def_var("a"))
|
||||
ret_val = get_ret_val_from_source_code(context, "test_using_context(one, the one)", {
|
||||
"the one": self.get_concept_instance(sheerka, the, a="one"),
|
||||
"one": self.get_concept_instance(sheerka, "one")
|
||||
})
|
||||
|
||||
evaluated = PythonEvaluator().eval(context, ret_val)
|
||||
assert evaluated.status
|
||||
assert evaluated.value.startswith("I have access to Sheerka ! param1=(1001)one, param2=(1001)one, event=")
|
||||
|
||||
Reference in New Issue
Block a user