|
| 1 | +import fnmatch |
| 2 | +import json |
| 3 | +from os.path import basename |
| 4 | + |
| 5 | +from pip._vendor.packaging.utils import canonicalize_name |
| 6 | +from pytest import mark |
| 7 | + |
| 8 | + |
| 9 | +def pip(script, command, requirement): |
| 10 | + return script.pip( |
| 11 | + command, '--prefer-binary', '--no-cache-dir', |
| 12 | + '--use-feature=fast-deps', requirement, |
| 13 | + allow_stderr_warning=True, |
| 14 | + ) |
| 15 | + |
| 16 | + |
| 17 | +def assert_installed(script, names): |
| 18 | + list_output = json.loads(script.pip('list', '--format=json').stdout) |
| 19 | + installed = {canonicalize_name(item['name']) for item in list_output} |
| 20 | + assert installed.issuperset(map(canonicalize_name, names)) |
| 21 | + |
| 22 | + |
| 23 | +@mark.network |
| 24 | +@mark.parametrize(('requirement', 'expected'), ( |
| 25 | + ('Paste==3.4.2', ('Paste', 'six')), |
| 26 | + ('Paste[flup]==3.4.2', ('Paste', 'six', 'flup')), |
| 27 | +)) |
| 28 | +def test_install_from_pypi(requirement, expected, script): |
| 29 | + pip(script, 'install', requirement) |
| 30 | + assert_installed(script, expected) |
| 31 | + |
| 32 | + |
| 33 | +@mark.network |
| 34 | +@mark.parametrize(('requirement', 'expected'), ( |
| 35 | + ('Paste==3.4.2', ('Paste-3.4.2-*.whl', 'six-*.whl')), |
| 36 | + ('Paste[flup]==3.4.2', ('Paste-3.4.2-*.whl', 'six-*.whl', 'flup-*')), |
| 37 | +)) |
| 38 | +def test_download_from_pypi(requirement, expected, script): |
| 39 | + result = pip(script, 'download', requirement) |
| 40 | + created = list(map(basename, result.files_created)) |
| 41 | + assert all(fnmatch.filter(created, f) for f in expected) |
| 42 | + |
| 43 | + |
| 44 | +@mark.network |
| 45 | +def test_build_wheel_with_deps(data, script): |
| 46 | + result = pip(script, 'wheel', data.packages/'requiresPaste') |
| 47 | + created = list(map(basename, result.files_created)) |
| 48 | + assert fnmatch.filter(created, 'requiresPaste-3.1.4-*.whl') |
| 49 | + assert fnmatch.filter(created, 'Paste-3.4.2-*.whl') |
| 50 | + assert fnmatch.filter(created, 'six-*.whl') |
0 commit comments