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_context = context.push(BuiltinConcepts.EVALUATING_CONCEPT, foo, desc=f"some desc") parsing_prop_context = eval_context.push(BuiltinConcepts.PARSING, {"prop": ConceptParts.BODY}) level1 = parsing_prop_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 not eval_context.in_context("to_put_in_context") assert not parsing_prop_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") 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_context = context.push(BuiltinConcepts.EVALUATING_CONCEPT, foo, desc=f"some desc") parsing_prop_context = eval_context.push(BuiltinConcepts.PARSING, {"prop": ConceptParts.BODY}) level1 = parsing_prop_context.push(BuiltinConcepts.TESTING, "some stuff") level2 = level1.push(BuiltinConcepts.TESTING, "some stuff") # another level for the fun PrepareEvalCommon.update_context_hints(level2, "var_name", ["to_put_in_context"]) assert not context.in_context("to_put_in_context") assert not eval_context.in_context("to_put_in_context") assert not parsing_prop_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") assert foo.get_compiled_context_hints() == {"var_name": ["to_put_in_context"]}