From 09865d1d08bec680dd8108bac09fa59bf33be3d2 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Thu, 30 Mar 2023 23:47:30 +0200 Subject: [PATCH] Add support for pip==23.1 where refactored requirement options --- tests/conftest.py | 12 ++++++++-- tests/test_repository_local.py | 8 +++---- tests/test_sync.py | 40 +++++++++++++++------------------- tests/test_utils.py | 12 +++++----- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f0d3505e7..01849de91 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,7 +23,7 @@ from pip._vendor.packaging.version import Version from pip._vendor.pkg_resources import Requirement -from piptools._compat.pip_compat import uses_pkg_resources +from piptools._compat.pip_compat import PIP_VERSION, uses_pkg_resources from piptools.cache import DependencyCache from piptools.exceptions import NoCandidateFound from piptools.logging import log @@ -216,7 +216,15 @@ def base_resolver(depcache): @pytest.fixture def from_line(): - return install_req_from_line + def _from_line(*args, **kwargs): + if PIP_VERSION[:2] <= (23, 0): + hash_options = kwargs.pop("hash_options", {}) + options = kwargs.pop("options", {}) + options["hashes"] = hash_options + kwargs["options"] = options + return install_req_from_line(*args, **kwargs) + + return _from_line @pytest.fixture diff --git a/tests/test_repository_local.py b/tests/test_repository_local.py index ba7ea0399..e3645d6ed 100644 --- a/tests/test_repository_local.py +++ b/tests/test_repository_local.py @@ -23,8 +23,8 @@ def test_get_hashes_local_repository_cache_miss( def test_get_hashes_local_repository_cache_hit(from_line, repository): # Create an install requirement with the hashes included in its options - options = {"hashes": {"sha256": [entry.split(":")[1] for entry in EXPECTED]}} - req = from_line("small-fake-a==0.1", options=options) + hash_options = {"sha256": [entry.split(":")[1] for entry in EXPECTED]} + req = from_line("small-fake-a==0.1", hash_options=hash_options) existing_pins = {key_from_ireq(req): req} # Use fake repository so that we know the hashes are coming from cache @@ -44,8 +44,8 @@ def test_toggle_reuse_hashes_local_repository( capsys, pip_conf, from_line, pypi_repository, reuse_hashes, expected ): # Create an install requirement with the hashes included in its options - options = {"hashes": {"sha256": [entry.split(":")[1] for entry in NONSENSE]}} - req = from_line("small-fake-a==0.1", options=options) + hash_options = {"sha256": [entry.split(":")[1] for entry in NONSENSE]} + req = from_line("small-fake-a==0.1", hash_options=hash_options) existing_pins = {key_from_ireq(req): req} local_repository = LocalRequirementsRepository( diff --git a/tests/test_sync.py b/tests/test_sync.py index f084336d7..2eabaaa78 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -335,37 +335,31 @@ def test_sync_requirement_file_with_hashes( to_install = { from_line( "django==1.8", - options={ - "hashes": { - "sha256": [ - "6a03ce2feafdd193a0ba8a26dbd9773e" - "757d2e5d5e7933a62eac129813bd381a" - ] - } + hash_options={ + "sha256": [ + "6a03ce2feafdd193a0ba8a26dbd9773e" + "757d2e5d5e7933a62eac129813bd381a" + ] }, ), from_line( "click==4.0", - options={ - "hashes": { - "sha256": [ - "9ab1d313f99b209f8f71a629f3683303" - "0c8d7c72282cf7756834baf567dca662" - ] - } + hash_options={ + "sha256": [ + "9ab1d313f99b209f8f71a629f3683303" + "0c8d7c72282cf7756834baf567dca662" + ] }, ), from_line( "pytz==2017.2", - options={ - "hashes": { - "sha256": [ - "d1d6729c85acea542367138286862712" - "9432fba9a89ecbb248d8d1c7a9f01c67", - "f5c056e8f62d45ba8215e5cb8f50dfcc" - "b198b4b9fbea8500674f3443e4689589", - ] - } + hash_options={ + "sha256": [ + "d1d6729c85acea542367138286862712" + "9432fba9a89ecbb248d8d1c7a9f01c67", + "f5c056e8f62d45ba8215e5cb8f50dfcc" + "b198b4b9fbea8500674f3443e4689589", + ] }, ), } diff --git a/tests/test_utils.py b/tests/test_utils.py index 271a9273e..9d25899f1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -231,13 +231,11 @@ def test_dedup(): def test_get_hashes_from_ireq(from_line): ireq = from_line( "pytz==2017.2", - options={ - "hashes": { - "sha256": [ - "d1d6729c85acea5423671382868627129432fba9a89ecbb248d8d1c7a9f01c67", - "f5c056e8f62d45ba8215e5cb8f50dfccb198b4b9fbea8500674f3443e4689589", - ] - } + hash_options={ + "sha256": [ + "d1d6729c85acea5423671382868627129432fba9a89ecbb248d8d1c7a9f01c67", + "f5c056e8f62d45ba8215e5cb8f50dfccb198b4b9fbea8500674f3443e4689589", + ] }, ) expected = {