diff options
author | Gregory P. Smith <greg@krypto.org> | 2012-12-26 06:38:32 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2012-12-26 06:38:32 (GMT) |
commit | a689e524e7465b5facc07f493adfa7eda6b918d4 (patch) | |
tree | 9d128bee57985c61bbae5bbbd5a7b153678e3271 /Lib/test/test_int.py | |
parent | 83a2aa70af52eaddaaaff13167d8b1f61567d481 (diff) | |
download | cpython-a689e524e7465b5facc07f493adfa7eda6b918d4.zip cpython-a689e524e7465b5facc07f493adfa7eda6b918d4.tar.gz cpython-a689e524e7465b5facc07f493adfa7eda6b918d4.tar.bz2 |
Test for issue16772 and redoes the previous fix to accept __index__-aware
objects as the base by using PyNumber_AsSsize_t similar to round().
Diffstat (limited to 'Lib/test/test_int.py')
-rw-r--r-- | Lib/test/test_int.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index e0406dd..fdb84a0 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -240,6 +240,30 @@ class IntTestCases(unittest.TestCase): self.assertEquals(int(base=1000), 0) self.assertEquals(int(base='foo'), 0) + def test_int_base_limits(self): + """Testing the supported limits of the int() base parameter.""" + self.assertEqual(int('0', 5), 0) + with self.assertRaises(ValueError): + int('0', 1) + with self.assertRaises(ValueError): + int('0', 37) + with self.assertRaises(ValueError): + int('0', -909) # An old magic value base from Python 2. + with self.assertRaises(ValueError): + int('0', base=0-(2**234)) + with self.assertRaises(ValueError): + int('0', base=2**234) + # Bases 2 through 36 are supported. + for base in range(2,37): + self.assertEqual(int('0', base=base), 0) + + def test_int_base_bad_types(self): + """Not integer types are not valid bases; issue16772.""" + with self.assertRaises(TypeError): + int('0', 5.5) + with self.assertRaises(TypeError): + int('0', 5.0) + def test_non_numeric_input_types(self): # Test possible non-numeric types for the argument x, including # subclasses of the explicitly documented accepted types. |