From: Serhiy Storchaka Date: Thu, 27 Dec 2012 22:16:53 +0000 (+0200) Subject: Issue #16792: Mark small ints test as CPython-only. X-Git-Tag: v3.3.1rc1~471 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1ef73d21a209ab48248db4fa75db523e803a9f19;p=thirdparty%2FPython%2Fcpython.git Issue #16792: Mark small ints test as CPython-only. --- 1ef73d21a209ab48248db4fa75db523e803a9f19 diff --cc Lib/test/test_int.py index e0406dd4f9d8,4f2224b9323d..225b520d567e --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@@ -221,46 -218,14 +217,54 @@@ class IntTestCases(unittest.TestCase) self.assertEqual(int('2br45qc', 35), 4294967297) self.assertEqual(int('1z141z5', 36), 4294967297) + @support.cpython_only + def test_small_ints(self): + # Bug #3236: Return small longs from PyLong_FromString + self.assertIs(int('10'), 10) + self.assertIs(int('-1'), -1) + self.assertIs(int(b'10'), 10) + self.assertIs(int(b'-1'), -1) + + def test_no_args(self): + self.assertEquals(int(), 0) + + def test_keyword_args(self): + # Test invoking int() using keyword arguments. + self.assertEquals(int(x=1.2), 1) + self.assertEquals(int('100', base=2), 4) + self.assertEquals(int(x='100', base=2), 4) + + # For example, PyPy 1.9.0 raised TypeError for these cases because it + # expects x to be a string if base is given. + @support.cpython_only + def test_base_arg_with_no_x_arg(self): + self.assertEquals(int(base=6), 0) + # Even invalid bases don't raise an exception. + self.assertEquals(int(base=1), 0) + self.assertEquals(int(base=1000), 0) + self.assertEquals(int(base='foo'), 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. + class CustomStr(str): pass + class CustomBytes(bytes): pass + class CustomByteArray(bytearray): pass + + values = [b'100', + bytearray(b'100'), + CustomStr('100'), + CustomBytes(b'100'), + CustomByteArray(b'100')] + + for x in values: + msg = 'x has type %s' % type(x).__name__ + self.assertEquals(int(x), 100, msg=msg) + self.assertEquals(int(x, 2), 4, msg=msg) + + def test_string_float(self): + self.assertRaises(ValueError, int, '1.2') + def test_intconversion(self): # Test __int__() class ClassicMissingMethods: