cpython: 60f7197f991f (original) (raw)
Mercurial > cpython
changeset 81057:60f7197f991f
Test for issue16772 and redoes the previous fix to accept __index__-aware objects as the base by using PyNumber_AsSsize_t similar to round(). [#16772]
Gregory P. Smith greg@krypto.org | |
---|---|
date | Tue, 25 Dec 2012 22:38:32 -0800 |
parents | 3cd57e8144dc |
children | 43b19d9f9af4 |
files | Lib/test/test_int.py Objects/longobject.c |
diffstat | 2 files changed, 27 insertions(+), 4 deletions(-)[+] [-] Lib/test/test_int.py 24 Objects/longobject.c 7 |
line wrap: on
line diff
--- 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."""[](#l1.8)
self.assertEqual(int('0', 5), 0)[](#l1.9)
with self.assertRaises(ValueError):[](#l1.10)
int('0', 1)[](#l1.11)
with self.assertRaises(ValueError):[](#l1.12)
int('0', 37)[](#l1.13)
with self.assertRaises(ValueError):[](#l1.14)
int('0', -909) # An old magic value base from Python 2.[](#l1.15)
with self.assertRaises(ValueError):[](#l1.16)
int('0', base=0-(2**234))[](#l1.17)
with self.assertRaises(ValueError):[](#l1.18)
int('0', base=2**234)[](#l1.19)
# Bases 2 through 36 are supported.[](#l1.20)
for base in range(2,37):[](#l1.21)
self.assertEqual(int('0', base=base), 0)[](#l1.22)
- def test_int_base_bad_types(self):
"""Not integer types are not valid bases; issue16772."""[](#l1.25)
with self.assertRaises(TypeError):[](#l1.26)
int('0', 5.5)[](#l1.27)
with self.assertRaises(TypeError):[](#l1.28)
int('0', 5.0)[](#l1.29)
+ def test_non_numeric_input_types(self): # Test possible non-numeric types for the argument x, including # subclasses of the explicitly documented accepted types.
--- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4247,8 +4247,7 @@ static PyObject * long_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *obase = NULL, *x = NULL;