Fixed #72 : Exception when get_results(id=10)

Fixed #74 : Keyword parameters are no longer recognized when a concept that redefines equality is created
Fixed #118 : RecursionError: maximum recursion depth exceeded
Fixed #119 : PreventCircularReferenceEvaluator
Fixed #121 : Plural are not updated when new elements are added
Fixed #123 : BaseCache : Values in cache can be evicted before being committed
Fixed #105 : TOO_MANY_ERROR is not the relevant error when results are filtered
This commit is contained in:
2021-09-09 10:57:01 +02:00
parent 54e5681c5a
commit 945807b375
36 changed files with 503 additions and 98 deletions
+65
View File
@@ -1,3 +1,5 @@
from core.builtin_concepts import ConceptEvalError
from core.builtin_helpers import only_successful
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
@@ -77,3 +79,66 @@ class TestSheerkaNonRegMemory2(TestUsingMemoryBasedSheerka):
rex = sheerka.new("rex")
dog = sheerka.new("dog")
assert sheerka.isa(rex, dog)
def test_fixing_maximum_recursion_depth_exceeded(self):
init = [
"def concept x and y pre is_question() as x and y",
"def concept x or y pre is_question() as x or y",
"def concept or from a or b as a or b",
"def concept and",
]
sheerka = self.init_scenario(init)
context = self.get_context(sheerka)
res = sheerka.evaluate_user_input("or or and")
res = only_successful(context, res)
assert len(res.body.body) == 3
# note that there will be only one result when the sya node parser will fix its duplicate results issue
def test_121_plural_are_not_updated_when_new_elements_are_added(self):
init = [
"def concept animal",
"def concept dog",
"def concept a x is an y as set_isa(x, y)",
"eval animals",
"global_truth(a dog is an animal)",
]
sheerka = self.init_scenario(init)
res = sheerka.evaluate_user_input("eval animals")
assert len(res) == 1
assert res[0].status
assert res[0].body == [sheerka.new("dog")]
def test_105_TOO_MANY_ERROR_is_not_the_relevant_error_when_results_are_filtered(self):
init = [
"def concept foo",
"def concept bar",
"def concept x is a y pre is_question() def_var x def_var y",
"def concept x is a y as raise NotImplementedError() def_var x def_var y",
]
sheerka = self.init_scenario(init)
res = sheerka.evaluate_user_input("eval foo is a bar")
assert len(res) == 1
assert not res[0].status
assert isinstance(res[0].body, ConceptEvalError)
def test_74_keyword_parameters_are_no_longer_recognized_when_a_concept_that_redefines_equality_is_created(self):
init = [
"def concept a=b as a=b",
]
sheerka = self.init_scenario(init)
bag = {}
def test_function(**kwargs):
nonlocal bag
bag.update(kwargs)
sheerka.add_to_short_term_memory(None, "test_function", test_function)
res = sheerka.evaluate_user_input("test_function(id=11)")
assert len(res) == 1
assert res[0].status
assert bag["id"] == 11