Permalink
Browse files

Hash of SemVer well defined

  • Loading branch information...
1 parent 645a735 commit d34692f25604793bc6d17aadb4c6521b16fe7e95 @dvarrazzo committed Nov 28, 2011
Showing with 5 additions and 0 deletions.
  1. +2 −0 pgxnclient/tests/test_semver.py
  2. +3 −0 pgxnclient/utils/semver.py
@@ -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),
@@ -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 [
@@ -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]

0 comments on commit d34692f

Please sign in to comment.