diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2013-01-27 10:17:52 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2013-01-27 10:17:52 (GMT) |
commit | 07c71365244ce496042566d94bdd469f7d3b1bf6 (patch) | |
tree | 6de3120c827869ed95aca8c6b034bbbc5d9c61ee /Lib/test/test_int.py | |
parent | 3a62e45b974611c80ba9e21670cfbfbe2bd193c1 (diff) | |
download | cpython-07c71365244ce496042566d94bdd469f7d3b1bf6.zip cpython-07c71365244ce496042566d94bdd469f7d3b1bf6.tar.gz cpython-07c71365244ce496042566d94bdd469f7d3b1bf6.tar.bz2 |
Issue #16772: in int(x, base), non-integer bases must have an __index__ method.
Diffstat (limited to 'Lib/test/test_int.py')
-rw-r--r-- | Lib/test/test_int.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index 09b9a77..afc9169 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -260,6 +260,23 @@ class IntTestCases(unittest.TestCase): with self.assertRaises(TypeError): int('0', 5.0) + def test_int_base_indexable(self): + class MyIndexable(object): + def __init__(self, value): + self.value = value + def __index__(self): + return self.value + + # Check out of range bases. + for base in 2**100, -2**100, 1, 37: + with self.assertRaises(ValueError): + int('43', base) + + # Check in-range bases. + self.assertEqual(int('101', base=MyIndexable(2)), 5) + self.assertEqual(int('101', base=MyIndexable(10)), 101) + self.assertEqual(int('101', base=MyIndexable(36)), 1 + 36**2) + def test_non_numeric_input_types(self): # Test possible non-numeric types for the argument x, including # subclasses of the explicitly documented accepted types. |