Refactored Concept class for better separation of metadata, compiled and values
This commit is contained in:
@@ -21,7 +21,7 @@ def get_context():
|
||||
return ExecutionContext("test", Event(), sheerka)
|
||||
|
||||
|
||||
def get_concept(name, where=None, pre=None, post=None, body=None, definition=None):
|
||||
def get_def_concept(name, where=None, pre=None, post=None, body=None, definition=None):
|
||||
concept = DefConceptNode([], name=NameNode(list(Tokenizer(name))))
|
||||
|
||||
if body:
|
||||
@@ -87,7 +87,7 @@ def test_i_can_match(ret_val, expected):
|
||||
|
||||
def test_that_the_source_is_correctly_set():
|
||||
context = get_context()
|
||||
def_concept_return_value = get_concept(
|
||||
def_concept_return_value = get_def_concept(
|
||||
name="hello a",
|
||||
definition=get_concept_definition("hello a", Sequence(StrMatch("hello"), StrMatch("a"))),
|
||||
where="isinstance(a, str )",
|
||||
@@ -132,21 +132,22 @@ def test_that_the_source_is_correctly_set():
|
||||
#
|
||||
# created_concept = evaluated.body.body
|
||||
#
|
||||
# assert ConceptParts.WHERE in created_concept.cached_asts
|
||||
# assert ConceptParts.PRE in created_concept.cached_asts
|
||||
# assert ConceptParts.BODY in created_concept.cached_asts
|
||||
# assert ConceptParts.POST not in created_concept.cached_asts
|
||||
# assert ConceptParts.WHERE in created_concept.compiled
|
||||
# assert ConceptParts.PRE in created_concept.compiled
|
||||
# assert ConceptParts.BODY in created_concept.compiled
|
||||
# assert ConceptParts.POST not in created_concept.compiled
|
||||
|
||||
|
||||
def test_that_the_new_concept_is_correctly_saved():
|
||||
def test_that_the_new_concept_is_correctly_saved_in_db():
|
||||
context = get_context()
|
||||
def_concept_return_value = get_concept(
|
||||
def_concept_return_value = get_def_concept(
|
||||
name="hello a",
|
||||
definition=get_concept_definition("hello a", Sequence(StrMatch("hello"), StrMatch("a"))),
|
||||
where="isinstance(a, str )",
|
||||
pre="a is not None",
|
||||
body="print('hello' + a)")
|
||||
|
||||
# sanity. Make sure that the concept does not already exist
|
||||
from_db = context.sheerka.get("hello " + VARIABLE_PREFIX + "0")
|
||||
assert context.sheerka.isinstance(from_db, BuiltinConcepts.UNKNOWN_CONCEPT)
|
||||
|
||||
@@ -161,10 +162,11 @@ def test_that_the_new_concept_is_correctly_saved():
|
||||
assert from_db.metadata.post is None
|
||||
assert from_db.metadata.body == "print('hello' + a)"
|
||||
assert from_db.metadata.definition == "hello a"
|
||||
assert len(from_db.props) == 1
|
||||
assert len(from_db.metadata.props) == 1
|
||||
assert from_db.metadata.props[0] == ("a", None)
|
||||
assert "a" in from_db.props
|
||||
|
||||
assert from_db.cached_asts == {} # ast is not saved in db
|
||||
assert from_db.compiled == {} # ast is not saved in db
|
||||
|
||||
|
||||
def test_i_can_get_props_from_python_node():
|
||||
@@ -175,7 +177,7 @@ def test_i_can_get_props_from_python_node():
|
||||
|
||||
|
||||
def test_i_can_get_props_from_another_concept():
|
||||
concept = Concept("hello").set_prop("a").set_prop("b")
|
||||
concept = Concept("hello").def_prop("a").def_prop("b")
|
||||
ret_val = ReturnValueConcept(who="some_parser",
|
||||
status=True,
|
||||
value=ParserResultConcept(value=concept))
|
||||
|
||||
Reference in New Issue
Block a user