|
6 | 6 |
|
7 | 7 | from setuptools.extern import six |
8 | 8 | from setuptools.extern.six.moves import urllib, http_client |
| 9 | +import mock |
9 | 10 |
|
10 | 11 | import pkg_resources |
11 | 12 | import setuptools.package_index |
@@ -223,6 +224,44 @@ def test_egg_fragment(self): |
223 | 224 | assert dists[0].version == '' |
224 | 225 | assert dists[1].version == vc |
225 | 226 |
|
| 227 | + def test_download_git_with_rev(self, tmpdir): |
| 228 | + url = 'git+https://github.example/group/project@master#egg=foo' |
| 229 | + index = setuptools.package_index.PackageIndex() |
| 230 | + |
| 231 | + with mock.patch("os.system") as os_system_mock: |
| 232 | + result = index.download(url, str(tmpdir)) |
| 233 | + |
| 234 | + os_system_mock.assert_called() |
| 235 | + |
| 236 | + expected_dir = str(tmpdir / 'project@master') |
| 237 | + expected = ( |
| 238 | + 'git clone --quiet ' |
| 239 | + 'https://github.example/group/project {expected_dir}' |
| 240 | + ).format(**locals()) |
| 241 | + first_call_args = os_system_mock.call_args_list[0][0] |
| 242 | + assert first_call_args == (expected,) |
| 243 | + |
| 244 | + tmpl = '(cd {expected_dir} && git checkout --quiet master)' |
| 245 | + expected = tmpl.format(**locals()) |
| 246 | + assert os_system_mock.call_args_list[1][0] == (expected,) |
| 247 | + assert result == expected_dir |
| 248 | + |
| 249 | + def test_download_git_no_rev(self, tmpdir): |
| 250 | + url = 'git+https://github.example/group/project#egg=foo' |
| 251 | + index = setuptools.package_index.PackageIndex() |
| 252 | + |
| 253 | + with mock.patch("os.system") as os_system_mock: |
| 254 | + result = index.download(url, str(tmpdir)) |
| 255 | + |
| 256 | + os_system_mock.assert_called() |
| 257 | + |
| 258 | + expected_dir = str(tmpdir / 'project') |
| 259 | + expected = ( |
| 260 | + 'git clone --quiet ' |
| 261 | + 'https://github.example/group/project {expected_dir}' |
| 262 | + ).format(**locals()) |
| 263 | + os_system_mock.assert_called_once_with(expected) |
| 264 | + |
226 | 265 |
|
227 | 266 | class TestContentCheckers: |
228 | 267 | def test_md5(self): |
|
0 commit comments