Refactored Caching, Refactored BnfNodeParser, Introduced Sphinx
This commit is contained in:
+47
-24
@@ -3,7 +3,7 @@ import pytest
|
||||
from core.concept import Concept, ConceptParts, DEFINITION_TYPE_DEF
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name, properties, expected", [
|
||||
@pytest.mark.parametrize("name, variables, expected", [
|
||||
("foo", [], "foo"),
|
||||
("foo(bar)", [], "foo ( bar )"),
|
||||
("foo a", ["a"], "foo __var__0"),
|
||||
@@ -20,21 +20,20 @@ from core.concept import Concept, ConceptParts, DEFINITION_TYPE_DEF
|
||||
("a b a c", ["a", "b"], "__var__0 __var__1 __var__0 c"),
|
||||
("a b a c", ["b", "a"], "__var__1 __var__0 __var__1 c"),
|
||||
])
|
||||
def test_i_can_compute_the_key(name, properties, expected):
|
||||
def test_i_can_compute_the_key(name, variables, expected):
|
||||
concept = Concept(name)
|
||||
for prop in properties:
|
||||
concept.metadata.props.append((prop, None))
|
||||
for var_name in variables:
|
||||
concept.metadata.variables.append((var_name, None))
|
||||
concept.init_key()
|
||||
|
||||
assert concept.key == expected
|
||||
|
||||
|
||||
def test_i_can_compute_the_key_when_from_definition():
|
||||
|
||||
# if definition is not defined, use the name
|
||||
concept = Concept()
|
||||
concept.metadata.name = "hello a"
|
||||
concept.metadata.props = [("a", None)]
|
||||
concept.metadata.variables = [("a", None)]
|
||||
concept.init_key()
|
||||
assert concept.key == "hello __var__0"
|
||||
|
||||
@@ -43,13 +42,13 @@ def test_i_can_compute_the_key_when_from_definition():
|
||||
concept.metadata.name = "greetings"
|
||||
concept.metadata.definition = "hello a"
|
||||
concept.metadata.definition_type = DEFINITION_TYPE_DEF
|
||||
concept.metadata.props = [("a", None)]
|
||||
concept.metadata.variables = [("a", None)]
|
||||
concept.init_key()
|
||||
assert concept.key == "hello __var__0"
|
||||
|
||||
|
||||
def test_key_does_not_use_variable_when_definition_is_set():
|
||||
concept = Concept("plus").def_prop('plus')
|
||||
concept = Concept("plus").def_var('plus')
|
||||
|
||||
concept.init_key()
|
||||
assert concept.metadata.key == "plus"
|
||||
@@ -73,7 +72,7 @@ def test_i_can_serialize():
|
||||
definition_type="def type",
|
||||
desc="this this the desc",
|
||||
id="123456"
|
||||
).def_prop("a", "10").def_prop("b", None)
|
||||
).def_var("a", "10").def_var("b", None)
|
||||
|
||||
to_dict = concept.to_dict()
|
||||
assert to_dict == {
|
||||
@@ -88,7 +87,8 @@ def test_i_can_serialize():
|
||||
'name': 'concept_name',
|
||||
'post': 'definition of the post',
|
||||
'pre': 'definition of the pre',
|
||||
'props': [('a', "10"), ('b', None)],
|
||||
'props': {},
|
||||
'variables': [('a', "10"), ('b', None)],
|
||||
'where': 'definition of the where'
|
||||
}
|
||||
|
||||
@@ -111,7 +111,8 @@ def test_i_can_deserialize():
|
||||
'name': 'concept_name',
|
||||
'post': 'definition of the post',
|
||||
'pre': 'definition of the pre',
|
||||
'props': [('a', "10"), ('b', None)],
|
||||
'props': {},
|
||||
'variables': [('a', "10"), ('b', None)],
|
||||
'where': 'definition of the where'
|
||||
}
|
||||
|
||||
@@ -130,16 +131,16 @@ def test_i_can_deserialize():
|
||||
definition_type="def type",
|
||||
desc="this this the desc",
|
||||
id="123456"
|
||||
).def_prop("a", "10").def_prop("b", None)
|
||||
).def_var("a", "10").def_var("b", None)
|
||||
|
||||
|
||||
def test_i_can_deserialize_props_coming_from_sdp():
|
||||
def test_i_can_deserialize_variables_coming_from_sdp():
|
||||
from_dict = {
|
||||
'props': [['a', "10"], ['b', None]], # JSON transform set into list
|
||||
'variables': [['a', "10"], ['b', None]], # JSON transform set into list
|
||||
}
|
||||
|
||||
concept = Concept().from_dict(from_dict)
|
||||
assert concept == Concept().def_prop("a", "10").def_prop("b", None)
|
||||
assert concept == Concept().def_var("a", "10").def_var("b", None)
|
||||
|
||||
|
||||
def test_i_can_compare_concepts():
|
||||
@@ -156,7 +157,7 @@ def test_i_can_compare_concepts():
|
||||
definition_type="def type",
|
||||
desc="this this the desc",
|
||||
id="123456"
|
||||
).def_prop("a", "10").def_prop("b", None)
|
||||
).def_var("a", "10").def_var("b", None).add_prop("prop", "prop_val")
|
||||
|
||||
concept_b = Concept(
|
||||
name="concept_name",
|
||||
@@ -171,11 +172,33 @@ def test_i_can_compare_concepts():
|
||||
definition_type="def type",
|
||||
desc="this this the desc",
|
||||
id="123456"
|
||||
).def_prop("a", "10").def_prop("b", None)
|
||||
).def_var("a", "10").def_var("b", None).add_prop("prop", "prop_val")
|
||||
|
||||
assert concept_a == concept_b
|
||||
|
||||
|
||||
def test_i_can_detect_concept_differences():
|
||||
assert Concept(name="concept_name") != Concept()
|
||||
assert Concept(is_builtin=True) != Concept()
|
||||
assert Concept(is_unique=True) != Concept()
|
||||
assert Concept(key="concept_key") != Concept()
|
||||
assert Concept(body="concept_body") != Concept()
|
||||
assert Concept(where="concept_where") != Concept()
|
||||
assert Concept(pre="concept_pre") != Concept()
|
||||
assert Concept(post="concept_post") != Concept()
|
||||
assert Concept(definition="def") != Concept()
|
||||
assert Concept(definition_type="def type") != Concept()
|
||||
assert Concept(desc="desc") != Concept()
|
||||
assert Concept(id="concept_id") != Concept()
|
||||
assert Concept().def_var("a") != Concept()
|
||||
assert Concept().add_prop("a", "b") != Concept()
|
||||
assert Concept().set_value("a", "b") != Concept()
|
||||
|
||||
concept = Concept()
|
||||
concept.compiled["foo"] = "value"
|
||||
assert concept == Concept() # compiled is not used in the comparison
|
||||
|
||||
|
||||
def test_i_can_compare_concept_with_circular_reference():
|
||||
foo = Concept("foo")
|
||||
foo.metadata.body = foo
|
||||
@@ -215,17 +238,17 @@ def test_i_can_update_from():
|
||||
definition_type="def type",
|
||||
desc="this this the desc",
|
||||
id="123456"
|
||||
).def_prop("a", "10").def_prop("b", None)
|
||||
).def_var("a", "10").def_var("b", None)
|
||||
|
||||
# make sure origin is preserved
|
||||
setattr(template, "##origin##", "digest")
|
||||
|
||||
template.values[ConceptParts.BODY] = "value in body"
|
||||
template.values[ConceptParts.WHERE] = "value in where"
|
||||
template.values[ConceptParts.PRE] = "value in pre"
|
||||
template.values[ConceptParts.POST] = "value in post"
|
||||
template.set_prop("a", 10)
|
||||
template.set_prop("b", 20)
|
||||
template.set_value(ConceptParts.BODY, "value in body")
|
||||
template.set_value(ConceptParts.WHERE, "value in where")
|
||||
template.set_value(ConceptParts.PRE, "value in pre")
|
||||
template.set_value(ConceptParts.POST, "value in post")
|
||||
template.set_value("a", 10)
|
||||
template.set_value("b", 20)
|
||||
|
||||
concept = Concept().update_from(template)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user