51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
import pytest
|
|
|
|
from core.builtin_concepts import BuiltinConcepts, ReturnValueConcept, UserInputConcept
|
|
from core.concept import Concept
|
|
from evaluators.PrepareEvalQuestionEvaluator import PrepareEvalQuestionEvaluator
|
|
|
|
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
|
|
|
r = ReturnValueConcept
|
|
|
|
|
|
class TestPrepareEvalQuestionEvaluator(TestUsingMemoryBasedSheerka):
|
|
|
|
@pytest.mark.parametrize("ret_val, expected", [
|
|
(r("name", True, UserInputConcept("question(1 + 1)")), True),
|
|
(r("name", True, UserInputConcept(" question(1 + 1) ")), True),
|
|
(r("name", True, UserInputConcept("question()")), False),
|
|
(r("name", True, UserInputConcept("1+1")), False),
|
|
(r("name", True, UserInputConcept("")), False),
|
|
(r("name", True, UserInputConcept("question(")), False),
|
|
(r("name", True, UserInputConcept(")")), False),
|
|
(r("name", True, UserInputConcept([])), False),
|
|
(r("name", True, Concept("foo")), False),
|
|
(r("name", True, "not a concept"), False),
|
|
(r("name", False, UserInputConcept("question(1 + 1)")), False),
|
|
])
|
|
def test_i_can_match(self, ret_val, expected):
|
|
context = self.get_context()
|
|
assert PrepareEvalQuestionEvaluator().matches(context, ret_val) == expected
|
|
|
|
@pytest.mark.parametrize("ret_val, expected", [
|
|
(r("name", True, UserInputConcept("question(1 + 1)")), "1 + 1"),
|
|
(r("name", True, UserInputConcept(" question( 1 + 1 ) ")), "1 + 1"),
|
|
])
|
|
def test_i_can_eval(self, ret_val, expected):
|
|
context = self.get_context()
|
|
sheerka = context.sheerka
|
|
|
|
prepare_evaluator = PrepareEvalQuestionEvaluator()
|
|
prepare_evaluator.matches(context, ret_val)
|
|
res = prepare_evaluator.eval(context, ret_val)
|
|
|
|
assert res.status
|
|
assert sheerka.isinstance(res.body, BuiltinConcepts.USER_INPUT)
|
|
assert res.body.body == expected
|
|
|
|
assert BuiltinConcepts.EVAL_QUESTION_REQUESTED in context.protected_hints
|
|
assert BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED in context.protected_hints
|
|
assert BuiltinConcepts.EVAL_BODY_REQUESTED in context.protected_hints
|
|
assert BuiltinConcepts.RETURN_BODY_REQUESTED in context.protected_hints
|