def test_sync(self, tmp_path): path = tmp_path / 'repo' syncer = git.git_syncer(str(path), "https://github.com/pkgcore/pkgrepo.git") assert syncer.sync() assert os.path.exists(os.path.join(path, 'metadata', 'layout.conf')) assert syncer.sync()
def test_uri_parse(self): assert git.git_syncer.parse_uri("git+http://dar") == "http://dar" with pytest.raises(base.UriError): git.git_syncer.parse_uri("git+://dar") # external binary doesn't exist with mock.patch('snakeoil.process.find_binary') as find_binary: find_binary.side_effect = CommandNotFound('git') with pytest.raises(base.SyncError): git.git_syncer(str(self.repo_path), "git+http://foon.com/dar") # fake that the external binary exists with mock.patch('snakeoil.process.find_binary') as find_binary: find_binary.return_value = 'git' for proto in ('http', 'https'): for uri in (f"git+{proto}://repo.git", f"{proto}://repo.git"): o = git.git_syncer(str(self.repo_path), uri) assert o.uri == f"{proto}://repo.git"
def test_basedir_is_file_error(self, spawn, find_binary, tmp_path): repo = tmp_path / "repo" repo.touch() syncer = git.git_syncer(str(repo), 'git://blah.git') # basedir gets '/' appended by default and stat errors out with pytest.raises(base.PathError) as excinfo: syncer.sync() # remove trailing slash from basedir and file check catches it instead syncer.basedir = str(repo) with pytest.raises(base.PathError) as excinfo: syncer.sync() assert "isn't a directory" in str(excinfo.value)
def test_sync(self, spawn): uri = 'git://foo.git' with mock.patch('snakeoil.process.find_binary', return_value='git'): syncer = git.git_syncer(str(self.repo_path), uri) # initial sync syncer.sync() assert spawn.call_args[0] == ([ 'git', 'clone', uri, str(self.repo_path) + os.path.sep ], ) assert spawn.call_args[1]['cwd'] is None # repo update self.repo_path.mkdir() syncer.sync() assert spawn.call_args[0] == (['git', 'pull'], ) assert spawn.call_args[1]['cwd'] == syncer.basedir
def test_quiet_sync(self, spawn, find_binary, tmp_path): syncer = git.git_syncer(str(tmp_path), 'git://blah.git') syncer.sync(verbosity=-1) assert '-q' == spawn.call_args[0][0][-1]
def test_basedir_perms_error(self, spawn, find_binary, tmp_path): syncer = git.git_syncer(str(tmp_path), 'git://blah.git') with pytest.raises(base.PathError): with mock.patch('os.stat') as stat: stat.side_effect = EnvironmentError('fake exception') syncer.sync()