Exemplo n.º 1
0
 def test_init_error(self):
     """Verify the repository, name, and rev are required."""
     with pytest.raises(ValueError):
         Source('', name='mock_name', rev='master')
     with pytest.raises(ValueError):
         Source('http://mock.git', name='', rev='master')
     with pytest.raises(ValueError):
         Source('http://mock.git', name='mock_name', rev='')
Exemplo n.º 2
0
    def test_lt(self):
        sources = [
            Source('http://github.com/owner/123.git'),
            Source('bbb', name='456'),
            Source('ccc', '456'),
            Source('BBB', 'AAA'),
            Source('AAA', 'AAA'),
        ]

        assert sources == sorted(sources)
Exemplo n.º 3
0
    def test_lt(self):
        sources = [
            Source(type='git', repo='http://github.com/owner/123.git', name=None),
            Source(type='git', repo='bbb', name='456'),
            Source(type='git', repo='ccc', name='456'),
            Source(type='git', repo='BBB', name='AAA'),
            Source(type='git', repo='AAA', name='AAA'),
        ]

        assert sources == sorted(sources)
Exemplo n.º 4
0
    def test_update_files_invalid_repo(self, mock_clone,
                                       mock_is_fetch_required, mock_fetch,
                                       mock_update):
        """Verify update_files throws exception on invalid repo when not forced"""
        source = Source('git', 'repo', 'name', rev='rev', link='link')

        with pytest.raises(Exception):
            source.update_files()

        mock_clone.assert_not_called()
        mock_is_fetch_required.assert_not_called()
        mock_fetch.assert_not_called()
        mock_update.assert_not_called()
Exemplo n.º 5
0
    def test_update_files_rebuild_git(
        self, mock_clone, mock_rebuild, mock_is_fetch_required, mock_fetch, mock_update
    ):
        """Verify update_files rebuilds when invalid repo and force is passed"""
        source = Source(type='git', repo='repo', name='name', rev='rev', link='link')
        source.update_files(force=True)

        mock_clone.assert_not_called()
        mock_rebuild.assert_called_once_with('git', 'repo')
        mock_is_fetch_required.assert_not_called()
        mock_fetch.assert_called_once_with('git', 'repo', 'name', rev='rev')
        mock_update.assert_called_once_with(
            'git', 'repo', 'name', clean=True, fetch=True, rev='rev'
        )
Exemplo n.º 6
0
    def test_update_files(
        self, mock_clone, mock_is_fetch_required, mock_fetch, mock_update
    ):
        """Verify update_files when path does not exist"""
        source = Source(type='git', repo='repo', name='name', rev='rev', link='link')
        source.update_files()

        mock_clone.assert_called_once_with(
            'git', 'repo', 'name', rev='rev', sparse_paths=[]
        )
        mock_is_fetch_required.assert_called_once_with('git', 'rev')
        mock_fetch.assert_called_once_with('git', 'repo', 'name', rev='rev')
        mock_update.assert_called_once_with(
            'git', 'repo', 'name', clean=True, fetch=False, rev='rev'
        )
Exemplo n.º 7
0
    def test_init_link(self):
        """Verify the link can be set."""
        source = Source(
            type='git', repo='http://mock.git', name='mock_name', link='mock/link'
        )

        assert 'mock/link' == source.link
Exemplo n.º 8
0
    def test_init_rev(self):
        """Verify the revision can be customized."""
        source = Source(
            type='git', repo='http://mock.git', name='mock_name', rev='v1.0'
        )

        assert 'v1.0' == source.rev
Exemplo n.º 9
0
    def test_init_defaults(self):
        """Verify a source has a default revision."""
        source = Source('http://example.com/foo/bar.git')

        assert 'http://example.com/foo/bar.git' == source.repo
        assert 'bar' == source.name
        assert 'master' == source.rev
        assert None is source.link
Exemplo n.º 10
0
    def test_init_name_as_path(self, tmp_path):
        """Verify the name can be a path."""
        source = Source(type='git', repo='http://example.com', name=tmp_path)

        assert isinstance(source.name, str)
Exemplo n.º 11
0
def source():
    return Source(type='git', repo='repo', name='name', rev='rev', link='link')
Exemplo n.º 12
0
def source():
    return Source('repo', 'name', rev='rev', link='link')