You must now use 'eval' to get the body of a concept
This commit is contained in:
@@ -5,12 +5,13 @@ from core.sheerka import Sheerka, ExecutionContext
|
||||
from core.concept import Concept
|
||||
from evaluators.PythonEvaluator import PythonEvaluator
|
||||
from parsers.PythonParser import PythonNode, PythonParser
|
||||
from sdp.sheerkaDataProvider import Event
|
||||
|
||||
|
||||
def get_context():
|
||||
sheerka = Sheerka(skip_builtins_in_db=True)
|
||||
sheerka.initialize("mem://")
|
||||
return ExecutionContext("test", "xxx", sheerka)
|
||||
return ExecutionContext("test", Event(), sheerka)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ret_val, expected", [
|
||||
@@ -39,30 +40,62 @@ def test_i_can_eval(text, expected):
|
||||
assert evaluated.value == expected
|
||||
|
||||
|
||||
def test_i_can_eval_expression_that_references_concepts():
|
||||
@pytest.mark.parametrize("concept", [
|
||||
Concept("foo"),
|
||||
Concept("foo", body="2"),
|
||||
Concept("foo").set_prop("prop", "'a'"),
|
||||
Concept("foo", body="bar")
|
||||
])
|
||||
def test_i_cannot_eval_simple_concept(concept):
|
||||
context = get_context()
|
||||
context.sheerka.add_in_cache(Concept("foo"))
|
||||
|
||||
parsed = PythonParser().parse(context, "foo")
|
||||
evaluated = PythonEvaluator().eval(context, parsed)
|
||||
|
||||
assert evaluated.status
|
||||
assert evaluated.value == Concept("foo").init_key()
|
||||
assert not evaluated.status
|
||||
assert context.sheerka.isinstance(evaluated.value, BuiltinConcepts.NOT_FOR_ME)
|
||||
|
||||
|
||||
def test_i_can_eval_expression_that_references_concepts_with_body():
|
||||
#
|
||||
# def test_i_can_eval_expression_that_references_concepts():
|
||||
# context = get_context()
|
||||
# context.sheerka.add_in_cache(Concept("foo"))
|
||||
#
|
||||
# parsed = PythonParser().parse(context, "foo")
|
||||
# evaluated = PythonEvaluator().eval(context, parsed)
|
||||
#
|
||||
# assert evaluated.status
|
||||
# assert evaluated.value == Concept("foo").init_key()
|
||||
#
|
||||
#
|
||||
# def test_i_can_eval_expression_that_references_concepts_with_body():
|
||||
# """
|
||||
# I can test expression with variables
|
||||
# :return:
|
||||
# """
|
||||
# context = get_context()
|
||||
# context.sheerka.add_in_cache(Concept("foo", body="2"))
|
||||
#
|
||||
# parsed = PythonParser().parse(context, "foo")
|
||||
# evaluated = PythonEvaluator().eval(context, parsed)
|
||||
#
|
||||
# assert evaluated.status
|
||||
# assert evaluated.value == 2
|
||||
|
||||
def test_i_can_eval_expression_with_that_references_concepts():
|
||||
"""
|
||||
I can test expression with variables
|
||||
I can test modules with variables
|
||||
:return:
|
||||
"""
|
||||
context = get_context()
|
||||
context.sheerka.add_in_cache(Concept("foo", body="2"))
|
||||
context.sheerka.add_in_cache(Concept("foo", body=1))
|
||||
|
||||
parsed = PythonParser().parse(context, "foo")
|
||||
parsed = PythonParser().parse(context, "foo + 2")
|
||||
evaluated = PythonEvaluator().eval(context, parsed)
|
||||
|
||||
assert evaluated.status
|
||||
assert evaluated.value == 2
|
||||
assert evaluated.value == 3
|
||||
|
||||
|
||||
def test_i_can_eval_module_with_that_references_concepts():
|
||||
@@ -94,24 +127,24 @@ def test_i_can_eval_module_with_that_references_concepts_with_body():
|
||||
assert evaluated.status
|
||||
assert evaluated.value == 2
|
||||
|
||||
|
||||
def test_i_can_eval_concept_with_props():
|
||||
context = get_context()
|
||||
context.sheerka.add_in_cache(Concept("foo").set_prop("prop", "'a'"))
|
||||
|
||||
parsed = PythonParser().parse(context, "foo")
|
||||
evaluated = PythonEvaluator().eval(context, parsed)
|
||||
|
||||
assert evaluated.status
|
||||
assert evaluated.value == Concept("foo").set_prop("prop", "a").init_key() # evaluated version of foo
|
||||
|
||||
|
||||
def test_i_cannot_eval_when_body_references_unknown_concept():
|
||||
context = get_context()
|
||||
context.sheerka.add_in_cache(Concept("foo", body="bar"))
|
||||
|
||||
parsed = PythonParser().parse(context, "foo")
|
||||
evaluated = PythonEvaluator().eval(context, parsed)
|
||||
|
||||
assert not evaluated.status
|
||||
assert context.sheerka.isinstance(evaluated.value, BuiltinConcepts.ERROR)
|
||||
#
|
||||
# def test_i_can_eval_concept_with_props():
|
||||
# context = get_context()
|
||||
# context.sheerka.add_in_cache(Concept("foo").set_prop("prop", "'a'"))
|
||||
#
|
||||
# parsed = PythonParser().parse(context, "foo")
|
||||
# evaluated = PythonEvaluator().eval(context, parsed)
|
||||
#
|
||||
# assert evaluated.status
|
||||
# assert evaluated.value == Concept("foo").set_prop("prop", "a").init_key() # evaluated version of foo
|
||||
#
|
||||
#
|
||||
# def test_i_cannot_eval_when_body_references_unknown_concept():
|
||||
# context = get_context()
|
||||
# context.sheerka.add_in_cache(Concept("foo", body="bar"))
|
||||
#
|
||||
# parsed = PythonParser().parse(context, "foo")
|
||||
# evaluated = PythonEvaluator().eval(context, parsed)
|
||||
#
|
||||
# assert not evaluated.status
|
||||
# assert context.sheerka.isinstance(evaluated.value, BuiltinConcepts.ERROR)
|
||||
|
||||
Reference in New Issue
Block a user