summaryrefslogtreecommitdiff
path: root/Lib/test/test_int.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2013-01-27 10:17:52 +0000
committerMark Dickinson <dickinsm@gmail.com>2013-01-27 10:17:52 +0000
commit07c71365244ce496042566d94bdd469f7d3b1bf6 (patch)
tree6de3120c827869ed95aca8c6b034bbbc5d9c61ee /Lib/test/test_int.py
parent3a62e45b974611c80ba9e21670cfbfbe2bd193c1 (diff)
downloadcpython-git-07c71365244ce496042566d94bdd469f7d3b1bf6.tar.gz
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.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py
index 09b9a7785b..afc91699a9 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.