Exemplo n.º 1
0
    def test_handle_project_resolution(self, tmpdir):
        directory = Path(str(tmpdir))
        name = 'name.txt'
        path = directory / name
        mock_project = MagicMock()
        mock_project.get_config.return_value = None
        mock_cache = MagicMock()
        mock_cache.names = ['a name']
        mock_cache.get_project.return_value = mock_project
        language = Language({}, 'lang')

        language.project_as_dist_path = MagicMock(return_value=None)

        context = DependencyContext([], language,
                                    Configuration({}, [], mock_cache))

        assert context._handle_project_resolution('', name) is None

        language.project_as_dist_path = MagicMock(return_value=directory)

        assert context._handle_project_resolution('', name) is None

        path.write_text("")

        assert context._handle_project_resolution('', name) == path
Exemplo n.º 2
0
    def test_handle_project_resolution_missing_function(self):
        context = DependencyContext([], Language({}, 'lang'),
                                    Configuration({}, [], None))

        with pytest.raises(ValueError) as info:
            context._handle_project_resolution('', 'name.txt')

        assert info.value.args[0] == 'The language, lang, does not provide a means of resolving project-based ' \
                                     'dependencies.'
Exemplo n.º 3
0
    def test_fetch_file(self):
        remote_dep = _make_dep(location='remote')
        local_dep = _make_dep(location='local')
        project_dep = _make_dep(location='project')
        p1 = Path('path1')
        p2 = Path('path2')
        p3 = Path('path3')
        context = DependencyContext([], Language({}, 'lang'),
                                    Configuration({}, [], None))

        context._handle_remote_resolution = MagicMock(return_value=p1)
        context._handle_local_resolution = MagicMock(return_value=p2)
        context._handle_project_resolution = MagicMock(return_value=p3)

        r1 = context._fetch_file(remote_dep, 'remote.name')
        r2 = context._fetch_file(local_dep, 'local.name')
        r3 = context._fetch_file(project_dep, 'project.name')

        context._handle_remote_resolution.assert_called_once_with(
            'remote.name')
        context._handle_local_resolution.assert_called_once_with('local.name')
        context._handle_project_resolution.assert_called_once_with(
            'dep', 'project.name')

        assert r1 is p1
        assert r2 is p2
        assert r3 is p3