Added keyword c:xxx: to express that we want the concept, not its body
This commit is contained in:
@@ -14,6 +14,10 @@ def get_context():
|
||||
return ExecutionContext("test", Event(), sheerka)
|
||||
|
||||
|
||||
def get_context_name(context):
|
||||
return context.name
|
||||
|
||||
|
||||
@pytest.mark.parametrize("ret_val, expected", [
|
||||
(ReturnValueConcept("some_name", True, ParserResultConcept(value=PythonNode("", None))), True),
|
||||
(ReturnValueConcept("some_name", True, ParserResultConcept(value="other thing")), False),
|
||||
@@ -57,32 +61,6 @@ def test_i_cannot_eval_simple_concept(concept):
|
||||
assert context.sheerka.isinstance(evaluated.value, BuiltinConcepts.NOT_FOR_ME)
|
||||
|
||||
|
||||
#
|
||||
# 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 modules with variables
|
||||
@@ -127,24 +105,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_token():
|
||||
context = get_context()
|
||||
context.sheerka.add_in_cache(Concept("foo", body="2"))
|
||||
|
||||
parsed = PythonParser().parse(context, "get_context_name(c:foo:)")
|
||||
python_evaluator = PythonEvaluator()
|
||||
python_evaluator.locals["get_context_name"] = get_context_name
|
||||
evaluated = python_evaluator.eval(context, parsed)
|
||||
|
||||
assert evaluated.status
|
||||
assert evaluated.value == "foo"
|
||||
|
||||
# sanity, to make sure that otherwise foo is resolved to '2'
|
||||
parsed = PythonParser().parse(context, "get_context_name(foo)")
|
||||
python_evaluator = PythonEvaluator()
|
||||
python_evaluator.locals["get_context_name"] = get_context_name
|
||||
evaluated = python_evaluator.eval(context, parsed)
|
||||
|
||||
assert not evaluated.status
|
||||
assert evaluated.body.body.args[0] == "'int' object has no attribute 'name'"
|
||||
|
||||
Reference in New Issue
Block a user