|
3 | 3 | import urllib.error
|
4 | 4 | import http.client
|
5 | 5 | from inspect import cleandoc
|
6 |
| -from unittest import mock |
7 | 6 |
|
8 | 7 | import pytest
|
9 | 8 |
|
@@ -171,41 +170,38 @@ def test_egg_fragment(self):
|
171 | 170 | assert dists[0].version == ''
|
172 | 171 | assert dists[1].version == vc
|
173 | 172 |
|
174 |
| - def test_download_git_with_rev(self, tmpdir): |
| 173 | + def test_download_git_with_rev(self, tmpdir, fp): |
175 | 174 | url = 'git+https://github.example/group/project@master#egg=foo'
|
176 | 175 | index = setuptools.package_index.PackageIndex()
|
177 | 176 |
|
178 |
| - with mock.patch("os.system") as os_system_mock: |
179 |
| - result = index.download(url, str(tmpdir)) |
| 177 | + expected_dir = str(tmpdir / 'project@master') |
| 178 | + fp.register([ |
| 179 | + 'git', |
| 180 | + 'clone', |
| 181 | + '--quiet', |
| 182 | + 'https://github.example/group/project', |
| 183 | + expected_dir, |
| 184 | + ]) |
| 185 | + fp.register(['git', '-C', expected_dir, 'checkout', '--quiet', 'master']) |
180 | 186 |
|
181 |
| - os_system_mock.assert_called() |
| 187 | + result = index.download(url, str(tmpdir)) |
182 | 188 |
|
183 |
| - expected_dir = str(tmpdir / 'project@master') |
184 |
| - expected = ( |
185 |
| - 'git clone --quiet ' 'https://github.example/group/project {expected_dir}' |
186 |
| - ).format(**locals()) |
187 |
| - first_call_args = os_system_mock.call_args_list[0][0] |
188 |
| - assert first_call_args == (expected,) |
189 |
| - |
190 |
| - tmpl = 'git -C {expected_dir} checkout --quiet master' |
191 |
| - expected = tmpl.format(**locals()) |
192 |
| - assert os_system_mock.call_args_list[1][0] == (expected,) |
193 | 189 | assert result == expected_dir
|
| 190 | + assert len(fp.calls) == 2 |
194 | 191 |
|
195 |
| - def test_download_git_no_rev(self, tmpdir): |
| 192 | + def test_download_git_no_rev(self, tmpdir, fp): |
196 | 193 | url = 'git+https://github.example/group/project#egg=foo'
|
197 | 194 | index = setuptools.package_index.PackageIndex()
|
198 | 195 |
|
199 |
| - with mock.patch("os.system") as os_system_mock: |
200 |
| - result = index.download(url, str(tmpdir)) |
201 |
| - |
202 |
| - os_system_mock.assert_called() |
203 |
| - |
204 | 196 | expected_dir = str(tmpdir / 'project')
|
205 |
| - expected = ( |
206 |
| - 'git clone --quiet ' 'https://github.example/group/project {expected_dir}' |
207 |
| - ).format(**locals()) |
208 |
| - os_system_mock.assert_called_once_with(expected) |
| 197 | + fp.register([ |
| 198 | + 'git', |
| 199 | + 'clone', |
| 200 | + '--quiet', |
| 201 | + 'https://github.example/group/project', |
| 202 | + expected_dir, |
| 203 | + ]) |
| 204 | + index.download(url, str(tmpdir)) |
209 | 205 |
|
210 | 206 | def test_download_svn(self, tmpdir):
|
211 | 207 | url = 'svn+https://svn.example/project#egg=foo'
|
|
0 commit comments