Introduced ParserInput
This commit is contained in:
@@ -3,7 +3,8 @@ import ast
|
||||
import core.utils
|
||||
import pytest
|
||||
from core.builtin_concepts import ParserResultConcept, NotForMeConcept
|
||||
from core.tokenizer import Tokenizer, LexerError
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.tokenizer import LexerError
|
||||
from parsers.PythonParser import PythonNode, PythonParser, PythonErrorNode
|
||||
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
@@ -17,21 +18,7 @@ class TestPythonParser(TestUsingMemoryBasedSheerka):
|
||||
])
|
||||
def test_i_can_parse_a_simple_expression(self, text, expected):
|
||||
parser = PythonParser()
|
||||
res = parser.parse(self.get_context(), text)
|
||||
|
||||
assert res.status
|
||||
assert res.who == parser.name
|
||||
assert isinstance(res.value, ParserResultConcept)
|
||||
assert res.value.value == expected
|
||||
|
||||
@pytest.mark.parametrize("text, expected", [
|
||||
("1+1", PythonNode("1+1", ast.parse("1+1", mode="eval"))),
|
||||
("a=10", PythonNode("a=10", ast.parse("a=10", mode="exec"))),
|
||||
])
|
||||
def test_i_can_parse_from_tokens(self, text, expected):
|
||||
parser = PythonParser()
|
||||
tokens = list(Tokenizer(text))
|
||||
res = parser.parse(self.get_context(), tokens)
|
||||
res = parser.parse(self.get_context(), ParserInput(text))
|
||||
|
||||
assert res.status
|
||||
assert res.who == parser.name
|
||||
@@ -40,12 +27,11 @@ class TestPythonParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
@pytest.mark.parametrize("text", [
|
||||
"1+",
|
||||
"'name",
|
||||
"foo = 'name"
|
||||
"&#é",
|
||||
])
|
||||
def test_i_can_detect_error(self, text):
|
||||
def test_i_can_detect_python_error(self, text):
|
||||
parser = PythonParser()
|
||||
res = parser.parse(self.get_context(), text)
|
||||
res = parser.parse(self.get_context(), ParserInput(text))
|
||||
|
||||
assert not res.status
|
||||
assert res.who == parser.name
|
||||
@@ -61,7 +47,7 @@ class TestPythonParser(TestUsingMemoryBasedSheerka):
|
||||
])
|
||||
def test_i_can_detect_lexer_errors(self, text, error_msg, error_text):
|
||||
parser = PythonParser()
|
||||
res = parser.parse(self.get_context(), text)
|
||||
res = parser.parse(self.get_context(), ParserInput(text))
|
||||
|
||||
assert not res.status
|
||||
assert isinstance(res.value, NotForMeConcept)
|
||||
@@ -76,12 +62,13 @@ class TestPythonParser(TestUsingMemoryBasedSheerka):
|
||||
text = "c:name|id: + 1"
|
||||
|
||||
parser = PythonParser()
|
||||
res = parser.parse(self.get_context(), text)
|
||||
res = parser.parse(self.get_context(), ParserInput(text))
|
||||
encoded = core.utils.encode_concept(("name", "id"))
|
||||
|
||||
assert res
|
||||
assert res.value.source == "c:name|id: + 1"
|
||||
assert res.value.value == PythonNode(
|
||||
"c:name|id: + 1",
|
||||
"__C__KEY_name__ID_id__C__ + 1",
|
||||
ast.parse(encoded + "+1", mode="eval"))
|
||||
assert res.value.value.concepts == {
|
||||
encoded: ("name", "id")
|
||||
|
||||
Reference in New Issue
Block a user