示例#1
0
    def test_create_project_from_bad_file(self):
        file = get_test_path('project') / 'bad_project.yaml'

        with pytest.raises(ValueError) as info:
            Project.from_file(file)

        assert info.value.args[0] == "Bad project file format: #/info/name violates the \"pattern\" constraint: it " \
                                     "does not match the '[a-zA-Z0-9-_]+' pattern."
示例#2
0
    def test_get_module_set(self):
        project = Project.from_file(Path(get_test_path('project') / 'good_project.yaml'))

        assert isinstance(project.get_module_set(), ModuleSet)

        project = Project.from_file(Path(get_test_path('project') / 'good_project_unknown_language.yaml'))

        assert project.get_module_set() is None
示例#3
0
    def test_get_unknown_languages(self):
        project = Project.from_file(Path(get_test_path('project') / 'good_project.yaml'))

        assert project.get_unknown_languages() is None

        project = Project.from_file(Path(get_test_path('project') / 'good_project_unknown_language.yaml'))

        assert project.get_unknown_languages() == ['python']
示例#4
0
    def test_has_unknown_languages(self):
        project = Project.from_file(Path(get_test_path('project') / 'good_project.yaml'))

        assert project.has_unknown_languages() is False

        project = Project.from_file(Path(get_test_path('project') / 'good_project_unknown_language.yaml'))

        assert project.has_unknown_languages() is True
示例#5
0
    def test_prefetch_module_set(self):
        project = Project.from_file(Path(get_test_path('project') / 'good_project_unknown_language.yaml'))

        assert project._info['languages'] == ['java', 'python']
        assert project._module_set is None
        assert project._unknown_languages == ['python']

        project = Project.from_file(Path(get_test_path('project') / 'good_project.yaml'))

        assert project._info['languages'] == ['java']
        assert isinstance(project._module_set, ModuleSet)
        assert project._unknown_languages is None
示例#6
0
    def test_format_args_task_config(self):
        config = {'lib_target': 'library'}
        project = Project.from_dir(Path('/path/to/project'))
        engine = Engine(project)
        module = Language(None, 'java')
        task = Task('myTask', func_task_config)
        mock_get_config = MagicMock()

        mock_get_config.return_value = config

        project.get_config = mock_get_config

        # noinspection PyProtectedMember
        args, kwargs = engine._format_args(module, task)

        assert args == [config]
        assert kwargs == {}

        task.function = func_named_task_config

        # noinspection PyProtectedMember
        args, kwargs = engine._format_args(module, task)

        assert args == []
        assert kwargs == {'task_config': config}
示例#7
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, [])
示例#8
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')
示例#9
0
    def test_create_config_object(self):
        project = Project.from_dir(Path('/path/to/dir'))

        thing = project._create_config_object(Bob, None)

        assert thing == Bob()

        thing = project._create_config_object(Bob, 'bogus')

        assert thing == Bob()

        thing = project._create_config_object(Bob, {})

        assert thing == Bob()

        thing = project._create_config_object(Bob, {'name': 'Larry', 'extra': True})

        assert thing == Bob('Larry')
        assert hasattr(thing, 'extra') is True
        assert thing.extra is True

        thing = project._create_config_object(Bob, {'age': 12})

        assert thing == Bob(age=12)

        thing = project._create_config_object(Bob, {'name': 'Larry', 'age': 12})

        assert thing == Bob('Larry', 12)
示例#10
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')
示例#11
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)
示例#12
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.'
示例#13
0
    def test_plain_project_dir(self, tmpdir):
        root = Path(tmpdir)
        expected = root / 'dir'
        project = Project.from_dir(root)

        directory = project.project_dir(Path('dir'))

        assert directory == expected
示例#14
0
    def test_get_nonexistent_config(self):
        project = Project.from_dir(Path('/path/to/dir'))

        config = project.get_config('testing')

        assert config == {}
        # Make sure caching works.
        assert project.get_config('testing') is config
示例#15
0
    def test_project(self, tmpdir):
        options = GlobalOptions()
        project = Project.from_dir(Path(tmpdir))

        assert options.project() is None

        options.set_project(project)

        assert options.project() is project
示例#16
0
    def test_engine_construction(self):
        project = Project.from_dir(Path('/path/to/project'))
        engine = Engine(project)

        validate_attributes(engine, {
            '_project': project,
            '_module_set': project.get_module_set(),
            '_rc': 0
        })
示例#17
0
    def test_project_description(self):
        project = Project.from_dir(Path('/path/to/dir'))

        assert project.description == 'dir'

        # noinspection PyProtectedMember
        project._info['title'] = 'The Title'

        assert project.description == 'dir -- The Title'
示例#18
0
    def test_get_var_value(self):
        project = Project.from_dir(Path('/path/to/dir'))

        assert project.get_var_value('variable') is None

        # noinspection PyProtectedMember
        project._content['vars'] = {'variable': 'the value'}

        assert project.get_var_value('variable') == 'the value'
示例#19
0
 def test_create_project_from_directory(self):
     path = Path('/path/to/dir')
     project = Project.from_dir(path)
     # noinspection PyProtectedMember
     assert project._content == {
         'info': {
             'name': 'dir',
             'version': '0.0.1',
             'languages': []
         },
         'vars': {}
     }
     project = Project.from_dir(path, name='test')
     # noinspection PyProtectedMember
     assert project._content == {
         'info': {
             'name': 'test',
             'version': '0.0.1',
             'languages': []
         },
         'vars': {}
     }
     project = Project.from_dir(path, version='1.2.3')
     # noinspection PyProtectedMember
     assert project._content == {
         'info': {
             'name': 'dir',
             'version': '1.2.3',
             'languages': []
         },
         'vars': {}
     }
     project = Project.from_dir(path, language='java')
     # noinspection PyProtectedMember
     assert project._content == {
         'info': {
             'name': 'dir',
             'version': '0.0.1',
             'languages': ['java']
         },
         'vars': {}
     }
示例#20
0
    def test_format_args_no_args(self):
        project = Project.from_dir(Path('/path/to/project'))
        engine = Engine(project)
        module = Language(None, 'java')
        task = Task('myTask', func_no_args)

        # noinspection PyProtectedMember
        args, kwargs = engine._format_args(module, task)

        assert args == []
        assert kwargs == {}
示例#21
0
    def __init__(self, project: Project):
        """
        A function to create an instance of the ``Engine`` class.  This class is
        designed to be created once during the execution of the command line.

        :param project: the project that provides our execution definitions and
        context.
        """
        self._project = project
        self._module_set = project.get_module_set()
        self._rc = 0
示例#22
0
 def test_create_project_from_good_file(self):
     file = get_test_path('project') / 'good_project.yaml'
     project = Project.from_file(file)
     # noinspection PyProtectedMember
     assert project._content == {
         'info': {
             'name': 'test-project',
             'title': 'A Glorious Implementation',
             'version': '1.0.1',
             'languages': ['java']
         },
         'vars': {'n1': 'v1'}
     }
示例#23
0
    def test_get_config_with_schema(self):
        project = Project.from_dir(Path('/path/to/dir'))
        int_validator = SchemaValidator({'type': 'integer'})
        str_validator = SchemaValidator({'type': 'string'})
        # noinspection PyProtectedMember
        project._content['name'] = 'Bob'

        with pytest.raises(ValueError) as info:
            project.get_config('name', schema=int_validator)

        assert info.value.args[0] == 'Configuration for "name" is not valid: #/name violates the "type" constraint: ' \
                                     'it is not an integer.'
        assert project.get_config('name', str_validator) == 'Bob'
示例#24
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')
示例#25
0
    def test_get_tasks_in_execution_order_independent(self):
        project = Project.from_dir(Path('/path/to/project'), language='java')
        ms = project.get_module_set()
        engine = Engine(project)

        with patch('builder.engine.global_options') as go:
            go.tasks.return_value = ['test', 'compile']
            go.independent_tasks.return_value = True

            # noinspection PyProtectedMember
            tasks = engine._get_tasks_in_execution_order()

        assert tasks == [ms.get_task('test'), ms.get_task('compile')]
示例#26
0
    def test_get_task_config(self):
        config = {'field': 'value'}
        project = Project.from_dir(Path('/path/to/project'))
        engine = Engine(project)
        task = Task('myTask', None)
        mock_get_config = MagicMock()

        mock_get_config.return_value = config

        project.get_config = mock_get_config

        # noinspection PyProtectedMember
        assert engine._get_task_config(task) == config
        assert mock_get_config.mock_calls == [call('myTask', None, None)]
示例#27
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, [])
示例#28
0
    def test_get_language_config(self):
        config = {'lib_target': 'library'}
        project = Project.from_dir(Path('/path/to/project'))
        engine = Engine(project)
        module = Language(None, 'java')
        mock_get_config = MagicMock()

        mock_get_config.return_value = config

        project.get_config = mock_get_config

        # noinspection PyProtectedMember
        assert engine._get_language_config(module) == config
        assert mock_get_config.mock_calls == [call('java', None, None)]
示例#29
0
    def test_get_config_with_class(self):
        project = Project.from_dir(Path('/path/to/dir'))
        # noinspection PyProtectedMember
        project._content['bob'] = {
            'name': 'Bob',
            'age': 12
        }

        thing = project.get_config('bob', config_class=Bob)

        assert isinstance(thing, Bob) is True
        assert thing.name == 'Bob'
        assert thing.age == 12
        assert project.get_config('bob') is thing
示例#30
0
    def test_required_project_dir(self, tmpdir):
        root = Path(tmpdir)
        expected = root / 'dir'
        project = Project.from_dir(root)

        with pytest.raises(ValueError) as error:
            project.project_dir(Path('dir'), required=True)

        assert error.value.args[0] == f'Required directory, {expected}, does not exist or is not a directory.'

        expected.mkdir()

        directory = project.project_dir(Path('dir'), required=True)

        assert directory == expected