Added concepts with the same key handling
This commit is contained in:
@@ -9,6 +9,7 @@ from core import utils
|
||||
from core.builtin_concepts import BuiltinConcepts, ReturnValueConcept
|
||||
from core.concept import Concept, ConceptParts
|
||||
from core.sheerka import Sheerka, ExecutionContext
|
||||
from evaluators.MutipleSameSuccessEvaluator import MultipleSameSuccessEvaluator
|
||||
from parsers.DefaultParser import DefaultParser
|
||||
from parsers.PythonParser import PythonParser
|
||||
from sdp.sheerkaDataProvider import SheerkaDataProvider, SheerkaDataProviderDuplicateKeyError
|
||||
@@ -158,6 +159,44 @@ def test_i_can_get_a_known_concept_when_not_in_cache():
|
||||
assert loaded == concept
|
||||
|
||||
|
||||
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"
|
||||
|
||||
res1 = sheerka.create_new_concept(get_context(sheerka), concept1)
|
||||
res2 = sheerka.create_new_concept(get_context(sheerka), concept2)
|
||||
|
||||
assert res1.value.body.key == res2.value.body.key # same key
|
||||
|
||||
sheerka.concepts_cache = {} # reset the cache
|
||||
|
||||
from_cache = sheerka.get(concept1.key)
|
||||
assert len(from_cache) == 2
|
||||
assert from_cache[0] == concept1
|
||||
assert from_cache[1] == concept2
|
||||
|
||||
|
||||
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"
|
||||
|
||||
res1 = sheerka.create_new_concept(get_context(sheerka), concept1)
|
||||
res2 = sheerka.create_new_concept(get_context(sheerka), concept2)
|
||||
|
||||
assert res1.value.body.key == res2.value.body.key # same key
|
||||
|
||||
# sheerka.concepts_cache = {} # Do not reset the cache
|
||||
|
||||
from_cache = sheerka.get(concept1.key)
|
||||
assert len(from_cache) == 2
|
||||
assert from_cache[0] == concept1
|
||||
assert from_cache[1] == concept2
|
||||
|
||||
|
||||
def test_unknown_concept_is_return_when_the_concept_is_not_found():
|
||||
sheerka = get_sheerka()
|
||||
|
||||
@@ -538,6 +577,40 @@ def test_i_can_eval_duplicate_concepts_with_same_value():
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].value, "hello foo"
|
||||
assert res[0].who == sheerka.get_evaluator_name(MultipleSameSuccessEvaluator.NAME)
|
||||
|
||||
|
||||
def test_i_cannot_manage_duplicate_concepts_when_the_values_are_different():
|
||||
sheerka = get_sheerka()
|
||||
|
||||
sheerka.add_in_cache(Concept(name="hello a", body="'hello ' + a").set_prop("a"))
|
||||
sheerka.add_in_cache(Concept(name="hello foo", body="'hello foo'"))
|
||||
sheerka.add_in_cache(Concept(name="foo", body="'another value'"))
|
||||
|
||||
res = sheerka.eval("hello foo")
|
||||
assert len(res) == 1
|
||||
assert not res[0].status
|
||||
assert sheerka.isinstance(res[0].value, BuiltinConcepts.TOO_MANY_SUCCESS)
|
||||
|
||||
concepts = res[0].value.obj
|
||||
assert len(concepts) == 2
|
||||
sorted_values = sorted(concepts, key=lambda x: x.value)
|
||||
assert sorted_values[0].value == "hello another value"
|
||||
assert sorted_values[1].value == "hello foo"
|
||||
|
||||
|
||||
def test_i_can_manage_concepts_with_the_same_key_when_values_are_the_same():
|
||||
sheerka = get_sheerka()
|
||||
context = get_context(sheerka)
|
||||
|
||||
sheerka.create_new_concept(context, Concept(name="hello a", body="'hello ' + a").set_prop("a"))
|
||||
sheerka.create_new_concept(context, Concept(name="hello b", body="'hello ' + b").set_prop("b"))
|
||||
|
||||
res = sheerka.eval("hello 'foo'")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].value, "hello foo"
|
||||
assert res[0].who == sheerka.get_evaluator_name(MultipleSameSuccessEvaluator.NAME)
|
||||
|
||||
|
||||
def get_sheerka():
|
||||
|
||||
Reference in New Issue
Block a user