Files
Sheerka-Old/tests/parsers/test_ShortTermMemoryParser.py
T
kodjo 7dcaa9c111 Fixed #29: Parsers: Implement parsing memoization
Fixed #77 : Parser: ShortTermMemoryParser should be called separately
Fixed #78 : Remove VariableNode usage
Fixed #79 : ConceptManager: Implement compile caching
Fixed #80 : SheerkaExecute : parsers_key is not correctly computed
Fixed #81 : ValidateConceptEvaluator : Validate concept's where and pre clauses right after the parsing
Fixed #82 : SheerkaIsAManager: isa() failed when the set as a body
Fixed #83 : ValidateConceptEvaluator : Support BNF and SYA Concepts
Fixed #84 : ExpressionParser: Implement the parser as a standard parser
Fixed #85 : Services: Give order to services
Fixed #86 : cannot manage smart_get_attr(the short, color)
2021-06-07 21:14:03 +02:00

70 lines
2.3 KiB
Python

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