Refactord Concept class to regroup all builtins properties into a ConceptMetadata class
This commit is contained in:
@@ -98,7 +98,7 @@ def test_i_can_manage_unknown_concept():
|
||||
|
||||
assert not res.status
|
||||
assert context.sheerka.isinstance(res.value, BuiltinConcepts.UNKNOWN_CONCEPT)
|
||||
assert res.value.obj == "def concept hello world"
|
||||
assert res.value.body == "def concept hello world"
|
||||
|
||||
|
||||
def test_i_can_detect_concepts_too_long():
|
||||
@@ -108,7 +108,7 @@ def test_i_can_detect_concepts_too_long():
|
||||
|
||||
assert not res.status
|
||||
assert context.sheerka.isinstance(res.value, BuiltinConcepts.CONCEPT_TOO_LONG)
|
||||
assert res.value.obj == "a very very long concept that cannot be an unique one"
|
||||
assert res.value.body == "a very very long concept that cannot be an unique one"
|
||||
|
||||
|
||||
def test_i_can_detect_concept_from_tokens():
|
||||
|
||||
@@ -25,7 +25,7 @@ def test_i_can_use_expect_one_when_too_many_success():
|
||||
res = core.builtin_helpers.expect_one(get_context(sheerka), items)
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.TOO_MANY_SUCCESS)
|
||||
assert res.value.obj == items
|
||||
assert res.value.body == items
|
||||
assert res.parents == items
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ def test_i_can_use_expect_when_only_errors_1():
|
||||
res = core.builtin_helpers.expect_one(get_context(sheerka), items)
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.TOO_MANY_ERRORS)
|
||||
assert res.value.obj == items
|
||||
assert res.value.body == items
|
||||
assert res.parents == items
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ def test_i_can_use_expect_when_only_errors_2():
|
||||
res = core.builtin_helpers.expect_one(get_context(sheerka), items)
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.TOO_MANY_ERRORS)
|
||||
assert res.value.obj == items
|
||||
assert res.value.body == items
|
||||
assert res.parents == items
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ def test_i_can_get_concept_key(name, variables, expected):
|
||||
concept.set_prop(v, None)
|
||||
|
||||
concept.init_key()
|
||||
assert concept.key == expected
|
||||
assert concept.metadata.key == expected
|
||||
|
||||
|
||||
def test_i_can_serialize():
|
||||
|
||||
+18
-18
@@ -6,7 +6,7 @@ from os import path
|
||||
import shutil
|
||||
|
||||
from core.builtin_concepts import BuiltinConcepts, ReturnValueConcept
|
||||
from core.concept import Concept
|
||||
from core.concept import Concept, PROPERTIES_TO_SERIALIZE
|
||||
from core.sheerka import Sheerka, ExecutionContext
|
||||
from evaluators.MutipleSameSuccessEvaluator import MultipleSameSuccessEvaluator
|
||||
from sdp.sheerkaDataProvider import SheerkaDataProvider
|
||||
@@ -63,13 +63,13 @@ def test_builtin_concepts_are_initialized():
|
||||
def test_builtin_concepts_can_be_updated():
|
||||
sheerka = get_sheerka(root_folder, skip_builtins_in_db=False)
|
||||
loaded_sheerka = sheerka.get(BuiltinConcepts.SHEERKA)
|
||||
loaded_sheerka.desc = "I have a description"
|
||||
loaded_sheerka.metadata.desc = "I have a description"
|
||||
sheerka.sdp.modify("Test", sheerka.CONCEPTS_ENTRY, loaded_sheerka.key, loaded_sheerka)
|
||||
|
||||
sheerka = get_sheerka(root_folder)
|
||||
loaded_sheerka = sheerka.get(BuiltinConcepts.SHEERKA)
|
||||
|
||||
assert loaded_sheerka.desc == "I have a description"
|
||||
assert loaded_sheerka.metadata.desc == "I have a description"
|
||||
|
||||
|
||||
def test_i_can_add_a_concept():
|
||||
@@ -82,8 +82,8 @@ def test_i_can_add_a_concept():
|
||||
assert sheerka.isinstance(res.value, BuiltinConcepts.NEW_CONCEPT)
|
||||
|
||||
concept_found = res.value.body
|
||||
for prop in Concept.props_to_serialize:
|
||||
assert getattr(concept_found, prop) == getattr(concept, prop)
|
||||
for prop in PROPERTIES_TO_SERIALIZE:
|
||||
assert getattr(concept_found.metadata, prop) == getattr(concept.metadata, prop)
|
||||
|
||||
assert concept_found.key == "__var__0 + __var__1"
|
||||
assert concept_found.id == "1001"
|
||||
@@ -166,7 +166,7 @@ def test_i_can_get_list_of_concept_when_same_key_when_no_cache():
|
||||
sheerka = get_sheerka()
|
||||
concept1 = get_default_concept()
|
||||
concept2 = get_default_concept()
|
||||
concept2.body = "a+b"
|
||||
concept2.metadata.body = "a+b"
|
||||
|
||||
res1 = sheerka.create_new_concept(get_context(sheerka), concept1)
|
||||
res2 = sheerka.create_new_concept(get_context(sheerka), concept2)
|
||||
@@ -185,7 +185,7 @@ def test_i_can_get_list_of_concept_when_same_key_when_cache():
|
||||
sheerka = get_sheerka()
|
||||
concept1 = get_default_concept()
|
||||
concept2 = get_default_concept()
|
||||
concept2.body = "a+b"
|
||||
concept2.metadata.body = "a+b"
|
||||
|
||||
res1 = sheerka.create_new_concept(get_context(sheerka), concept1)
|
||||
res2 = sheerka.create_new_concept(get_context(sheerka), concept2)
|
||||
@@ -239,8 +239,8 @@ def test_i_can_instantiate_a_concept():
|
||||
new = sheerka.new(concept.key, a=10, b="value")
|
||||
|
||||
assert sheerka.isinstance(new, concept)
|
||||
for prop in Concept.props_to_serialize:
|
||||
assert getattr(new, prop) == getattr(concept, prop)
|
||||
for prop in PROPERTIES_TO_SERIALIZE:
|
||||
assert getattr(new.metadata, prop) == getattr(concept.metadata, prop)
|
||||
|
||||
assert new.props["a"].value == 10
|
||||
assert new.props["b"].value == "value"
|
||||
@@ -398,8 +398,8 @@ as:
|
||||
"""
|
||||
|
||||
expected = get_default_concept()
|
||||
expected.id = "1001"
|
||||
expected.desc = None
|
||||
expected.metadata.id = "1001"
|
||||
expected.metadata.desc = None
|
||||
expected.init_key()
|
||||
|
||||
sheerka = get_sheerka()
|
||||
@@ -411,8 +411,8 @@ as:
|
||||
|
||||
concept_saved = res[0].value.body
|
||||
|
||||
for prop in Concept.props_to_serialize:
|
||||
assert getattr(concept_saved, prop) == getattr(expected, prop)
|
||||
for prop in PROPERTIES_TO_SERIALIZE:
|
||||
assert getattr(concept_saved.metadata, prop) == getattr(expected.metadata, prop)
|
||||
|
||||
assert concept_saved.key in sheerka.concepts_cache
|
||||
assert sheerka.sdp.io.exists(
|
||||
@@ -433,7 +433,7 @@ def test_i_can_eval_def_concept_part_when_one_part_is_a_ref_of_another_concept()
|
||||
|
||||
res = sheerka.eval("def concept a xx b as a plus b")
|
||||
expected = Concept(name="a xx b", body="a plus b").set_prop("a").set_prop("b").init_key()
|
||||
expected.id = "1001"
|
||||
expected.metadata.id = "1001"
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
@@ -441,8 +441,8 @@ def test_i_can_eval_def_concept_part_when_one_part_is_a_ref_of_another_concept()
|
||||
|
||||
concept_saved = res[0].value.body
|
||||
|
||||
for prop in Concept.props_to_serialize:
|
||||
assert getattr(concept_saved, prop) == getattr(expected, prop)
|
||||
for prop in PROPERTIES_TO_SERIALIZE:
|
||||
assert getattr(concept_saved.metadata, prop) == getattr(expected.metadata, prop)
|
||||
|
||||
assert concept_saved.key in sheerka.concepts_cache
|
||||
assert sheerka.sdp.io.exists(
|
||||
@@ -537,7 +537,7 @@ def test_i_cannot_manage_duplicate_concepts_when_the_values_are_different():
|
||||
assert not res[0].status
|
||||
assert sheerka.isinstance(res[0].value, BuiltinConcepts.TOO_MANY_SUCCESS)
|
||||
|
||||
concepts = res[0].value.obj
|
||||
concepts = res[0].value.body
|
||||
assert len(concepts) == 2
|
||||
sorted_values = sorted(concepts, key=lambda x: x.value)
|
||||
assert sorted_values[0].value == "hello another value"
|
||||
@@ -554,7 +554,7 @@ def test_i_can_manage_concepts_with_the_same_key_when_values_are_the_same():
|
||||
res = sheerka.eval("hello 'foo'")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].value == "hello foo"
|
||||
assert res[0].value == "hello foo"
|
||||
assert res[0].who == sheerka.get_evaluator_name(MultipleSameSuccessEvaluator.NAME)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user