Merge "Add VerNum.__index__() for Python 3 support"

This commit is contained in:
Jenkins 2015-07-31 02:11:27 +00:00 committed by Gerrit Code Review
commit 3c7ac7559c
2 changed files with 10 additions and 0 deletions

View File

@ -69,6 +69,13 @@ class TestVerNum(fixture.Base):
self.assertTrue(VerNum(2) >= 1)
self.assertFalse(VerNum(1) >= 2)
def test_int_cast(self):
ver = VerNum(3)
# test __int__
self.assertEqual(int(ver), 3)
# test __index__: range() doesn't call __int__
self.assertEqual(list(range(ver, ver)), [])
class TestVersion(fixture.Pathed):

View File

@ -65,6 +65,9 @@ class VerNum(object):
def __int__(self):
return int(self.value)
def __index__(self):
return int(self.value)
if six.PY3:
def __hash__(self):
return hash(self.value)