From: Mark Dickinson Date: Wed, 26 May 2010 19:06:33 +0000 (+0000) Subject: Issue #8825: additional testcases for int(string, 0) and long(string, 0). X-Git-Tag: v2.7rc1~80 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=784a47f2c0fcdee61518407900baa1e08025182b;p=thirdparty%2FPython%2Fcpython.git Issue #8825: additional testcases for int(string, 0) and long(string, 0). --- diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index ec57842b6880..6e611c2cc931 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -175,6 +175,12 @@ class IntTestCases(unittest.TestCase): self.assertEqual(int(' 0O123 ', 0), 83) self.assertEqual(int(' 0X123 ', 0), 291) self.assertEqual(int(' 0B100 ', 0), 4) + self.assertEqual(int('0', 0), 0) + self.assertEqual(int('+0', 0), 0) + self.assertEqual(int('-0', 0), 0) + self.assertEqual(int('00', 0), 0) + self.assertRaises(ValueError, int, '08', 0) + self.assertRaises(ValueError, int, '-012395', 0) # without base still base 10 self.assertEqual(int('0123'), 123) diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 7be89fcf1609..412ec7c52517 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -356,6 +356,23 @@ class LongTest(unittest.TestCase): self.assertRaises(ValueError, long, '53', 40) self.assertRaises(TypeError, long, 1, 12) + # tests with base 0 + self.assertEqual(long(' 0123 ', 0), 83) + self.assertEqual(long(' 0123 ', 0), 83) + self.assertEqual(long('000', 0), 0) + self.assertEqual(long('0o123', 0), 83) + self.assertEqual(long('0x123', 0), 291) + self.assertEqual(long('0b100', 0), 4) + self.assertEqual(long(' 0O123 ', 0), 83) + self.assertEqual(long(' 0X123 ', 0), 291) + self.assertEqual(long(' 0B100 ', 0), 4) + self.assertEqual(long('0', 0), 0) + self.assertEqual(long('+0', 0), 0) + self.assertEqual(long('-0', 0), 0) + self.assertEqual(long('00', 0), 0) + self.assertRaises(ValueError, long, '08', 0) + self.assertRaises(ValueError, long, '-012395', 0) + # SF patch #1638879: embedded NULs were not detected with # explicit base self.assertRaises(ValueError, long, '123\0', 10)