Skip to content

Commit

Permalink
Make ComparableVersion hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Apr 4, 2023
1 parent 1e16536 commit eda8e59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openeo/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.16.0a4"
__version__ = "0.16.0a5"
3 changes: 3 additions & 0 deletions openeo/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def __repr__(self):
def __str__(self):
return ".".join(map(str, self._version))

def __hash__(self):
return hash(self._version)

def to_string(self):
return str(self)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,19 @@ def test_require_at_least(self):
v.require_at_least("1.2.0")
with pytest.raises(ApiVersionException):
v.require_at_least("1.2.4")

def test_hashable_dict(self):
d = {
ComparableVersion("1.2.3"): "red",
}
assert d[ComparableVersion((1, 2, 3))] == "red"

def test_hashable_set(self):
s = {
ComparableVersion("1.2.3"),
ComparableVersion("2.4.6"),
}
assert s == {
ComparableVersion((2, 4, 6)),
ComparableVersion("1.2.3"),
}

0 comments on commit eda8e59

Please sign in to comment.