diff --git a/src/poetry/core/packages/specification.py b/src/poetry/core/packages/specification.py index 2b0092136..c3bcde74e 100644 --- a/src/poetry/core/packages/specification.py +++ b/src/poetry/core/packages/specification.py @@ -71,9 +71,15 @@ def source_subdirectory(self) -> str | None: def features(self) -> frozenset[str]: return self._features - def is_same_package_as(self, other: PackageSpecification) -> bool: - if other.complete_name != self.complete_name: - return False + def is_same_package_as( + self, other: PackageSpecification, *, ignore_features: bool = False + ) -> bool: + if ignore_features: + if other.name != self.name: + return False + else: + if other.complete_name != self.complete_name: + return False if self._source_type: if self._source_type != other.source_type: diff --git a/tests/packages/test_specification.py b/tests/packages/test_specification.py new file mode 100644 index 000000000..ff764ca5f --- /dev/null +++ b/tests/packages/test_specification.py @@ -0,0 +1,37 @@ +from __future__ import annotations + +import pytest + +from poetry.core.packages.specification import PackageSpecification + + +@pytest.mark.parametrize( + "spec1, spec2, expected_exact, expected_ignore_features", + [ + (PackageSpecification("a"), PackageSpecification("a"), True, True), + (PackageSpecification("a"), PackageSpecification("ab"), False, False), + ( + PackageSpecification("a"), + PackageSpecification("a", features=["c"]), + False, + True, + ), + ( + PackageSpecification("a", features=["c"]), + PackageSpecification("a", features=["c", "d"]), + False, + True, + ), + ], +) +def test_is_same_package_ignore_features( + spec1: PackageSpecification, + spec2: PackageSpecification, + expected_exact: bool, + expected_ignore_features: bool, +) -> None: + assert spec1.is_same_package_as(spec2) == expected_exact + assert ( + spec1.is_same_package_as(spec2, ignore_features=True) + == expected_ignore_features + )