Skip to content

Commit

Permalink
Add explanatory comment and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering committed Jul 3, 2022
1 parent d4d8727 commit 3137990
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ def __eq__(self, other: object) -> bool:
if not isinstance(other, Dependency):
return NotImplemented

# "constraint" is implicitly given for direct origin dependencies and might not
# be set yet ("*"). Thus, it shouldn't be used to determine if two direct origin
# dependencies are equal.
# Calling is_direct_origin() for one dependency is sufficient because
# super().__eq__() returns False for different origins.
return super().__eq__(other) and (
self._constraint == other.constraint or self.is_direct_origin()
)
Expand Down
28 changes: 28 additions & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,34 @@ def test_create_from_pep_508_url_with_activated_extras() -> None:
assert dependency.extras == {"fred", "bar"}


@pytest.mark.parametrize(
"dependency1, dependency2, expected",
[
(Dependency("a", "1.0"), Dependency("a", "1.0"), True),
(Dependency("a", "1.0"), Dependency("a", "1.0.1"), False),
(Dependency("a", "1.0"), Dependency("a1", "1.0"), False),
(Dependency("a", "1.0"), Dependency("a", "1.0", source_type="file"), False),
# constraint is implicitly given for direct origin dependencies,
# but might not be set
(
Dependency("a", "1.0", source_type="file"),
Dependency("a", "*", source_type="file"),
True,
),
# constraint is not implicit for non direct origin dependencies
(Dependency("a", "1.0"), Dependency("a", "*"), False),
(
Dependency("a", "1.0", source_type="legacy"),
Dependency("a", "*", source_type="legacy"),
False,
),
],
)
def test_eq(dependency1: Dependency, dependency2: Dependency, expected: bool) -> None:
assert (dependency1 == dependency2) is expected
assert (dependency2 == dependency1) is expected


@pytest.mark.parametrize(
"attr_name, value",
[
Expand Down

0 comments on commit 3137990

Please sign in to comment.