Skip to content

Commit

Permalink
Implement Artifact.__eq__ (#27)
Browse files Browse the repository at this point in the history
* Implement Artifact.__eq__

Closes: #26

* run linting on opened and reopened

* format

---------

Co-authored-by: Erlend Hamnaberg <[email protected]>
  • Loading branch information
candrews and hamnis authored Jun 6, 2023
1 parent 7b2a88f commit 1363e92
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
- main
pull_request:
types:
- opened
- reopened
- synchronize

jobs:
Expand Down
10 changes: 10 additions & 0 deletions src/maven_artifact/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def __str__(self):
else:
return "%s:%s:%s" % (self.group_id, self.artifact_id, self.version)

def __eq__(self, other):
return (
isinstance(other, Artifact)
and self.group_id == other.group_id
and self.artifact_id == other.artifact_id
and self.version == other.version
and self.classifier == other.classifier
and self.extension == other.extension
)

@staticmethod
def parse(maven_coordinate):
parts = maven_coordinate.split(":")
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/maven_artifact/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,27 @@ def test_issnapshot():
artifact = artifact.with_version(_version="0.0.1-SNAPSHOT")

assert artifact.is_snapshot() is True


@pytest.mark.parametrize(
"test_input,expected",
[
("group:artifact:version", Artifact(group_id="group", artifact_id="artifact", version="version")),
(
"group:artifact:extension:version",
Artifact(group_id="group", artifact_id="artifact", version="version", extension="extension"),
),
(
"group:artifact:extension:classifier:version",
Artifact(
group_id="group",
artifact_id="artifact",
version="version",
extension="extension",
classifier="classifier",
),
),
],
)
def test_eq(test_input, expected):
assert Artifact.parse(test_input) == expected

0 comments on commit 1363e92

Please sign in to comment.