Improved PyhtonEvaluator in order to use methods that need context

This commit is contained in:
2020-05-18 22:35:59 +02:00
parent c822ff6a7f
commit 95dc147bbd
14 changed files with 187 additions and 74 deletions
+19
View File
@@ -25,6 +25,7 @@ class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
@pytest.mark.parametrize("text, expected", [
("1 + 1", 2),
("test()", "I have access to Sheerka !"),
("sheerka.test()", "I have access to Sheerka !"),
("a=10\na", 10),
])
@@ -37,6 +38,24 @@ class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
assert evaluated.status
assert evaluated.value == expected
def test_i_can_eval_using_context(self):
context = self.get_context()
parsed = PythonParser().parse(context, "test_using_context('value for param1', 10)")
evaluated = PythonEvaluator().eval(context, parsed)
assert evaluated.status
assert evaluated.value.startswith("I have access to Sheerka ! param1='value for param1', param2=10, event=")
def test_i_can_eval_using_context_when_self_is_not_sheerka(self):
sheerka, context = self.init_concepts()
parsed = PythonParser().parse(context, "create_new_concept(Concept('foo'))")
evaluated = PythonEvaluator().eval(context, parsed)
assert evaluated.status
assert sheerka.has_key("foo")
@pytest.mark.parametrize("concept", [
Concept("foo"),
Concept("foo", body="2"),