Пример #1
0
    def test_sources_no_dir(self, tmpdir):
        project_dir = Path(str(tmpdir))
        project = Project.from_dir(project_dir, name='test', version='1.2.3')

        with Options(project=project):
            config = JavaConfiguration()
            task_config = PackageConfiguration()

        task_config.doc = False

        jar_file = config.library_dist_dir(
            ensure=True) / project.name / 'test-1.2.3.jar'
        _ = config.classes_dir(ensure=True)
        _ = config.resources_dir(ensure=True)
        code_dir = config.code_dir()
        expected = [
            'jar', '--create', '--file',
            str(jar_file), '--manifest',
            Regex('.*'), '-C',
            Regex('.*/jar_content'), '.'
        ]

        with FakeProcessContext(FakeProcess(expected)):
            with pytest.raises(ValueError) as info:
                with Options(project=project):
                    with patch(
                            'builder.java.package.sign_path') as mock_signer:
                        mock_signer.return_value = {}

                        java_package(config, task_config, [])

        mock_signer.assert_called_once_with(jar_file)

        assert info.value.args[
            0] == f'Cannot build a sources archive since {code_dir} does not exist.'
Пример #2
0
    def test_no_source(self, tmpdir):
        project_dir = Path(str(tmpdir))
        project = Project.from_dir(project_dir, name='test', version='1.2.3')

        with Options(project=project):
            java_config = JavaConfiguration()
            task_config = PackageConfiguration()

        task_config.sources = False
        task_config.doc = False

        jar_file = java_config.library_dist_dir(
            ensure=True) / project.name / 'test-1.2.3.jar'
        _ = java_config.classes_dir(ensure=True)
        _ = java_config.resources_dir(ensure=True)
        expected = [
            'jar', '--create', '--file',
            str(jar_file), '--manifest',
            Regex('.*'), '-C',
            Regex('.*/jar_content'), '.'
        ]

        with FakeProcessContext(FakeProcess(expected)):
            with Options(project=project):
                with patch('builder.java.package.sign_path') as mock_signer:
                    mock_signer.return_value = {}

                    java_package(java_config, task_config, [])

        mock_signer.assert_called_once_with(jar_file)
Пример #3
0
    def _test_java_doc(self, tmpdir, verbose: int):
        project_dir = Path(str(tmpdir))
        project = Project.from_dir(project_dir)

        with Options(project=project):
            config = JavaConfiguration()

        # These need to exist for the test to work.
        code_dir = config.code_dir(ensure=True)
        doc_dir = config.doc_dir(ensure=True)

        self._create_fake_source_structure(code_dir)

        expected = [
            'javadoc', '-d',
            str(doc_dir), '--source-path',
            str(code_dir), 'com.test.pkg', 'com.test.pkg.sub'
        ]

        if verbose == 0:
            expected.insert(1, '-quiet')

        with FakeProcessContext(FakeProcess(expected)):
            with Options(verbose=verbose):
                java_doc(config, [])
Пример #4
0
    def test_add_verbose_options_no_extras(self):
        options = []

        with Options(verbose=2):
            _add_verbose_options(options)

        assert options == []

        with Options(verbose=3):
            _add_verbose_options(options)

        assert options == ['-verbose']
Пример #5
0
    def test_fix_up_option_language_list(self):
        info = {'languages': 'java'}

        with Options(languages=['python']):
            _fix_up_language_list(info)

        assert info == {'languages': ['java', 'python']}

        info = {'languages': ['java', 'python']}

        with Options(languages=['python']):
            _fix_up_language_list(info)

        assert info == {'languages': ['java', 'python']}
Пример #6
0
    def test_add_verbose_options_inserted_first(self):
        options = ['--flag', 'other-thing']

        with Options(verbose=3):
            _add_verbose_options(options)

        assert options == ['-verbose', '--flag', 'other-thing']

        options = ['--flag', 'other-thing']

        with Options(verbose=3):
            _add_verbose_options(options, '-bogus1', '-bogus2')

        assert options == ['-verbose', '-bogus1', '-bogus2', '--flag', 'other-thing']
Пример #7
0
    def test_add_variant_with_dependencies(self, tmpdir):
        path = Path(str(tmpdir)) / 'fake.jar'
        project = Project.from_dir(Path('/path/to/project'), version='1.3.4')

        path.write_text("Testing\n", encoding='utf-8')

        with Options(project=project):
            module_data = _create_module_data()

        dependency = Dependency('dep', {
            'location': 'remote',
            'version': '1.2.3',
            'scope': 'scope'
        })

        transient = dependency.derive_from('group', 'name', '1.2.4')
        transient.transient = True
        path_sets = [
            DependencyPathSet(dependency, path),
            DependencyPathSet(transient, path)
        ]

        _add_variant(module_data, API_ELEMENTS, path, {}, 'library', 'api',
                     None, path_sets)

        self._compare_to_file(module_data, 'variant_2')
Пример #8
0
    def test_add_verbose_options_with_extras_only(self):
        options = []

        with Options(verbose=2):
            _add_verbose_options(options, '-bogus1', '-bogus2')

        assert options == ['-bogus1', '-bogus2']
Пример #9
0
    def test_create_module_data(self):
        project = Project.from_dir(Path('/path/to/project'), version='1.3.4')

        with Options(project=project):
            module_data = _create_module_data()

        self._compare_to_file(module_data, 'basic_module')
Пример #10
0
    def test_verbose_output(self):
        cmd_line = ['ls', '-l']

        with Options(verbose=1):
            with FakeEcho.simple('Running: ls -l', fg='green') as fe:
                with FakeProcessContext(FakeProcess(cmd_line)):
                    checked_run(cmd_line, 'Testing')
            assert fe.was_called()
Пример #11
0
    def test_out_ignore_quiet(self):
        with Options(quiet=True):
            with FakeEcho.simple('test') as fe:
                out('test', respect_quiet=False)
        assert fe.was_called()

        with FakeEcho.simple('test') as fe:
            out('test', respect_quiet=False)
        assert fe.was_called()
Пример #12
0
    def test_build_options_with_verbose(self):
        """Make sure we build options correctly with no class path but verbosely."""
        path = Path('classes')

        with Options(verbose=3):
            options = _build_compiler_options(path, [])

        # noinspection SpellCheckingInspection
        assert options == ['-verbose', '-Xdiags:verbose', '-d', 'classes']
Пример #13
0
    def test_verbose_out_verbose(self):
        with Options(verbose=1):
            with FakeEcho.simple('test', fg='white') as fe:
                verbose_out('test', fg='white')
            assert fe.was_called()

            with FakeEcho.simple('test', fg='green') as fe:
                verbose_out('test')
            assert fe.was_called()
Пример #14
0
    def test_basic_dict_substitutions(self):
        data = {'name': '${value}'}
        variables = {
            'value': '1'
        }

        with Options(variables=variables):
            _resolve_vars_in_dict(data, {})

        assert data == {'name': '1'}
Пример #15
0
    def test_basic_list_substitutions(self):
        data = ['name', '${value}']
        variables = {
            'value': '1'
        }

        with Options(variables=variables):
            _resolve_vars_in_list(data, {})

        assert data == ['name', '1']
Пример #16
0
    def test_build_options_with_verbose(self):
        """Make sure we build options correctly with no entry point but verbosely."""
        path = Path('path/to/file.jar')

        with Options(verbose=3):
            options = _build_jar_options(path, None)

        assert options == [
            '-verbose', '--create', '--file', 'path/to/file.jar'
        ]
Пример #17
0
    def test_sources_with_dir(self, tmpdir):
        project_dir = Path(str(tmpdir))
        project = Project.from_dir(project_dir, name='test', version='1.2.3')

        with Options(project=project):
            config = JavaConfiguration()
            task_config = PackageConfiguration()

        task_config.doc = False

        jar_file = config.library_dist_dir(
            ensure=True) / project.name / 'test-1.2.3.jar'
        sources_jar_file = config.library_dist_dir(
        ) / project.name / 'test-1.2.3-sources.jar'
        _ = config.classes_dir(ensure=True)
        resources_dir = config.resources_dir(ensure=True)
        code_dir = config.code_dir(ensure=True)
        expected_jar = [
            'jar', '--create', '--file',
            str(jar_file), '--manifest',
            Regex('.*'), '-C',
            Regex('.*/jar_content'), '.'
        ]
        expected_sources = [
            'jar', '--create', '--file',
            str(sources_jar_file), '-C',
            str(code_dir), '.', '-C',
            str(resources_dir), '.'
        ]

        with FakeProcessContext(
            [FakeProcess(expected_jar),
             FakeProcess(expected_sources)]):
            with Options(project=project):
                with patch('builder.java.package.sign_path') as mock_signer:
                    mock_signer.return_value = {}

                    java_package(config, task_config, [])

        assert mock_signer.mock_calls == [
            call(jar_file), call(sources_jar_file)
        ]
Пример #18
0
    def test_run_javap_with_public_verbose(self):
        directory = Path('.')
        class_file = Path('MyClass.class')
        expected_args = ['javap', '-verbose', '-public', str(class_file)]

        with Options(verbose=3):
            with FakeProcessContext(
                    FakeProcess(expected_args, "line 1\nline 2",
                                cwd=directory)):
                result = _run_describer(directory, [class_file], True)

        assert result == ['line 1', 'line 2']
Пример #19
0
    def test_warn_out(self):
        with FakeEcho.simple('Warning: testing', fg='yellow') as fe:
            warn('testing')
        assert fe.was_called()

        with FakeEcho.simple('ERROR: testing', fg='yellow') as fe:
            warn('testing', label='ERROR')
        assert fe.was_called()

        with Options(quiet=True):
            with FakeEcho.simple('Warning: testing', fg='yellow') as fe:
                warn('testing')
            assert fe.was_called()
Пример #20
0
    def test_add_variant_no_dependencies(self, tmpdir):
        path = Path(str(tmpdir)) / 'fake.jar'
        project = Project.from_dir(Path('/path/to/project'), version='1.3.4')

        path.write_text("Testing\n", encoding='utf-8')

        with Options(project=project):
            module_data = _create_module_data()

        _add_variant(module_data, API_ELEMENTS, path, {}, 'library', 'api',
                     None, [])

        self._compare_to_file(module_data, 'variant_1')
Пример #21
0
    def test_javadoc_no_dir(self, tmpdir):
        project_dir = Path(str(tmpdir))
        project = Project.from_dir(project_dir, name='test', version='1.2.3')

        with Options(project=project):
            config = JavaConfiguration()
            task_config = PackageConfiguration()

        task_config.sources = False

        _ = config.classes_dir(ensure=True)
        _ = config.resources_dir(ensure=True)
        doc_dir = config.doc_dir()

        with pytest.raises(ValueError) as info:
            with Options(project):
                with patch('builder.java.package.sign_path') as mock_signer:
                    mock_signer.return_value = {}

                    java_package(config, task_config, [])

        assert info.value.args[
            0] == f'Cannot build a JavaDoc archive since {doc_dir} does not exist.'
Пример #22
0
    def test_simple_java_compile(self, tmpdir):
        project_dir = Path(str(tmpdir))
        project = Project.from_dir(project_dir)

        with Options(project=project):
            config = JavaConfiguration()

        # This needs to exist for the test to work.
        _ = config.code_dir(ensure=True)

        expected = ['javac', '-d', str(config.classes_dir()), Regex(r'@.*')]

        with FakeProcessContext(FakeProcess(expected)):
            java_compile(config, [])
Пример #23
0
    def _test_for_type(tmpdir, project_type, dist_dir):
        project_dir = Path(str(tmpdir))
        project = Project.from_dir(project_dir)
        code_dir = project_dir / Path('src/code')
        classes_dir = project_dir / Path('build/code/classes')
        doc_dir = project_dir / Path('build/code/javadoc')
        resources_dir = project_dir / Path('src/resources')
        output_dir = project_dir / Path(f'dist/{dist_dir}')
        expected = (code_dir, classes_dir, doc_dir, resources_dir, output_dir)

        classes_dir.mkdir(parents=True)
        doc_dir.mkdir(parents=True)

        with Options(project=project):
            config = JavaConfiguration()

        config.type = project_type
        result = _get_packaging_dirs(config)

        assert isinstance(result, tuple)
        assert result == expected
Пример #24
0
    def test_compound_substitutions(self):
        data = {
            'name': '${value}',
            'list': ['${value}', '2'],
            'tuple': ('${value}', '2'),
            'dict': {
                'nested': '${value}'
            }
        }
        variables = {
            'value': '1'
        }

        with Options(variables=variables):
            _resolve_vars_in_dict(data, {})

        assert data == {
            'name': '1',
            'list': ['1', '2'],
            'tuple': ['1', '2'],
            'dict': {'nested': '1'}
        }
Пример #25
0
 def test_out_quiet(self):
     with Options(quiet=True):
         with FakeEcho.simple('test') as fe:
             out('test')
     assert not fe.was_called()
Пример #26
0
    def _make_config(tmpdir) -> Tuple[Path, JavaConfiguration, PackageConfiguration]:
        directory = Path(str(tmpdir))
        project = Project.from_dir(directory)

        with Options(project=project):
            return directory, JavaConfiguration(), PackageConfiguration()