diff --git a/tests/constants.py b/tests/constants.py index 0a33a278..3bbfa0bf 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -5,3 +5,6 @@ TEST_DATA_PATH = os.path.join(os.path.dirname(__file__), "test_data") MINIMAL_WHEELS_PATH = os.path.join(TEST_DATA_PATH, "minimal_wheels") PACKAGES_PATH = os.path.join(TEST_DATA_PATH, "packages") +PACKAGES_RELATIVE_PATH = os.path.relpath( + PACKAGES_PATH, os.path.commonpath([os.getcwd(), PACKAGES_PATH]) +) diff --git a/tests/test_pip_compat.py b/tests/test_pip_compat.py new file mode 100644 index 00000000..caa36499 --- /dev/null +++ b/tests/test_pip_compat.py @@ -0,0 +1,31 @@ +from __future__ import annotations + +import os +import tempfile + +import pytest + +from piptools._compat.pip_compat import parse_requirements +from piptools.repositories import PyPIRepository + +from .constants import PACKAGES_RELATIVE_PATH + + +@pytest.fixture +def repository(): + with tempfile.TemporaryDirectory() as cache_dir: + yield PyPIRepository([], cache_dir=cache_dir) + + +def test_parse_requirements_preserve_editable_relative(repository): + test_package_path = os.path.join(PACKAGES_RELATIVE_PATH, "small_fake_a") + + with tempfile.NamedTemporaryFile("w") as infile: + infile.write(f"-e {test_package_path}") + infile.flush() + [install_requirement] = parse_requirements( + infile.name, session=repository.session + ) + + assert install_requirement.link.url == test_package_path + assert install_requirement.link.file_path == test_package_path