You must now use 'eval' to get the body of a concept
This commit is contained in:
@@ -6,12 +6,13 @@ from core.sheerka import Sheerka, ExecutionContext
|
||||
from evaluators.ConceptEvaluator import ConceptEvaluator
|
||||
from parsers.BaseParser import BaseParser
|
||||
from parsers.ExactConceptParser import ExactConceptParser
|
||||
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)
|
||||
|
||||
|
||||
def get_return_value(concept, source=None):
|
||||
@@ -55,7 +56,7 @@ def test_i_can_evaluate_concept():
|
||||
assert result.parents == [item]
|
||||
|
||||
|
||||
def test_body_is_returned_when_defined():
|
||||
def test_body_is_returned_when_defined_and_requested():
|
||||
context = get_context()
|
||||
concept = Concept(name="foo",
|
||||
body="'I have a value'",
|
||||
@@ -63,7 +64,7 @@ def test_body_is_returned_when_defined():
|
||||
pre="2",
|
||||
post="3").set_prop("a", "4").set_prop("b", "5")
|
||||
|
||||
evaluator = ConceptEvaluator()
|
||||
evaluator = ConceptEvaluator(return_body=True)
|
||||
item = get_return_value(concept)
|
||||
result = evaluator.eval(context, item)
|
||||
|
||||
@@ -73,7 +74,25 @@ def test_body_is_returned_when_defined():
|
||||
assert result.parents == [item]
|
||||
|
||||
|
||||
def test_i_cannot_eval_if_with_the_same_name_is_defined_in_the_context():
|
||||
def test_body_is_not_returned_if_not_requested():
|
||||
context = get_context()
|
||||
concept = Concept(name="foo",
|
||||
body="'I have a value'",
|
||||
where="1",
|
||||
pre="2",
|
||||
post="3").set_prop("a", "4").set_prop("b", "5")
|
||||
|
||||
evaluator = ConceptEvaluator(return_body=False) # which is the default behaviour
|
||||
item = get_return_value(concept)
|
||||
result = evaluator.eval(context, item)
|
||||
|
||||
assert result.who == evaluator.name
|
||||
assert result.status
|
||||
assert result.value == concept
|
||||
assert result.parents == [item]
|
||||
|
||||
|
||||
def test_i_can_eval_if_with_the_same_name_is_defined_in_the_context():
|
||||
# If we evaluate Concept("foo", body="a").set_prop("a", "'property_a'")
|
||||
# ConceptEvaluator will be called to resolve 'a' while we know that 'a' refers to the string 'property_a'
|
||||
|
||||
@@ -84,8 +103,8 @@ def test_i_cannot_eval_if_with_the_same_name_is_defined_in_the_context():
|
||||
item = get_return_value(concept)
|
||||
result = ConceptEvaluator().eval(context, item)
|
||||
|
||||
assert not result.status
|
||||
assert context.sheerka.isinstance(result.value, BuiltinConcepts.NOT_FOR_ME)
|
||||
assert result.status
|
||||
assert result.value == "'some_other_value'"
|
||||
|
||||
|
||||
def test_i_cannot_recognize_a_concept_if_one_of_the_prop_is_unknown():
|
||||
|
||||
Reference in New Issue
Block a user