From 14b7b8db984dad518b32450f5cc289e9b76ed731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Sun, 30 Apr 2023 14:45:41 +0200 Subject: [PATCH] tests: ensure forward compatibility with python-poetry/poetry-core#402 --- tests/utils/test_dependency_specification.py | 55 ++++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/tests/utils/test_dependency_specification.py b/tests/utils/test_dependency_specification.py index a782a55924e..96bd9595e3a 100644 --- a/tests/utils/test_dependency_specification.py +++ b/tests/utils/test_dependency_specification.py @@ -11,6 +11,8 @@ if TYPE_CHECKING: + from collections.abc import Collection + from pytest_mock import MockerFixture from poetry.utils.cache import ArtifactCache @@ -69,12 +71,38 @@ ), ( 'requests [security,tests] >= 2.8.1, == 2.8.* ; python_version < "2.7"', - { - "name": "requests", - "markers": 'python_version < "2.7"', - "version": ">=2.8.1,<2.9.0", - "extras": ["security", "tests"], - }, + ( # allow several equivalent versions to make test more robust + { + "name": "requests", + "markers": 'python_version < "2.7"', + "version": ">=2.8.1,<2.9", + "extras": ["security", "tests"], + }, + { + "name": "requests", + "markers": 'python_version < "2.7"', + "version": ">=2.8.1,<2.9.0", + "extras": ["security", "tests"], + }, + { + "name": "requests", + "markers": 'python_version < "2.7"', + "version": ">=2.8.1,<2.9.dev0", + "extras": ["security", "tests"], + }, + { + "name": "requests", + "markers": 'python_version < "2.7"', + "version": ">=2.8.1,<2.9.0.dev0", + "extras": ["security", "tests"], + }, + { + "name": "requests", + "markers": 'python_version < "2.7"', + "version": ">=2.8.1,!=2.8.*", + "extras": ["security", "tests"], + }, + ), ), ("name (>=3,<4)", {"name": "name", "version": ">=3,<4"}), ( @@ -106,7 +134,7 @@ ) def test_parse_dependency_specification( requirement: str, - specification: DependencySpec, + specification: DependencySpec | Collection[DependencySpec], mocker: MockerFixture, artifact_cache: ArtifactCache, ) -> None: @@ -119,8 +147,13 @@ def _mock(self: Path) -> bool: mocker.patch("pathlib.Path.exists", _mock) - assert not DeepDiff( - RequirementsParser(artifact_cache=artifact_cache).parse(requirement), - specification, - ignore_order=True, + if isinstance(specification, dict): + specification = [specification] + assert any( + not DeepDiff( + RequirementsParser(artifact_cache=artifact_cache).parse(requirement), + spec, + ignore_order=True, + ) + for spec in specification )