Beispiel #1
0
    def test_get_whole_expression_syntax_error(self):

        with patch("inspect.getsourcelines") as getsourcelines_mock:
            getsourcelines_mock.return_value = (
                [
                    "x = (y",
                    "+ 1",
                ], 0
            )
            stack_mock = Mock()
            stack_mock.line = "x = (y"
            stack_mock.lineno = 1
            with pytest.raises(frosch.ParseError):
                frosch.find_next_parseable_statment(stack_mock, None)
Beispiel #2
0
    def test_get_whole_expression(self):

        with patch("inspect.getsourcelines") as getsourcelines_mock:
            getsourcelines_mock.return_value = (
                [
                    "x = (y",
                    "+ 1",
                    "+ z)"
                ], 0
            )
            stack_mock = Mock()
            stack_mock.line = "x = (y"
            stack_mock.lineno = 1

            result = frosch.find_next_parseable_statment(stack_mock, None)
            expected_result = "x = (y + 1 + z)"
            self.assertEqual(result, expected_result)
Beispiel #3
0
    def test_find_next_parseable_statement(self):
        with patch("inspect.getsourcelines") as getsourcelines_mock:
            getsourcelines_mock.return_value = (
                [
                    "1+1",
                    "x = (",
                    "1",
                    "+ z)",
                    "2 + 2"
                ], 0
            )
            stack_mock = Mock()
            stack_mock.line = "x = ("
            stack_mock.lineno = 2

            result = frosch.find_next_parseable_statment(stack_mock, None)
            expected_result = "x = ( 1 + z)"
            self.assertEqual(result, expected_result)
Beispiel #4
0
    def test_get_whole_expression2(self):

        with patch("inspect.getsourcelines") as getsourcelines_mock:
            multi_line = [
                    "x = (",
                    "    y + "
                    "z)"
                ]
            getsourcelines_mock.return_value = (
                multi_line, 0
            )
            stack_mock = Mock()
            stack_mock.line = multi_line[0]
            stack_mock.lineno = 1

            result = frosch.find_next_parseable_statment(stack_mock, None)
            expected_result = "x = ( y + z)"
            self.assertEqual(result, expected_result)
Beispiel #5
0
    def test_find_next_parseable_statement2(self):
        source_lines = """
import sys
sys.path.append("..")

from frosch.frosch import hook

hook()


def hello():
    y = "Some String"
    z = [1, 2, "hel"]
    index = 0
    i = "Other string"
    x = ( 
        1 + 
        z)


def num():
    return 3


hello()

"""
        with patch("inspect.getsourcelines") as getsourcelines_mock:
            getsourcelines_mock.return_value = (
                source_lines.split("\n")
                , 0
            )
            stack_mock = Mock()
            stack_mock.line = "1 +"
            stack_mock.lineno = 15 

            result = frosch.find_next_parseable_statment(stack_mock, None)
            expected_result = "x = ( 1 + z)"
            self.assertEqual(result, expected_result)