Skip to content

Commit

Permalink
PEP 440 direct reference tweak unit tests (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentJeannot authored Aug 2, 2021
1 parent 14afbf8 commit 5c9df27
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 52 deletions.
113 changes: 62 additions & 51 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import shutil
import subprocess
import sys
from pathlib import Path
from textwrap import dedent
from unittest import mock

Expand Down Expand Up @@ -513,40 +512,34 @@ def test_locally_available_editable_package_is_not_archived_in_cache_dir(
@pytest.mark.parametrize(
("line", "dependency"),
(
# zip URL
# use pip-tools version prior to its use of setuptools_scm,
# which is incompatible with https: install
(
pytest.param(
"https://github.com/jazzband/pip-tools/archive/"
"7d86c8d3ecd1faa6be11c7ddc6b29a30ffd1dae3.zip",
"\nclick==",
id="Zip URL",
),
# scm URL
(
pytest.param(
"git+git://github.com/jazzband/pip-tools@"
"7d86c8d3ecd1faa6be11c7ddc6b29a30ffd1dae3",
"\nclick==",
id="VCS URL",
),
# wheel URL
(
pytest.param(
"https://files.pythonhosted.org/packages/06/96/"
"89872db07ae70770fba97205b0737c17ef013d0d1c790"
"899c16bb8bac419/pip_tools-3.6.1-py2.py3-none-any.whl",
"\nclick==",
id="Wheel URL",
),
(
pytest.param(
"pytest-django @ git+git://github.com/pytest-dev/pytest-django"
"@21492afc88a19d4ca01cd0ac392a5325b14f95c7"
"#egg=pytest-django",
"git+git://github.com/pytest-dev/pytest-django"
"@21492afc88a19d4ca01cd0ac392a5325b14f95c7#egg=pytest-django",
),
(
"git+git://github.com/open-telemetry/opentelemetry-python.git"
"@v1.3.0#subdirectory=opentelemetry-api"
"&egg=opentelemetry-api",
"git+git://github.com/open-telemetry/opentelemetry-python.git"
"@v1.3.0#subdirectory=opentelemetry-api",
id="VCS with direct reference and egg",
),
),
)
Expand All @@ -565,25 +558,23 @@ def test_url_package(runner, line, dependency, generate_hashes):
@pytest.mark.parametrize(
("line", "dependency", "rewritten_line"),
(
# file:// wheel URL
(
pytest.param(
path_to_url(
os.path.join(
MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"
)
),
"\nsmall-fake-a==0.1",
None,
id="Wheel URI",
),
# file:// directory
(
pytest.param(
path_to_url(os.path.join(PACKAGES_PATH, "small_fake_with_deps")),
"\nsmall-fake-a==0.1",
None,
id="Local project URI",
),
# bare path
# will be rewritten to file:// URL
(
pytest.param(
os.path.join(
MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"
),
Expand All @@ -593,11 +584,38 @@ def test_url_package(runner, line, dependency, generate_hashes):
MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"
)
),
id="Bare path to file URI",
),
pytest.param(
os.path.join(
MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"
),
"\nsmall-fake-with-deps @ "
+ path_to_url(
os.path.join(
MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"
)
),
"\nsmall-fake-with-deps @ "
+ path_to_url(
os.path.join(
MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"
)
),
id="Local project with absolute URI",
),
pytest.param(
path_to_url(os.path.join(PACKAGES_PATH, "small_fake_with_subdir"))
+ "#subdirectory=subdir&egg=small_fake_a",
path_to_url(os.path.join(PACKAGES_PATH, "small_fake_with_subdir"))
+ "#subdirectory=subdir&egg=small_fake_a",
None,
id="Local project with subdirectory",
),
),
)
@pytest.mark.parametrize("generate_hashes", ((True,), (False,)))
def test_local_url_package(
def test_local_file_uri_package(
pip_conf, runner, line, dependency, rewritten_line, generate_hashes
):
if rewritten_line is None:
Expand All @@ -612,38 +630,31 @@ def test_local_url_package(
assert dependency in out.stderr


@pytest.mark.parametrize(
("line", "dependency", "rewritten_line"),
(
pytest.param(
os.path.join(
MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"
),
"\nfile:small_fake_with_deps-0.1-py2.py3-none-any.whl",
"file:small_fake_with_deps-0.1-py2.py3-none-any.whl",
id="Relative URL",
def test_relative_file_uri_package(pip_conf, runner):
# Copy wheel into temp dir
shutil.copy(
os.path.join(
MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"
),
pytest.param(
os.path.join(
MINIMAL_WHEELS_PATH, "small_fake_with_deps-0.1-py2.py3-none-any.whl"
),
"\nsmall-fake-with-deps"
" @ file://{absolute_path}/small_fake_with_deps-0.1-py2.py3-none-any.whl",
"small-fake-with-deps"
" @ file://{absolute_path}/small_fake_with_deps-0.1-py2.py3-none-any.whl",
id="Relative URL",
),
),
)
def test_relative_url_package(pip_conf, runner, line, dependency, rewritten_line):
dependency = dependency.format(absolute_path=Path(".").absolute())
rewritten_line = rewritten_line.format(absolute_path=Path(".").absolute())
shutil.copy(line, ".")
".",
)
with open("requirements.in", "w") as req_in:
req_in.write(dependency)
req_in.write("file:small_fake_with_deps-0.1-py2.py3-none-any.whl")
out = runner.invoke(cli, ["-n", "--rebuild"])
assert out.exit_code == 0
assert rewritten_line in out.stderr
assert "file:small_fake_with_deps-0.1-py2.py3-none-any.whl" in out.stderr


def test_direct_reference_with_extras(runner):
with open("requirements.in", "w") as req_in:
req_in.write(
"piptools[testing,coverage] @ git+https://github.com/jazzband/pip-tools@6.2.0"
)
out = runner.invoke(cli, ["-n", "--rebuild"])
assert out.exit_code == 0
assert "pip-tools @ git+https://github.com/jazzband/pip-tools@6.2.0" in out.stderr
assert "pytest==" in out.stderr
assert "pytest-cov==" in out.stderr


def test_input_file_without_extension(pip_conf, runner):
Expand Down
1 change: 0 additions & 1 deletion tests/test_data/packages/fake_with_deps/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
"SQLAlchemy!=0.9.5,<2.0.0,>=0.7.8,>=1.0.0",
"python-memcached>=1.57,<2.0",
"xmltodict<=0.11,>=0.4.6",
"requests @ git+git://github.com/psf/requests@v2.25.1",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup

setup(name="small_fake_a", version=0.1)

0 comments on commit 5c9df27

Please sign in to comment.