Fixed #3: Added sheerka.resolve_rule()

Fixed #5: Refactored SheerkaComparisonManager
Fixed #6: Sya parser no longer works after restart
This commit is contained in:
2021-01-15 07:11:04 +01:00
parent e26c83a825
commit 821dbed189
44 changed files with 1617 additions and 1068 deletions
+68 -8
View File
@@ -1,12 +1,13 @@
import types
import pytest
from core.builtin_concepts import BuiltinConcepts
from core.sheerka.ExecutionContext import ExecutionContext
from core.sheerka.SheerkaOntologyManager import SheerkaOntologyManager
from core.sheerka.services.SheerkaResultManager import SheerkaResultConcept
from core.sheerka.services.SheerkaResultManager import SheerkaResultManager
from sdp.sheerkaDataProvider import Event
from tests.TestUsingFileBasedSheerka import TestUsingFileBasedSheerka
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
@@ -25,7 +26,7 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
def init_service(self):
sheerka, context = self.init_test().unpack()
service = sheerka.services[SheerkaResultConcept.NAME]
service = sheerka.services[SheerkaResultManager.NAME]
return sheerka, context, service
@@ -64,7 +65,7 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
assert isinstance(res.body, types.GeneratorType)
# the digest is correctly recorded
assert sheerka.load_var(SheerkaResultConcept.NAME, "digest") == digest
assert sheerka.load_var(SheerkaResultManager.NAME, "digest") == digest
previous_results = list(res.body)
@@ -93,7 +94,7 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
assert isinstance(res.body, types.GeneratorType)
# the digest is correctly recorded
assert sheerka.load_var(SheerkaResultConcept.NAME, "digest") == digest
assert sheerka.load_var(SheerkaResultManager.NAME, "digest") == digest
previous_results = list(res.body)
@@ -148,7 +149,7 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
sheerka.evaluate_user_input("one")
sheerka.evaluate_user_input("one")
service = SheerkaResultConcept(sheerka, 2)
service = SheerkaResultManager(sheerka, 2)
res = service.get_results_by_command(context, "def concept")
assert sheerka.isinstance(res, BuiltinConcepts.EXPLANATION)
assert res.command == "def concept one as 1"
@@ -171,7 +172,7 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
sheerka.evaluate_user_input("one")
sheerka.evaluate_user_input("one")
service = SheerkaResultConcept(sheerka, 2)
service = SheerkaResultManager(sheerka, 2)
res = service.get_results_by_command(context, "fake command")
assert sheerka.isinstance(res, BuiltinConcepts.NOT_FOUND)
assert res.body == {'command': 'fake command'}
@@ -336,7 +337,7 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
def test_i_can_manage_invalid_predicates(self):
predicate = {"filter": "a b c"}
with pytest.raises(SyntaxError):
SheerkaResultConcept.get_predicate(**predicate)
SheerkaResultManager.get_predicate(**predicate)
def test_i_can_get_last_return_value(self):
sheerka, context, service = self.init_service()
@@ -368,3 +369,62 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
assert service.last_created_concept_id == new_concept.id
assert sheerka.get_last_created_concept(context) == new_concept
def test_last_error_is_recorded(self):
sheerka, context, foo = self.init_test().with_concepts("foo", create_new=True).unpack()
service = sheerka.services[SheerkaResultManager.NAME]
res = sheerka.evaluate_user_input("bar") # does not exist, will cause an error
sheerka.evaluate_user_input("foo") # exists, to validate that the error is not reset
assert service.last_error_event_id is not None
assert len(res) == 1
assert sheerka.get_last_error() == res[0]
def test_multiple_errors_are_recorded(self):
sheerka, context, foo = self.init_test().with_concepts("foo", create_new=True).unpack()
service = sheerka.services[SheerkaResultManager.NAME]
service.test_only_reset()
res = sheerka.evaluate_user_input("x x") # cannot be parsed
sheerka.evaluate_user_input("foo") # exists, to validate that the error is not reset
assert service.last_error_event_id is not None
assert len(res) > 1
assert sheerka.get_last_error() == [r for r in res if not r.status]
def test_i_cannot_get_last_error_when_no_error(self):
sheerka, context = self.init_test().unpack()
service = sheerka.services[SheerkaResultManager.NAME]
service.test_only_reset()
assert service.last_error_event_id is None
assert sheerka.get_last_error() == self.sheerka.new(BuiltinConcepts.NOT_FOUND, body={"query": "get_last_error"})
class TestSheerkaResultManagerFileBased(TestUsingFileBasedSheerka):
@classmethod
def setup_class(cls):
sheerka = cls().get_sheerka(cache_only=False, ontology="#TestSheerkaResultManager#")
sheerka.save_execution_context = True
cls.root_ontology_name = "#TestSheerkaResultManager#"
@classmethod
def teardown_class(cls):
cls.sheerka.pop_ontology()
cls.root_ontology_name = SheerkaOntologyManager.ROOT_ONTOLOGY_NAME
def test_i_can_retrieve_the_last_error_after_startup(self):
sheerka, context, foo = self.init_test().with_concepts("foo", create_new=True).unpack()
service = sheerka.services[SheerkaResultManager.NAME]
res_in_error = sheerka.evaluate_user_input("bar") # does not exist, will cause an error
sheerka.evaluate_user_input("foo") # exists, to validate that the error is not reset
assert service.last_error_event_id is not None
assert service.get_last_error() == res_in_error[0]
# simulate restart
sheerka = self.new_sheerka_instance(False)
service = sheerka.services[SheerkaResultManager.NAME]
assert service.last_error_event_id is not None
assert service.get_last_error() == res_in_error[0]