Kaydet (Commit) 804b9d4d authored tarafından Mark Dickinson's avatar Mark Dickinson

Merged revisions 81551 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81551 | mark.dickinson | 2010-05-26 20:06:33 +0100 (Wed, 26 May 2010) | 1 line

  Issue #8825: additional testcases for int(string, 0) and long(string, 0).
........
üst aa59f762
...@@ -174,6 +174,12 @@ class IntTestCases(unittest.TestCase): ...@@ -174,6 +174,12 @@ class IntTestCases(unittest.TestCase):
self.assertEqual(int(' 0O123 ', 0), 83) self.assertEqual(int(' 0O123 ', 0), 83)
self.assertEqual(int(' 0X123 ', 0), 291) self.assertEqual(int(' 0X123 ', 0), 291)
self.assertEqual(int(' 0B100 ', 0), 4) 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 # without base still base 10
self.assertEqual(int('0123'), 123) self.assertEqual(int('0123'), 123)
......
...@@ -323,6 +323,23 @@ class LongTest(unittest.TestCase): ...@@ -323,6 +323,23 @@ class LongTest(unittest.TestCase):
self.assertRaises(ValueError, long, '53', 40) self.assertRaises(ValueError, long, '53', 40)
self.assertRaises(TypeError, long, 1, 12) 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 # SF patch #1638879: embedded NULs were not detected with
# explicit base # explicit base
self.assertRaises(ValueError, long, '123\0', 10) self.assertRaises(ValueError, long, '123\0', 10)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment