From 24fe4c29ac505b7829eb00a2bddc2959bd7d836b 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 | 53 ++++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/tests/utils/test_dependency_specification.py b/tests/utils/test_dependency_specification.py index 8b1c1dfd1b1..c628398df0b 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.dependency_specification import DependencySpec @@ -68,12 +70,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"}), ( @@ -104,7 +132,9 @@ ], ) def test_parse_dependency_specification( - requirement: str, specification: DependencySpec, mocker: MockerFixture + requirement: str, + specification: DependencySpec | Collection[DependencySpec], + mocker: MockerFixture, ) -> None: original = Path.exists @@ -115,6 +145,11 @@ def _mock(self: Path) -> bool: mocker.patch("pathlib.Path.exists", _mock) - assert not DeepDiff( - parse_dependency_specification(requirement), specification, ignore_order=True + if isinstance(specification, dict): + specification = [specification] + assert any( + not DeepDiff( + parse_dependency_specification(requirement), spec, ignore_order=True + ) + for spec in specification )