Added first version of console autocompletion
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import pytest
|
||||
from core.builtin_concepts import ReturnValueConcept, BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.sheerka.services.SheerkaFunctionsParametersHistory import SheerkaFunctionsParametersHistory
|
||||
from evaluators.UpdateFunctionsParametersEvaluator import UpdateFunctionsParametersEvaluator
|
||||
from parsers.PythonParser import PythonNode
|
||||
|
||||
from tests.BaseTest import BaseTest
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
|
||||
r = ReturnValueConcept
|
||||
|
||||
|
||||
class TestUpdateFunctionsParametersEvaluator(TestUsingMemoryBasedSheerka):
|
||||
|
||||
@pytest.mark.parametrize("return_value, expected_result", [
|
||||
(r("evaluators.Python", True), True),
|
||||
(r("evaluators.Python", False), False),
|
||||
(r("other_name", True), False),
|
||||
(r("other_name", False), False),
|
||||
])
|
||||
def test_i_can_match(self, return_value, expected_result):
|
||||
sheerka, context = self.init_concepts()
|
||||
evaluator = UpdateFunctionsParametersEvaluator()
|
||||
|
||||
assert evaluator.matches(context, return_value) == expected_result
|
||||
|
||||
@pytest.mark.parametrize("return_value", [
|
||||
r("evaluators.Python", True),
|
||||
r("evaluators.Python", True, parents=[]),
|
||||
r("evaluators.Python", True, parents=[BaseTest.pretval(Concept(), who="notPythonParser")]),
|
||||
])
|
||||
def test_i_cannot_eval_if_original_parser_is_not_found(self, return_value):
|
||||
sheerka, context = self.init_concepts()
|
||||
evaluator = UpdateFunctionsParametersEvaluator()
|
||||
|
||||
res = evaluator.eval(context, return_value)
|
||||
|
||||
assert res == return_value
|
||||
assert not res.parents[-1].status
|
||||
assert sheerka.isinstance(res.parents[-1].body, BuiltinConcepts.NOT_FOUND)
|
||||
assert res.parents[-1].body.body == "source code"
|
||||
|
||||
@pytest.mark.parametrize("source, func_name, param_number, expected", [
|
||||
("func()", "func", 0, []),
|
||||
("func(10)", "func", 0, ["10"]),
|
||||
("func(10, True, 'some string')", "func", 0, ["10"]),
|
||||
("func(10, True, 'some string')", "func", 1, ["True"]),
|
||||
("func(10, True, 'some string')", "func", 2, ["'some string'"]),
|
||||
("func1(10) | func2(20)", "func2", 0, ["20"]),
|
||||
("func1(10, func2(20), 'string')", "func1", 0, ["10"]),
|
||||
("func1(10, func2(20), 'string')", "func1", 1, ["func2(20)"]),
|
||||
("func1(10, func2(20), 'string')", "func1", 2, ["'string'"]),
|
||||
("func1(10, func2(20), 'string')", "func2", 0, ["20"]),
|
||||
])
|
||||
def test_i_can_record_functions_parameters(self, source, func_name, param_number, expected):
|
||||
sheerka, context = self.init_concepts()
|
||||
|
||||
parser_ret_val = self.pretval(PythonNode(source), who="parsers.Python", source=source)
|
||||
return_value = r("evaluators.Python", True, parents=[parser_ret_val])
|
||||
evaluator = UpdateFunctionsParametersEvaluator()
|
||||
|
||||
res = evaluator.eval(context, return_value)
|
||||
|
||||
assert res == return_value
|
||||
|
||||
service = sheerka.services[SheerkaFunctionsParametersHistory.NAME]
|
||||
assert service.get_function_parameters(func_name, param_number) == expected
|
||||
Reference in New Issue
Block a user