Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60878,60880-60892,60894-60898 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60876 | georg.brandl | 2008-02-17 16:14:10 +0100 (Sun, 17 Feb 2008) | 2 lines
Fix function name.
........
r60877 | facundo.batista | 2008-02-17 17:21:13 +0100 (Sun, 17 Feb 2008) | 4 lines
Now we handle different the backup copy, because of security
issues regarding user/group and permissions. Fixes 1050828.
........
r60878 | facundo.batista | 2008-02-17 19:59:29 +0100 (Sun, 17 Feb 2008) | 4 lines
Issue 2112. mmap does not raises EnvironmentError no more, but
a subclass of it. Thanks John Lenton.
........
r60882 | amaury.forgeotdarc | 2008-02-17 21:56:31 +0100 (Sun, 17 Feb 2008) | 5 lines
Compilation was broken on Windows since the introduction of Advanced String Formatting.
Only PCBuild (vs9) was really tested.
Changes for older compilers were done manually.
........
r60883 | georg.brandl | 2008-02-17 22:18:55 +0100 (Sun, 17 Feb 2008) | 2 lines
#2133: fix HTML color spec.
........
r60884 | facundo.batista | 2008-02-18 04:43:43 +0100 (Mon, 18 Feb 2008) | 5 lines
Issue #1916. Added isgenerator() and isgeneratorfunction() to
inspect.py. Thanks Javi Mansilla for patch review and
corrections.
........
r60885 | facundo.batista | 2008-02-18 13:48:43 +0100 (Mon, 18 Feb 2008) | 4 lines
Issue 1224. Now we support again the double slash in the URL.
Thanks Anthony Lenton.
........
r60887 | eric.smith | 2008-02-18 15:25:02 +0100 (Mon, 18 Feb 2008) | 1 line
Temporarily removed float tests. See issue 1600.
........
r60891 | kristjan.jonsson | 2008-02-18 18:40:47 +0100 (Mon, 18 Feb 2008) | 1 line
Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
........
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 0014323..f82fe30 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -63,15 +63,15 @@
try: 5 / 0
except ZeroDivisionError: pass
- else: self.fail("5 / 0L didn't raise ZeroDivisionError")
+ else: self.fail("5 / 0 didn't raise ZeroDivisionError")
try: 5 // 0
except ZeroDivisionError: pass
- else: self.fail("5 // 0L didn't raise ZeroDivisionError")
+ else: self.fail("5 // 0 didn't raise ZeroDivisionError")
try: 5 % 0
except ZeroDivisionError: pass
- else: self.fail("5 % 0L didn't raise ZeroDivisionError")
+ else: self.fail("5 % 0 didn't raise ZeroDivisionError")
def test_numeric_types(self):
if 0 != 0 or 0 != 0.0 or 0 != 0.0: self.fail('mixed comparisons')
@@ -80,7 +80,7 @@
self.fail('int/long/float value not equal')
# calling built-in types without argument must return 0
if int() != 0: self.fail('int() does not return 0')
- if int() != 0: self.fail('long() does not return 0L')
+ if int() != 0: self.fail('long() does not return 0')
if float() != 0.0: self.fail('float() does not return 0.0')
if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass
else: self.fail('int() does not round properly')
@@ -203,6 +203,251 @@
self.assertRaises(TypeError, type, 1, 2)
self.assertRaises(TypeError, type, 1, 2, 3, 4)
+ def test_int__format__(self):
+ def test(i, format_spec, result):
+ # just make sure I'm not accidentally checking longs
+ assert type(i) == int
+ assert type(format_spec) == str
+ self.assertEqual(i.__format__(format_spec), result)
+
+ test(123456789, 'd', '123456789')
+ test(123456789, 'd', '123456789')
+
+ test(1, 'c', '\01')
+
+ # sign and aligning are interdependent
+ test(1, "-", '1')
+ test(-1, "-", '-1')
+ test(1, "-3", ' 1')
+ test(-1, "-3", ' -1')
+ test(1, "+3", ' +1')
+ test(-1, "+3", ' -1')
+ test(1, " 3", ' 1')
+ test(-1, " 3", ' -1')
+ test(1, " ", ' 1')
+ test(-1, " ", '-1')
+
+ # hex
+ test(3, "x", "3")
+ test(3, "X", "3")
+ test(1234, "x", "4d2")
+ test(-1234, "x", "-4d2")
+ test(1234, "8x", " 4d2")
+ test(-1234, "8x", " -4d2")
+ test(1234, "x", "4d2")
+ test(-1234, "x", "-4d2")
+ test(-3, "x", "-3")
+ test(-3, "X", "-3")
+ test(int('be', 16), "x", "be")
+ test(int('be', 16), "X", "BE")
+ test(-int('be', 16), "x", "-be")
+ test(-int('be', 16), "X", "-BE")
+
+ # octal
+ test(3, "o", "3")
+ test(-3, "o", "-3")
+ test(65, "o", "101")
+ test(-65, "o", "-101")
+ test(1234, "o", "2322")
+ test(-1234, "o", "-2322")
+ test(1234, "-o", "2322")
+ test(-1234, "-o", "-2322")
+ test(1234, " o", " 2322")
+ test(-1234, " o", "-2322")
+ test(1234, "+o", "+2322")
+ test(-1234, "+o", "-2322")
+
+ # binary
+ test(3, "b", "11")
+ test(-3, "b", "-11")
+ test(1234, "b", "10011010010")
+ test(-1234, "b", "-10011010010")
+ test(1234, "-b", "10011010010")
+ test(-1234, "-b", "-10011010010")
+ test(1234, " b", " 10011010010")
+ test(-1234, " b", "-10011010010")
+ test(1234, "+b", "+10011010010")
+ test(-1234, "+b", "-10011010010")
+
+ # make sure these are errors
+
+ # precision disallowed
+ self.assertRaises(ValueError, 3 .__format__, "1.3")
+ # sign not allowed with 'c'
+ self.assertRaises(ValueError, 3 .__format__, "+c")
+ # format spec must be string
+ self.assertRaises(TypeError, 3 .__format__, None)
+ self.assertRaises(TypeError, 3 .__format__, 0)
+
+ # ensure that only int and float type specifiers work
+ for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
+ [chr(x) for x in range(ord('A'), ord('Z')+1)]):
+ if not format_spec in 'bcdoxXeEfFgGn%':
+ self.assertRaises(ValueError, 0 .__format__, format_spec)
+ self.assertRaises(ValueError, 1 .__format__, format_spec)
+ self.assertRaises(ValueError, (-1) .__format__, format_spec)
+
+ # ensure that float type specifiers work; format converts
+ # the int to a float
+ for format_spec in 'eEfFgGn%':
+ for value in [0, 1, -1, 100, -100, 1234567890, -1234567890]:
+ self.assertEqual(value.__format__(format_spec),
+ float(value).__format__(format_spec))
+
+ def test_long__format__(self):
+ def test(i, format_spec, result):
+ # make sure we're not accidentally checking ints
+ assert type(i) == int
+ assert type(format_spec) == str
+ self.assertEqual(i.__format__(format_spec), result)
+
+ test(10**100, 'd', '1' + '0' * 100)
+ test(10**100+100, 'd', '1' + '0' * 97 + '100')
+
+ test(123456789, 'd', '123456789')
+ test(123456789, 'd', '123456789')
+
+ # sign and aligning are interdependent
+ test(1, "-", '1')
+ test(-1, "-", '-1')
+ test(1, "-3", ' 1')
+ test(-1, "-3", ' -1')
+ test(1, "+3", ' +1')
+ test(-1, "+3", ' -1')
+ test(1, " 3", ' 1')
+ test(-1, " 3", ' -1')
+ test(1, " ", ' 1')
+ test(-1, " ", '-1')
+
+ test(1, 'c', '\01')
+
+ # hex
+ test(3, "x", "3")
+ test(3, "X", "3")
+ test(1234, "x", "4d2")
+ test(-1234, "x", "-4d2")
+ test(1234, "8x", " 4d2")
+ test(-1234, "8x", " -4d2")
+ test(1234, "x", "4d2")
+ test(-1234, "x", "-4d2")
+ test(-3, "x", "-3")
+ test(-3, "X", "-3")
+
+ # octal
+ test(3, "o", "3")
+ test(-3, "o", "-3")
+ test(65, "o", "101")
+ test(-65, "o", "-101")
+ test(1234, "o", "2322")
+ test(-1234, "o", "-2322")
+ test(1234, "-o", "2322")
+ test(-1234, "-o", "-2322")
+ test(1234, " o", " 2322")
+ test(-1234, " o", "-2322")
+ test(1234, "+o", "+2322")
+ test(-1234, "+o", "-2322")
+
+ # binary
+ test(3, "b", "11")
+ test(-3, "b", "-11")
+ test(1234, "b", "10011010010")
+ test(-1234, "b", "-10011010010")
+ test(1234, "-b", "10011010010")
+ test(-1234, "-b", "-10011010010")
+ test(1234, " b", " 10011010010")
+ test(-1234, " b", "-10011010010")
+ test(1234, "+b", "+10011010010")
+ test(-1234, "+b", "-10011010010")
+
+ # make sure these are errors
+
+ # precision disallowed
+ self.assertRaises(ValueError, 3 .__format__, "1.3")
+ # sign not allowed with 'c'
+ self.assertRaises(ValueError, 3 .__format__, "+c")
+ # format spec must be string
+ self.assertRaises(TypeError, 3 .__format__, None)
+ self.assertRaises(TypeError, 3 .__format__, 0)
+
+ # ensure that only int and float type specifiers work
+ for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
+ [chr(x) for x in range(ord('A'), ord('Z')+1)]):
+ if not format_spec in 'bcdoxXeEfFgGn%':
+ self.assertRaises(ValueError, 0 .__format__, format_spec)
+ self.assertRaises(ValueError, 1 .__format__, format_spec)
+ self.assertRaises(ValueError, (-1) .__format__, format_spec)
+
+ # ensure that float type specifiers work; format converts
+ # the long to a float
+ for format_spec in 'eEfFgGn%':
+ for value in [0, 1, -1, 100, -100, 1234567890, -1234567890]:
+ self.assertEqual(value.__format__(format_spec),
+ float(value).__format__(format_spec))
+
+ def test_float__format__(self):
+ # these should be rewritten to use both format(x, spec) and
+ # x.__format__(spec)
+
+ def test(f, format_spec, result):
+ assert type(f) == float
+ assert type(format_spec) == str
+ self.assertEqual(f.__format__(format_spec), result)
+
+ test(0.0, 'f', '0.000000')
+
+ # the default is 'g', except for empty format spec
+ test(0.0, '', '0.0')
+ test(0.01, '', '0.01')
+ test(0.01, 'g', '0.01')
+
+ test( 1.0, ' g', ' 1')
+ test(-1.0, ' g', '-1')
+ test( 1.0, '+g', '+1')
+ test(-1.0, '+g', '-1')
+ test(1.1234e200, 'g', '1.1234e+200')
+ test(1.1234e200, 'G', '1.1234E+200')
+
+
+ test(1.0, 'f', '1.000000')
+
+ test(-1.0, 'f', '-1.000000')
+
+ test( 1.0, ' f', ' 1.000000')
+ test(-1.0, ' f', '-1.000000')
+ test( 1.0, '+f', '+1.000000')
+ test(-1.0, '+f', '-1.000000')
+ test(1.1234e200, 'f', '1.1234e+200')
+ test(1.1234e200, 'F', '1.1234e+200')
+
+ # temporarily removed. see issue 1600
+ # test( 1.0, 'e', '1.000000e+00')
+ # test(-1.0, 'e', '-1.000000e+00')
+ # test( 1.0, 'E', '1.000000E+00')
+ # test(-1.0, 'E', '-1.000000E+00')
+ # test(1.1234e20, 'e', '1.123400e+20')
+ # test(1.1234e20, 'E', '1.123400E+20')
+
+ # % formatting
+ test(-1.0, '%', '-100.000000%')
+
+ # format spec must be string
+ self.assertRaises(TypeError, 3.0.__format__, None)
+ self.assertRaises(TypeError, 3.0.__format__, 0)
+
+ # other format specifiers shouldn't work on floats,
+ # in particular int specifiers
+ for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] +
+ [chr(x) for x in range(ord('A'), ord('Z')+1)]):
+ if not format_spec in 'eEfFgGn%':
+ self.assertRaises(ValueError, format, 0.0, format_spec)
+ self.assertRaises(ValueError, format, 1.0, format_spec)
+ self.assertRaises(ValueError, format, -1.0, format_spec)
+ self.assertRaises(ValueError, format, 1e100, format_spec)
+ self.assertRaises(ValueError, format, -1e100, format_spec)
+ self.assertRaises(ValueError, format, 1e-100, format_spec)
+ self.assertRaises(ValueError, format, -1e-100, format_spec)
+
+
def test_main():
run_unittest(TypesTests)