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='')
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)
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)
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()
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' )
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' )
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
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
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
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)
def source(): return Source(type='git', repo='repo', name='name', rev='rev', link='link')
def source(): return Source('repo', 'name', rev='rev', link='link')