Skip to content

Commit

Permalink
Hash of SemVer well defined
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarrazzo committed Nov 28, 2011
1 parent 645a735 commit d34692f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pgxnclient/tests/test_semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_eq(self):
('0.1.2beta3', '0.1.2beta3'),
('1.0.0rc-1', '1.0.0RC-1'), ]:
self.assertEqual(SemVer(s1), SemVer(s2))
self.assertEqual(hash(SemVer(s1)), hash(SemVer(s2)))
self.assert_(SemVer(s1) <= SemVer(s2),
"%s <= %s failed" % (s1, s2))
self.assert_(SemVer(s1) >= SemVer(s2),
Expand All @@ -62,6 +63,7 @@ def test_ne(self):
('1.2.3a', '1.2.3b'),
('1.2.3aaaaaaa1', '1.2.3aaaaaaa2'), ]:
self.assertNotEqual(SemVer(s1), SemVer(s2))
self.assertNotEqual(hash(SemVer(s1)), hash(SemVer(s2)))

def test_dis(self):
for s1, s2 in [
Expand Down
3 changes: 3 additions & 0 deletions pgxnclient/utils/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def __eq__(self, other):
def __ne__(self, other):
return not self == other

def __hash__(self):
return hash(self.tuple[:3] + (self.tuple[3].lower(),))

def _ltgt(self, other, op):
if isinstance(other, SemVer):
t1 = self.tuple[:3]
Expand Down

0 comments on commit d34692f

Please sign in to comment.