diff options
author | 2019-02-11 15:20:57 -0600 | |
---|---|---|
committer | 2019-02-11 15:20:57 -0600 | |
commit | 7cb0b41beb965a35116655afd2bcadcdfab64dda (patch) | |
tree | 1dd8b613bca11350c992024563aaa10895ec47ae /tests/sync | |
parent | tests/sync/test_rsync: make faked sync tests work on systems without rsync in... (diff) | |
download | pkgcore-7cb0b41beb965a35116655afd2bcadcdfab64dda.tar.gz pkgcore-7cb0b41beb965a35116655afd2bcadcdfab64dda.tar.bz2 pkgcore-7cb0b41beb965a35116655afd2bcadcdfab64dda.zip |
tests/sync: simplify find_binary and spawn mocking
Diffstat (limited to 'tests/sync')
-rw-r--r-- | tests/sync/test_base.py | 6 | ||||
-rw-r--r-- | tests/sync/test_git.py | 28 | ||||
-rw-r--r-- | tests/sync/test_hg.py | 28 |
3 files changed, 29 insertions, 33 deletions
diff --git a/tests/sync/test_base.py b/tests/sync/test_base.py index 8d2e5e02..574d2adb 100644 --- a/tests/sync/test_base.py +++ b/tests/sync/test_base.py @@ -72,12 +72,11 @@ class TestExternalSyncer(object): assert o.binary == "/bin/sh" -@mock.patch('snakeoil.process.find_binary') +@mock.patch('snakeoil.process.find_binary', return_value='git') @mock.patch('snakeoil.process.spawn.spawn') class TestVcsSyncer(object): def test_basedir_perms_error(self, spawn, find_binary, tmp_path): - find_binary.return_value = 'git' syncer = git.git_syncer(str(tmp_path), 'git://blah.git') with pytest.raises(base.PathError): with mock.patch('os.stat') as stat: @@ -85,7 +84,6 @@ class TestVcsSyncer(object): syncer.sync() def test_basedir_is_file_error(self, spawn, find_binary, tmp_path): - find_binary.return_value = 'git' repo = tmp_path / "repo" repo.touch() syncer = git.git_syncer(str(repo), 'git://blah.git') @@ -101,7 +99,6 @@ class TestVcsSyncer(object): assert "isn't a directory" in str(excinfo.value) def test_verbose_sync(self, spawn, find_binary, tmp_path): - find_binary.return_value = 'git' syncer = git.git_syncer(str(tmp_path), 'git://blah.git') syncer.sync(verbosity=1) assert '-v' == spawn.call_args[0][0][-1] @@ -109,7 +106,6 @@ class TestVcsSyncer(object): assert '-vv' == spawn.call_args[0][0][-1] def test_quiet_sync(self, spawn, find_binary, tmp_path): - find_binary.return_value = 'git' syncer = git.git_syncer(str(tmp_path), 'git://blah.git') syncer.sync(verbosity=-1) assert '-q' == spawn.call_args[0][0][-1] diff --git a/tests/sync/test_git.py b/tests/sync/test_git.py index 883e3645..e620f3d5 100644 --- a/tests/sync/test_git.py +++ b/tests/sync/test_git.py @@ -29,22 +29,22 @@ class TestGitSyncer(object): o = valid("/tmp/foon", uri) assert o.uri == f"{proto}://repo.git" - def test_sync(self, tmp_path): + @mock.patch('snakeoil.process.find_binary', return_value='git') + @mock.patch('snakeoil.process.spawn.spawn') + def test_sync(self, spawn, find_binary, tmp_path): path = tmp_path / 'repo' uri = 'git://foo.git' - with mock.patch('snakeoil.process.spawn.spawn') as spawn, \ - mock.patch('snakeoil.process.find_binary') as find_binary: - find_binary.return_value = 'git' - syncer = git.git_syncer(str(path), uri) - # initial sync - syncer.sync() - assert spawn.call_args[0] == (['git', 'clone', uri, str(path) + os.path.sep],) - assert spawn.call_args[1]['cwd'] is None - # repo update - path.mkdir() - syncer.sync() - assert spawn.call_args[0] == (['git', 'pull'],) - assert spawn.call_args[1]['cwd'] == syncer.basedir + + syncer = git.git_syncer(str(path), uri) + # initial sync + syncer.sync() + assert spawn.call_args[0] == (['git', 'clone', uri, str(path) + os.path.sep],) + assert spawn.call_args[1]['cwd'] is None + # repo update + path.mkdir() + syncer.sync() + assert spawn.call_args[0] == (['git', 'pull'],) + assert spawn.call_args[1]['cwd'] == syncer.basedir @pytest.mark_network diff --git a/tests/sync/test_hg.py b/tests/sync/test_hg.py index 134287ef..6de39895 100644 --- a/tests/sync/test_hg.py +++ b/tests/sync/test_hg.py @@ -28,19 +28,19 @@ class TestHgSyncer(object): o = valid("/tmp/foon", "hg+http://dar") assert o.uri == "http://dar" - def test_sync(self, tmp_path): + @mock.patch('snakeoil.process.find_binary', return_value='hg') + @mock.patch('snakeoil.process.spawn.spawn') + def test_sync(self, spawn, find_binary, tmp_path): path = tmp_path / 'repo' uri = 'https://foo/bar' - with mock.patch('snakeoil.process.spawn.spawn') as spawn, \ - mock.patch('snakeoil.process.find_binary') as find_binary: - find_binary.return_value = 'hg' - syncer = hg.hg_syncer(str(path), f'hg+{uri}') - # initial sync - syncer.sync() - assert spawn.call_args[0] == (['hg', 'clone', uri, str(path) + os.path.sep],) - assert spawn.call_args[1]['cwd'] is None - # repo update - path.mkdir() - syncer.sync() - assert spawn.call_args[0] == (['hg', 'pull', '-u', uri],) - assert spawn.call_args[1]['cwd'] == syncer.basedir + + syncer = hg.hg_syncer(str(path), f'hg+{uri}') + # initial sync + syncer.sync() + assert spawn.call_args[0] == (['hg', 'clone', uri, str(path) + os.path.sep],) + assert spawn.call_args[1]['cwd'] is None + # repo update + path.mkdir() + syncer.sync() + assert spawn.call_args[0] == (['hg', 'pull', '-u', uri],) + assert spawn.call_args[1]['cwd'] == syncer.basedir |