Exemplo n.º 1
0
    def test_run_antlr_not_found(self, mock_find_antlr, mock_find_java, command):
        java_exe = pathlib.Path('c:/path/to/java/bin/java.exe')

        mock_find_java.return_value = java_exe
        mock_find_antlr.return_value = None

        with pytest.raises(distutils.errors.DistutilsExecError) as excinfo:
            command.run()
        assert excinfo.match('no ANTLR jar')
Exemplo n.º 2
0
    def test_run_java_found(self, mock_find_grammars, mock_run, mock_find_java, tmpdir, command):
        java_exe = pathlib.Path('c:/path/to/java/bin/java.exe')

        mock_find_java.return_value = java_exe
        mock_find_grammars.return_value = [AntlrGrammar(pathlib.Path('standalone/SomeGrammar.g4'))]
        mock_run.return_value = subprocess.CompletedProcess([], 0)

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

        args, _ = mock_run.call_args
        assert mock_run.called
        assert str(java_exe) in args[0]
        assert '-jar' in args[0]
Exemplo n.º 3
0
    def test_run_antlr_found(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
        mock_find_grammars.return_value = [AntlrGrammar(pathlib.Path('standalone/SomeGrammar.g4'))]
        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 str(antlr_jar) in args[0]
Exemplo n.º 4
0
    def test_run_package_not_exists(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'))
        mock_find_grammars.return_value = [grammar]
        mock_run.return_value = unittest.mock.Mock(returncode=0)

        gen_dir = str(tmpdir.mkdir('gen'))
        package_dir = pathlib.Path(gen_dir, 'some_grammar')

        init_file = pathlib.Path(package_dir, '__init__.py')

        command.output['default'] = gen_dir
        command.run()

        assert init_file.exists()
Exemplo n.º 5
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.')
Exemplo n.º 6
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])
Exemplo n.º 7
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])
Exemplo n.º 8
0
    def test_run_package_not_exists(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'))
        mock_find_grammars.return_value = [grammar]
        mock_run.return_value = unittest.mock.Mock(returncode=0)

        base_dir = str(tmpdir.mkdir('base'))
        package_dir = pathlib.Path(base_dir, 'some_grammar')

        package_init_file = pathlib.Path(package_dir, '__init__.py')

        command.output['default'] = base_dir
        os.chdir(str(base_dir))

        command.run()

        assert package_init_file.exists()
Exemplo n.º 9
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.'
        )
Exemplo n.º 10
0
    def test_run_java_not_found(self, mock_find_java, command):
        mock_find_java.return_value = None

        with pytest.raises(distutils.errors.DistutilsExecError) as excinfo:
            command.run()
        assert excinfo.match('no compatible JRE')
Exemplo n.º 11
0
    def test_run_java_not_found(self, mock_find_java, command):
        mock_find_java.return_value = None

        with pytest.raises(distutils.errors.DistutilsExecError) as excinfo:
            command.run()
        assert excinfo.match('no compatible JRE')