Files
Sheerka-Old/tests/evaluators/test_PrepareEvalCommon.py
kodjo 89e1f20975 Fixed #131 : Implement ExprToConditions
Fixed #130 : ArithmeticOperatorParser
Fixed #129 : python_wrapper : create_namespace
Fixed #128 : ExpressionParser: Cannot parse func(x) infixed concept 'xxx'
2021-10-13 16:06:57 +02:00

60 lines
3.4 KiB
Python

from core.builtin_concepts_ids import BuiltinConcepts
from core.concept import Concept, ConceptParts
from evaluators.PrepareEvalCommon import PrepareEvalCommon
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
class TestPrepareEvalCommon(TestUsingMemoryBasedSheerka):
def test_i_can_update_the_current_root(self):
sheerka, context = self.init_concepts()
PrepareEvalCommon.update_context_hints(context, "prop_name", ["to_put_in_context"])
assert context.in_context("to_put_in_context")
def test_i_can_update_process_input(self):
sheerka, context = self.init_concepts()
process_input_context = context.push(BuiltinConcepts.PROCESS_INPUT, "some input", desc=f"some desc")
level1 = process_input_context.push(BuiltinConcepts.TESTING, "some stuff")
level2 = level1.push(BuiltinConcepts.TESTING, "some stuff") # another level for the fun
PrepareEvalCommon.update_context_hints(level2, "prop_name", ["to_put_in_context"])
assert not context.in_context("to_put_in_context")
assert process_input_context.in_context("to_put_in_context")
assert not level1.in_context("to_put_in_context")
assert not level2.in_context("to_put_in_context")
def test_i_can_update_process_when_evaluating_a_concept(self):
sheerka, context, foo = self.init_concepts("foo")
eval_ctx = context.push(BuiltinConcepts.EVALUATING_CONCEPT, foo, desc=f"some desc")
parsing_prop_ctx = eval_ctx.push(BuiltinConcepts.PARSE_CODE, {"concept": foo, "prop": ConceptParts.BODY})
level1_ctx = parsing_prop_ctx.push(BuiltinConcepts.TESTING, "some stuff")
level2_ctx = level1_ctx.push(BuiltinConcepts.TESTING, "some stuff") # another level for the fun
PrepareEvalCommon.update_context_hints(level2_ctx, "prop_name", ["to_put_in_context"])
assert not context.in_context("to_put_in_context")
assert not eval_ctx.in_context("to_put_in_context")
assert not parsing_prop_ctx.in_context("to_put_in_context")
assert not level1_ctx.in_context("to_put_in_context")
assert not level2_ctx.in_context("to_put_in_context")
assert foo.get_compiled_context_hints() == {ConceptParts.BODY: ["to_put_in_context"]}
def test_i_can_update_for_the_correct_variable(self):
# when source is the name of the variable,
# use this name, rather than the attribute being parsed
sheerka, context, foo = self.init_concepts(Concept("foo").def_var("var_name"))
eval_ctx = context.push(BuiltinConcepts.EVALUATING_CONCEPT, foo, desc=f"some desc")
parsing_prop_ctx = eval_ctx.push(BuiltinConcepts.PARSE_CODE, {"concept": foo, "prop": ConceptParts.BODY})
level1_ctx = parsing_prop_ctx.push(BuiltinConcepts.TESTING, "some stuff")
level2_ctx = level1_ctx.push(BuiltinConcepts.TESTING, "some stuff") # another level for the fun
PrepareEvalCommon.update_context_hints(level2_ctx, "var_name", ["to_put_in_context"])
assert not context.in_context("to_put_in_context")
assert not eval_ctx.in_context("to_put_in_context")
assert not parsing_prop_ctx.in_context("to_put_in_context")
assert not level1_ctx.in_context("to_put_in_context")
assert not level2_ctx.in_context("to_put_in_context")
assert foo.get_compiled_context_hints() == {"var_name": ["to_put_in_context"]}