diff --git a/migrate/tests/versioning/test_version.py b/migrate/tests/versioning/test_version.py index 00ce695..df50072 100644 --- a/migrate/tests/versioning/test_version.py +++ b/migrate/tests/versioning/test_version.py @@ -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): diff --git a/migrate/versioning/version.py b/migrate/versioning/version.py index de7008f..3ab814c 100644 --- a/migrate/versioning/version.py +++ b/migrate/versioning/version.py @@ -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)