Пример #1
0
    def test_one_line_function(self):
        self._dp.ignore_lines.return_value = False
        path = file_path_mock(io.StringIO("def f(x): return x"))

        sp = script_set_processor._ContentParser(self._logger, self._dp, path)
        self.assertEqual(
            ParsedScriptContent(
                """# parsed by py4lo (https://github.com/jferard/py4lo)
def f(x): return x


g_exportedScripts = (f,)""", ["f"]), sp.parse(True))
        self.verify_open(path)
Пример #2
0
    def test_script_parser_directve_line(self):
        self._dp.process_line.return_value = ["line1", "line2"]
        path = file_path_mock(io.StringIO("#some line"))

        sp = script_set_processor._ContentParser(self._logger, self._dp, path)
        self.assertEqual(
            ParsedScriptContent(
                '# parsed by py4lo (https://github.com/jferard/py4lo)\nline1\nline2',
                []), sp.parse(True))

        self.assertEqual([], self._logger.mock_calls)
        self.assertEqual([call.process_line('#some line'),
                          call.end()], self._dp.mock_calls)
        self.verify_open(path)
Пример #3
0
    def test_script_parser_normal_line_ignore(self):
        self._dp.ignore_lines.return_value = True
        path = file_path_mock(io.StringIO("some line"))

        sp = script_set_processor._ContentParser(self._logger, self._dp, path)
        self.assertEqual(
            ParsedScriptContent(
                '# parsed by py4lo (https://github.com/jferard/py4lo)\n### py4lo ignore: some line',
                []), sp.parse(True))

        self.assertEqual([], self._logger.mock_calls)
        self.assertEqual([call.ignore_lines(), call.end()],
                         self._dp.mock_calls)
        self.verify_open(path)