Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deveshks committed Apr 8, 2020
1 parent 6e048b2 commit 5600163
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/functional/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,30 @@ def test_download_prefer_binary_when_tarball_higher_than_wheel(script, data):
)


def test_prefer_binary_tarball_higher_than_wheel_req_file(script, data):
fake_wheel(data, 'source-0.8-py2.py3-none-any.whl')
script.scratch_path.joinpath("test-req.txt").write_text(textwrap.dedent("""
--prefer-binary
source
"""))
result = script.pip(
'download',
'-r', script.scratch_path / 'test-req.txt',
'--no-index',
'-f', data.packages,
'-d', '.'
)

assert (
Path('scratch') / 'source-0.8-py2.py3-none-any.whl'
in result.files_created
)
assert (
Path('scratch') / 'source-1.0.tar.gz'
not in result.files_created
)


def test_download_prefer_binary_when_wheel_doesnt_satisfy_req(script, data):
fake_wheel(data, 'source-0.8-py2.py3-none-any.whl')
script.scratch_path.joinpath("test-req.txt").write_text(textwrap.dedent("""
Expand All @@ -712,6 +736,30 @@ def test_download_prefer_binary_when_wheel_doesnt_satisfy_req(script, data):
)


def test_prefer_binary_when_wheel_doesnt_satisfy_req_req_file(script, data):
fake_wheel(data, 'source-0.8-py2.py3-none-any.whl')
script.scratch_path.joinpath("test-req.txt").write_text(textwrap.dedent("""
--prefer-binary
source>0.9
"""))

result = script.pip(
'download',
'--no-index',
'-f', data.packages,
'-d', '.',
'-r', script.scratch_path / 'test-req.txt'
)
assert (
Path('scratch') / 'source-1.0.tar.gz'
in result.files_created
)
assert (
Path('scratch') / 'source-0.8-py2.py3-none-any.whl'
not in result.files_created
)


def test_download_prefer_binary_when_only_tarball_exists(script, data):
result = script.pip(
'download',
Expand All @@ -726,6 +774,24 @@ def test_download_prefer_binary_when_only_tarball_exists(script, data):
)


def test_prefer_binary_when_only_tarball_exists_req_file(script, data):
script.scratch_path.joinpath("test-req.txt").write_text(textwrap.dedent("""
--prefer-binary
source
"""))
result = script.pip(
'download',
'--no-index',
'-f', data.packages,
'-d', '.',
'-r', script.scratch_path / 'test-req.txt'
)
assert (
Path('scratch') / 'source-1.0.tar.gz'
in result.files_created
)


@pytest.fixture(scope="session")
def shared_script(tmpdir_factory, script_factory):
tmpdir = Path(str(tmpdir_factory.mktemp("download_shared_script")))
Expand Down

0 comments on commit 5600163

Please sign in to comment.