from core.builtin_concepts import BuiltinConcepts from core.concept import Concept from core.sheerka.services.SheerkaExecute import ParserInput from parsers.ShortTermMemoryParser import ShortTermMemoryParser from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka class TestShortTermMemoryParser(TestUsingMemoryBasedSheerka): def init_parser(self): sheerka, context = self.init_concepts() parser = ShortTermMemoryParser() return sheerka, context, parser def test_i_cannot_parse_empty_string(self): sheerka, context, parser = self.init_parser() res = parser.parse(context, ParserInput("")) assert not res.status assert sheerka.isinstance(res.body, BuiltinConcepts.IS_EMPTY) def test_i_can_get_concept_from_sheerka(self): sheerka, context, parser = self.init_parser() foo = Concept("foo") sheerka.add_to_short_term_memory(None, "test", foo) res = parser.parse(context, ParserInput("test")) assert res.status assert id(res.body) == id(foo) def test_i_can_get_concept_from_the_context(self): sheerka, context, parser = self.init_parser() foo = Concept("foo") sheerka.add_to_short_term_memory(context, "test", foo) res = parser.parse(context, ParserInput("test")) assert res.status assert id(res.body) == id(foo) def test_i_can_get_concept_from_parent_context(self): sheerka, context, parser = self.init_parser() foo = Concept("foo") sheerka.add_to_short_term_memory(context, "test", foo) with context.push(BuiltinConcepts.TESTING, None) as sub_context: res = parser.parse(sub_context, ParserInput("test")) assert res.status assert id(res.body) == id(foo) def test_i_cannot_get_concept_when_no_concept_in_memory(self): sheerka, context, parser = self.init_parser() res = parser.parse(context, ParserInput("test")) assert not res.status assert sheerka.isinstance(res.body, BuiltinConcepts.NOT_FOUND) assert res.body.body == "test" def test_parser_can_only_be_called_with_parser_input(self): sheerka, context, parser = self.init_parser() assert parser.parse(context, "not_a_parser_input") is None