Merge "Add VerNum.__index__() for Python 3 support"
This commit is contained in:
commit
3c7ac7559c
@ -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):
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user