def test_run_multiple_library_location(self, mock_find_grammars, mock_run, mock_find_antlr,
                                           mock_find_java, tmpdir, command):
        java_exe = pathlib.Path('c:/path/to/java/bin/java.exe')
        antlr_jar = pathlib.Path('antlr-4.5.3-complete.jar')
        mock_find_java.return_value = java_exe
        mock_find_antlr.return_value = antlr_jar

        grammar = AntlrGrammar(pathlib.Path('SomeGrammar.g4'))
        grammar.dependencies = [
            AntlrGrammar(pathlib.Path('terminals/common.g4')),
            AntlrGrammar(pathlib.Path('rules/common.g4'))
        ]
        mock_find_grammars.return_value = [grammar]
        mock_run.return_value = unittest.mock.Mock(returncode=0)

        command.output['default'] = str(tmpdir.mkdir('gen'))

        with pytest.raises(distutils.errors.DistutilsOptionError) as excinfo:
            command.run()
        assert excinfo.match('Imported grammars of \'SomeGrammar\' are located in more than one '
                             'directory.')
    def test_run_one_library_location(self, mock_find_grammars, mock_run, mock_find_antlr,
                                      mock_find_java, tmpdir, command):
        java_exe = pathlib.Path('c:/path/to/java/bin/java.exe')
        antlr_jar = pathlib.Path('antlr-4.5.3-complete.jar')
        mock_find_java.return_value = java_exe
        mock_find_antlr.return_value = antlr_jar

        grammar = AntlrGrammar(pathlib.Path('SomeGrammar.g4'))
        grammar.dependencies = [
            AntlrGrammar(pathlib.Path('shared/CommonTerminals.g4'))
        ]
        mock_find_grammars.return_value = [grammar]
        mock_run.return_value = unittest.mock.Mock(returncode=0)

        command.output['default'] = str(tmpdir.mkdir('gen'))
        command.run()

        args, _ = mock_run.call_args
        assert mock_run.called
        assert '-lib' in args[0]
        assert any(a.endswith('shared') for a in args[0])
Example #3
0
    def test_run_one_library_location(self, mock_find_grammars, mock_run,
                                      mock_find_antlr, mock_find_java, tmpdir,
                                      command):
        java_exe = pathlib.Path('c:/path/to/java/bin/java.exe')
        antlr_jar = pathlib.Path('antlr-4.5.3-complete.jar')
        mock_find_java.return_value = java_exe
        mock_find_antlr.return_value = antlr_jar

        grammar = AntlrGrammar(pathlib.Path('SomeGrammar.g4'))
        grammar.dependencies = [
            AntlrGrammar(pathlib.Path('shared/CommonTerminals.g4'))
        ]
        mock_find_grammars.return_value = [grammar]
        mock_run.return_value = unittest.mock.Mock(returncode=0)

        command.output['default'] = str(tmpdir.mkdir('gen'))
        command.run()

        args, _ = mock_run.call_args
        assert mock_run.called
        assert '-lib' in args[0]
        assert any(a.endswith('shared') for a in args[0])
Example #4
0
    def test_run_multiple_library_location(self, mock_find_grammars, mock_run,
                                           mock_find_antlr, mock_find_java,
                                           tmpdir, command):
        java_exe = pathlib.Path('c:/path/to/java/bin/java.exe')
        antlr_jar = pathlib.Path('antlr-4.5.3-complete.jar')
        mock_find_java.return_value = java_exe
        mock_find_antlr.return_value = antlr_jar

        grammar = AntlrGrammar(pathlib.Path('SomeGrammar.g4'))
        grammar.dependencies = [
            AntlrGrammar(pathlib.Path('terminals/common.g4')),
            AntlrGrammar(pathlib.Path('rules/common.g4'))
        ]
        mock_find_grammars.return_value = [grammar]
        mock_run.return_value = unittest.mock.Mock(returncode=0)

        command.output['default'] = str(tmpdir.mkdir('gen'))

        with pytest.raises(distutils.errors.DistutilsOptionError) as excinfo:
            command.run()
        assert excinfo.match(
            'Imported grammars of \'SomeGrammar\' are located in more than one directory.'
        )