First implementation of Debugger for SyaNodeParser
This commit is contained in:
@@ -14,10 +14,8 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
sheerka = cls().get_sheerka()
|
||||
sheerka = cls().get_sheerka(cache_only=False)
|
||||
sheerka.save_execution_context = True
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
cls.io_cache = sheerka.sdp.io.cache.copy()
|
||||
|
||||
@classmethod
|
||||
def teardown_class(cls):
|
||||
@@ -26,21 +24,73 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
|
||||
def init_test(self):
|
||||
sheerka, context = self.init_concepts()
|
||||
sheerka.sdp.io.cache = self.io_cache.copy()
|
||||
return sheerka, context
|
||||
service = sheerka.services[SheerkaResultConcept.NAME]
|
||||
|
||||
def test_i_can_get_the_result_by_digest(self):
|
||||
sheerka, context = self.init_test()
|
||||
return sheerka, context, service
|
||||
|
||||
digest = sheerka.get_last_execution().event.get_digest()
|
||||
def test_i_can_record_execution_contexts(self):
|
||||
sheerka, context, service = self.init_test()
|
||||
|
||||
sheerka.evaluate_user_input("foo")
|
||||
|
||||
executions_contexts_in_cache = service.executions_contexts_cache.copy()
|
||||
assert len(executions_contexts_in_cache) == 1
|
||||
event_id = list(executions_contexts_in_cache.keys())[0]
|
||||
execution_context = list(executions_contexts_in_cache.values())[0]
|
||||
|
||||
assert execution_context.desc == "Evaluating 'foo'"
|
||||
|
||||
executions_contexts_in_db = sheerka.sdp.load_result(event_id)
|
||||
assert executions_contexts_in_db is not None
|
||||
assert executions_contexts_in_db.desc == "Evaluating 'foo'"
|
||||
|
||||
assert service.last_execution is not None
|
||||
assert service.last_execution.desc == "Evaluating 'foo'"
|
||||
|
||||
def test_i_can_get_the_result_by_digest_using_cache(self):
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
|
||||
digest = service.last_execution.event.get_digest()
|
||||
|
||||
res = sheerka.get_results_by_digest(context, digest)
|
||||
|
||||
# we get the result
|
||||
assert sheerka.isinstance(res, BuiltinConcepts.EXPLANATION)
|
||||
assert res.command == "def concept one as 1"
|
||||
assert res.digest == digest
|
||||
assert isinstance(res.body, types.GeneratorType)
|
||||
|
||||
# the digest is correctly recorded
|
||||
assert sheerka.load_var(SheerkaResultConcept.NAME, "digest") == digest
|
||||
|
||||
previous_results = list(res.body)
|
||||
|
||||
# Second test,
|
||||
# I can get the result from the recorded digest
|
||||
res = sheerka.get_results(context)
|
||||
assert sheerka.isinstance(res, BuiltinConcepts.EXPLANATION)
|
||||
assert res.command == "def concept one as 1"
|
||||
assert res.digest == digest
|
||||
assert isinstance(res.body, types.GeneratorType)
|
||||
|
||||
assert list(res.body) == previous_results
|
||||
|
||||
def test_i_can_get_result_by_digest_using_db(self):
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
digest = service.last_execution.event.get_digest()
|
||||
service.reset()
|
||||
|
||||
res = sheerka.get_results_by_digest(context, digest)
|
||||
|
||||
# we get the result
|
||||
assert sheerka.isinstance(res, BuiltinConcepts.EXPLANATION)
|
||||
assert res.command == "def concept one as 1"
|
||||
assert res.digest == digest
|
||||
assert isinstance(res.body, types.GeneratorType)
|
||||
|
||||
# the digest is correctly recorded
|
||||
assert sheerka.load_var(SheerkaResultConcept.NAME, "digest") == digest
|
||||
|
||||
previous_results = list(res.body)
|
||||
@@ -67,9 +117,10 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.get_results(context) is None
|
||||
|
||||
def test_i_can_get_the_result_by_command_name(self):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
|
||||
digest = sheerka.get_last_execution().event.get_digest()
|
||||
digest = service.last_execution.event.get_digest()
|
||||
sheerka.evaluate_user_input("one") # another command
|
||||
|
||||
res = sheerka.get_results_by_command(context, "def concept")
|
||||
@@ -78,8 +129,18 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
assert res.digest == digest
|
||||
assert isinstance(res.body, types.GeneratorType)
|
||||
|
||||
def test_i_can_get_the_result_by_command_name_using_db(self):
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
sheerka.evaluate_user_input("one") # another command
|
||||
service.reset()
|
||||
|
||||
res = sheerka.get_results_by_command(context, "def concept")
|
||||
assert res.command == "def concept one as 1"
|
||||
|
||||
def test_i_can_get_the_result_by_command_when_not_in_the_same_page_size(self):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
|
||||
sheerka.evaluate_user_input("one")
|
||||
sheerka.evaluate_user_input("one")
|
||||
@@ -98,7 +159,8 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
assert res.body == {'command': 'def concept'}
|
||||
|
||||
def test_i_cannot_get_result_from_command_if_the_command_does_not_exists_multiple_pages(self):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
|
||||
sheerka.evaluate_user_input("one")
|
||||
sheerka.evaluate_user_input("one")
|
||||
@@ -110,7 +172,8 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
assert res.body == {'command': 'fake command'}
|
||||
|
||||
def test_i_can_get_last_results(self):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
|
||||
sheerka.evaluate_user_input("one")
|
||||
|
||||
@@ -118,6 +181,16 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.isinstance(res, BuiltinConcepts.EXPLANATION)
|
||||
assert res.command == "one"
|
||||
|
||||
def test_i_can_get_last_results_using_db(self):
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
sheerka.evaluate_user_input("one")
|
||||
service.reset()
|
||||
|
||||
res = sheerka.get_last_results(context)
|
||||
assert sheerka.isinstance(res, BuiltinConcepts.EXPLANATION)
|
||||
assert res.command == "one"
|
||||
|
||||
def test_i_can_get_last_results_when_event_with_no_result(self):
|
||||
sheerka, context = self.init_concepts()
|
||||
|
||||
@@ -154,7 +227,8 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
{"desc": "Evaluating 'def concept one as 1'", "id": 0}
|
||||
])
|
||||
def test_i_can_get_last_results_using_kwarg(self, kwargs):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
ExecutionContext.ids.clear()
|
||||
|
||||
res = sheerka.get_last_results(context, **kwargs)
|
||||
@@ -170,7 +244,8 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
("'def concept one as 1' in desc and id == 0", {"desc": "Evaluating 'def concept one as 1'", "id": 0})
|
||||
])
|
||||
def test_i_can_get_last_results_using_filter(self, predicate, expected):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
ExecutionContext.ids.clear()
|
||||
|
||||
res = sheerka.get_last_results(context, filter=predicate)
|
||||
@@ -186,7 +261,8 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
("'def concept one as 1' in desc and id == 0", {"desc": "Evaluating 'def concept one as 1'", "id": 0})
|
||||
])
|
||||
def test_i_can_get_last_results_using_the_first_argument_to_filter(self, predicate, expected):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
ExecutionContext.ids.clear()
|
||||
|
||||
res = sheerka.get_last_results(context, predicate)
|
||||
@@ -202,7 +278,8 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
{"desc": "Evaluating 'def concept one as 1'", "id": 0}
|
||||
])
|
||||
def test_i_can_get_results_using_kwarg(self, kwargs):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
ExecutionContext.ids.clear()
|
||||
sheerka.get_last_results(context)
|
||||
|
||||
@@ -219,7 +296,8 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
("'def concept one as 1' in desc and id == 0", {"desc": "Evaluating 'def concept one as 1'", "id": 0})
|
||||
])
|
||||
def test_i_can_get_results_using_filter(self, predicate, expected):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
ExecutionContext.ids.clear()
|
||||
sheerka.get_last_results(context)
|
||||
|
||||
@@ -236,7 +314,8 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
("'def concept one as 1' in desc and id == 0", {"desc": "Evaluating 'def concept one as 1'", "id": 0})
|
||||
])
|
||||
def test_i_can_get_results_using_the_first_argument_to_filter(self, predicate, expected):
|
||||
sheerka, context = self.init_test()
|
||||
sheerka, context, service = self.init_test()
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
ExecutionContext.ids.clear()
|
||||
sheerka.get_last_results(context)
|
||||
|
||||
@@ -251,3 +330,35 @@ class TestSheerkaResultManager(TestUsingMemoryBasedSheerka):
|
||||
predicate = {"filter": "a b c"}
|
||||
with pytest.raises(SyntaxError):
|
||||
SheerkaResultConcept.get_predicate(**predicate)
|
||||
|
||||
def test_i_can_get_last_return_value(self):
|
||||
sheerka, context, service = self.init_test()
|
||||
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
ret = sheerka.last_ret(context)
|
||||
assert sheerka.isinstance(ret[0].body, BuiltinConcepts.NEW_CONCEPT)
|
||||
|
||||
sheerka.evaluate_user_input("eval one")
|
||||
ret = sheerka.last_ret(context)
|
||||
assert ret[0].body == 1
|
||||
|
||||
def test_i_can_track_new_concept(self):
|
||||
sheerka, context, service = self.init_test()
|
||||
|
||||
res = sheerka.evaluate_user_input("def concept one as 1")
|
||||
new_concept = res[0].body.body
|
||||
|
||||
assert sheerka.last_created_concept(context) == new_concept
|
||||
assert service.last_created_concept_id == new_concept.id
|
||||
|
||||
def test_last_created_concept_is_recorded(self):
|
||||
sheerka, context, service = self.init_test()
|
||||
res = sheerka.evaluate_user_input("def concept one as 1")
|
||||
new_concept = res[0].body.body
|
||||
service.reset()
|
||||
|
||||
service.initialize_deferred(context, False)
|
||||
|
||||
assert service.last_created_concept_id == new_concept.id
|
||||
assert sheerka.last_created_concept(context) == new_concept
|
||||
|
||||
|
||||
Reference in New Issue
Block a user