I can define variables

This commit is contained in:
2020-06-10 07:42:09 +02:00
parent af3a3ffe92
commit 9eae784581
3 changed files with 22 additions and 9 deletions
+14 -2
View File
@@ -121,7 +121,7 @@ class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
parsed = PythonParser().parse(context, ParserInput("get_concept_name(c:foo:)"))
python_evaluator = PythonEvaluator()
python_evaluator.locals["get_concept_name"] = get_concept_name
python_evaluator.globals["get_concept_name"] = get_concept_name
evaluated = python_evaluator.eval(context, parsed)
assert evaluated.status
@@ -130,7 +130,7 @@ class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
# sanity, does not work otherwise
parsed = PythonParser().parse(context, ParserInput("get_concept_name(foo)"))
python_evaluator = PythonEvaluator()
python_evaluator.locals["get_concept_name"] = get_concept_name
python_evaluator.globals["get_concept_name"] = get_concept_name
evaluated = python_evaluator.eval(context, parsed)
assert not evaluated.status
@@ -150,6 +150,18 @@ class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
assert evaluated.status
assert sheerka.get_concepts_weights(BuiltinConcepts.PRECEDENCE) == {'1001': 1, '1002': 2}
def test_i_can_define_variables(self):
sheerka, context = self.init_concepts()
parsed = PythonParser().parse(context, ParserInput("a=10"))
python_evaluator = PythonEvaluator()
python_evaluator.eval(context, parsed)
parsed = PythonParser().parse(context, ParserInput("a"))
evaluated = python_evaluator.eval(context, parsed)
assert evaluated.status
assert evaluated.body == 10
# @pytest.mark.parametrize("text, concept_key, concept_id, use_concept", [
# ("__C__key__C__", "key", None, False),