Added first version of DebugManager. Implemented draft of the rule engine

This commit is contained in:
2020-11-20 13:41:45 +01:00
parent cd066881b4
commit 315f8ea09b
156 changed files with 8388 additions and 2852 deletions
+29 -5
View File
@@ -15,7 +15,7 @@ class TestSheerkaMemory(TestUsingMemoryBasedSheerka):
foo = Concept("foo")
sheerka.add_to_short_term_memory(None, "a", foo)
assert service.short_term_objects.copy() == {":a": foo}
assert service.short_term_objects.copy() == {'global': {'a': foo}}
assert id(sheerka.get_from_short_term_memory(None, "a")) == id(foo)
def test_i_can_add_context_short_term_memory(self):
@@ -26,23 +26,36 @@ class TestSheerkaMemory(TestUsingMemoryBasedSheerka):
sheerka.add_to_short_term_memory(context, "a", foo)
context_id = ExecutionContext.ids[context.event.get_digest()]
assert service.short_term_objects.copy() == {f"{context_id}:a": foo}
assert service.short_term_objects.copy() == {context_id: {'a': foo}}
assert id(sheerka.get_from_short_term_memory(context, "a")) == id(foo)
assert sheerka.get_from_short_term_memory(None, "a") is None
def test_i_can_add_many(self):
sheerka, context = self.init_concepts()
bag = {"a": "foo", "b": "bar", }
context_id = ExecutionContext.ids[context.event.get_digest()]
service = sheerka.services[SheerkaMemory.NAME]
sheerka.add_many_to_short_term_memory(context, bag)
assert service.short_term_objects.copy() == {context_id: bag}
def test_i_can_get_obj_from_parents(self):
sheerka, context = self.init_concepts()
service = sheerka.services[SheerkaMemory.NAME]
foo = Concept("foo")
sheerka.add_to_short_term_memory(None, "a", foo)
sheerka.add_to_short_term_memory(context, "b", foo)
with context.push(BuiltinConcepts.TESTING, None) as sub_context:
assert service.short_term_objects.copy() == {":a": foo}
assert id(sheerka.get_from_short_term_memory(sub_context, "a")) == id(foo)
assert id(sheerka.get_from_short_term_memory(context, "a")) == id(foo)
assert id(sheerka.get_from_short_term_memory(None, "a")) == id(foo)
def test_entry_are_removed_on_context_exit(self):
assert id(sheerka.get_from_short_term_memory(sub_context, "b")) == id(foo)
assert id(sheerka.get_from_short_term_memory(context, "b")) == id(foo)
assert sheerka.get_from_short_term_memory(None, "b") is None
def test_short_term_memory_entries_are_removed_on_context_exit(self):
sheerka, context = self.init_concepts()
with context.push(BuiltinConcepts.TESTING, None) as sub_context:
@@ -52,6 +65,17 @@ class TestSheerkaMemory(TestUsingMemoryBasedSheerka):
assert sheerka.get_from_short_term_memory(sub_context, "a") is None
def test_short_term_memory_entries_are_removed_on_context_exit_2(self):
# this time we test the bulk insert
sheerka, context = self.init_concepts()
with context.push(BuiltinConcepts.TESTING, None) as sub_context:
foo = Concept("foo")
sheerka.add_many_to_short_term_memory(sub_context, {"a": foo})
assert id(sheerka.get_from_short_term_memory(sub_context, "a")) == id(foo)
assert sheerka.get_from_short_term_memory(sub_context, "a") is None
def test_i_can_add_and_retrieve_from_memory(self):
sheerka, context = self.init_concepts()
service = sheerka.services[SheerkaMemory.NAME]