Refactored Concept class for better separation of metadata, compiled and values
This commit is contained in:
@@ -86,7 +86,7 @@ def test_not_interested(text, interested):
|
||||
def test_i_can_parse_composition_of_concepts():
|
||||
foo = Concept("foo")
|
||||
bar = Concept("bar")
|
||||
plus = Concept("a plus b").set_prop("a").set_prop("b")
|
||||
plus = Concept("a plus b").def_prop("a").def_prop("b")
|
||||
|
||||
context, parser, result, wrapper, return_value = execute([foo, bar, plus], [foo, " plus ", bar])
|
||||
|
||||
@@ -96,8 +96,8 @@ def test_i_can_parse_composition_of_concepts():
|
||||
assert wrapper.source == "foo plus bar"
|
||||
assert context.sheerka.isinstance(return_value, plus)
|
||||
|
||||
assert return_value.cached_asts["a"] == foo
|
||||
assert return_value.cached_asts["b"] == bar
|
||||
assert return_value.compiled["a"] == foo
|
||||
assert return_value.compiled["b"] == bar
|
||||
|
||||
# sanity check, I can evaluate the result
|
||||
evaluated = context.sheerka.evaluate_concept(context, return_value)
|
||||
@@ -107,7 +107,7 @@ def test_i_can_parse_composition_of_concepts():
|
||||
|
||||
|
||||
def test_i_can_parse_when_composition_of_source_code():
|
||||
plus = Concept("a plus b", body="a + b").set_prop("a").set_prop("b")
|
||||
plus = Concept("a plus b", body="a + b").def_prop("a").def_prop("b")
|
||||
left = PythonNode("1+1", ast.parse("1+1", mode="eval"))
|
||||
right = PythonNode("2+2", ast.parse("2+2", mode="eval"))
|
||||
context, parser, result, wrapper, return_value = execute([plus], [left, " plus ", right])
|
||||
@@ -120,8 +120,8 @@ def test_i_can_parse_when_composition_of_source_code():
|
||||
|
||||
left_parser_result = ParserResultConcept(parser=parser, source="1+1", value=left)
|
||||
right_parser_result = ParserResultConcept(parser=parser, source="2+2", value=right)
|
||||
assert return_value.cached_asts["a"] == [ReturnValueConcept(parser.name, True, left_parser_result)]
|
||||
assert return_value.cached_asts["b"] == [ReturnValueConcept(parser.name, True, right_parser_result)]
|
||||
assert return_value.compiled["a"] == [ReturnValueConcept(parser.name, True, left_parser_result)]
|
||||
assert return_value.compiled["b"] == [ReturnValueConcept(parser.name, True, right_parser_result)]
|
||||
|
||||
# sanity check, I can evaluate the result
|
||||
evaluated = context.sheerka.evaluate_concept(context, return_value)
|
||||
@@ -132,7 +132,7 @@ def test_i_can_parse_when_composition_of_source_code():
|
||||
|
||||
|
||||
def test_i_can_parse_when_mix_of_concept_and_code():
|
||||
plus = Concept("a plus b").set_prop("a").set_prop("b")
|
||||
plus = Concept("a plus b").def_prop("a").def_prop("b")
|
||||
code = PythonNode("1+1", ast.parse("1+1", mode="eval"))
|
||||
foo = Concept("foo")
|
||||
context, parser, result, wrapper, return_value = execute([plus, foo], [foo, " plus ", code])
|
||||
@@ -144,8 +144,8 @@ def test_i_can_parse_when_mix_of_concept_and_code():
|
||||
assert context.sheerka.isinstance(return_value, plus)
|
||||
|
||||
code_parser_result = ParserResultConcept(parser=parser, source="1+1", value=code)
|
||||
assert return_value.cached_asts["a"] == foo
|
||||
assert return_value.cached_asts["b"] == [ReturnValueConcept(parser.name, True, code_parser_result)]
|
||||
assert return_value.compiled["a"] == foo
|
||||
assert return_value.compiled["b"] == [ReturnValueConcept(parser.name, True, code_parser_result)]
|
||||
|
||||
# sanity check, I can evaluate the result
|
||||
evaluated = context.sheerka.evaluate_concept(context, return_value)
|
||||
@@ -157,8 +157,8 @@ def test_i_can_parse_when_mix_of_concept_and_code():
|
||||
def test_i_can_parse_when_multiple_concepts_are_recognized():
|
||||
foo = Concept("foo")
|
||||
bar = Concept("bar")
|
||||
plus_1 = Concept("a plus b", body="body1").set_prop("a").set_prop("b")
|
||||
plus_2 = Concept("a plus b", body="body2").set_prop("a").set_prop("b")
|
||||
plus_1 = Concept("a plus b", body="body1").def_prop("a").def_prop("b")
|
||||
plus_2 = Concept("a plus b", body="body2").def_prop("a").def_prop("b")
|
||||
|
||||
context, input_return_values = init([foo, bar, plus_1, plus_2], [foo, " plus ", bar])
|
||||
parser = ConceptsWithConceptsParser()
|
||||
@@ -174,8 +174,8 @@ def test_i_can_parse_when_multiple_concepts_are_recognized():
|
||||
assert res.who == wrapper.parser.name
|
||||
assert wrapper.source == "foo plus bar"
|
||||
assert context.sheerka.isinstance(return_value, plus_1)
|
||||
assert return_value.cached_asts["a"] == foo
|
||||
assert return_value.cached_asts["b"] == bar
|
||||
assert return_value.compiled["a"] == foo
|
||||
assert return_value.compiled["b"] == bar
|
||||
|
||||
res = result[1]
|
||||
wrapper = res.value
|
||||
@@ -184,8 +184,8 @@ def test_i_can_parse_when_multiple_concepts_are_recognized():
|
||||
assert res.who == wrapper.parser.name
|
||||
assert wrapper.source == "foo plus bar"
|
||||
assert context.sheerka.isinstance(return_value, plus_2)
|
||||
assert return_value.cached_asts["a"] == foo
|
||||
assert return_value.cached_asts["b"] == bar
|
||||
assert return_value.compiled["a"] == foo
|
||||
assert return_value.compiled["b"] == bar
|
||||
|
||||
|
||||
def test_i_cannot_parse_when_unknown_concept():
|
||||
|
||||
Reference in New Issue
Block a user