Issue #7435: Remove duplicate int/long tests, and other
references to long in py3k. Patch provided by flox.
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 5f5a952..c6aa4eb 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -10,11 +10,9 @@
def test_truth_values(self):
if None: self.fail('None is true instead of false')
if 0: self.fail('0 is true instead of false')
- if 0: self.fail('0L is true instead of false')
if 0.0: self.fail('0.0 is true instead of false')
if '': self.fail('\'\' is true instead of false')
if not 1: self.fail('1 is false instead of true')
- if not 1: self.fail('1L is false instead of true')
if not 1.0: self.fail('1.0 is false instead of true')
if not 'x': self.fail('\'x\' is false instead of true')
if not {'x': 1}: self.fail('{\'x\': 1} is false instead of true')
@@ -36,8 +34,6 @@
def test_comparisons(self):
if 0 < 1 <= 1 == 1 >= 1 > 0 != 1: pass
else: self.fail('int comparisons failed')
- if 0 < 1 <= 1 == 1 >= 1 > 0 != 1: pass
- else: self.fail('long int comparisons failed')
if 0.0 < 1.0 <= 1.0 == 1.0 >= 1.0 > 0.0 != 1.0: pass
else: self.fail('float comparisons failed')
if '' < 'a' <= 'a' == 'a' < 'abc' < 'abd' < 'b': pass
@@ -75,18 +71,13 @@
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')
- if 1 != 1 or 1 != 1.0 or 1 != 1.0: self.fail('mixed comparisons')
- if -1 != -1 or -1 != -1.0 or -1 != -1.0:
- self.fail('int/long/float value not equal')
+ if 0 != 0.0 or 1 != 1.0 or -1 != -1.0:
+ self.fail('int/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 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')
- if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass
- else: self.fail('long() does not round properly')
if float(1) == 1.0 and float(-1) == -1.0 and float(0) == 0.0: pass
else: self.fail('float() does not work properly')
@@ -141,58 +132,38 @@
if type(prod) is not int:
self.fail("expected type(prod) to be int, not %r" %
type(prod))
- # Check for expected * overflow to long.
+ # Check for unified integral type
for divisor in 1, 2, 4, 8, 16, 32:
j = m // divisor - 1
prod = divisor * j
if type(prod) is not int:
- self.fail("expected type(%r) to be long, not %r" %
+ self.fail("expected type(%r) to be int, not %r" %
(prod, type(prod)))
- # Check for expected * overflow to long.
+ # Check for unified integral type
m = sys.maxsize
for divisor in 1, 2, 4, 8, 16, 32:
j = m // divisor + 1
prod = divisor * j
if type(prod) is not int:
- self.fail("expected type(%r) to be long, not %r" %
+ self.fail("expected type(%r) to be int, not %r" %
(prod, type(prod)))
- def test_long_integers(self):
- if 12 + 24 != 36: self.fail('long op')
- if 12 + (-24) != -12: self.fail('long op')
- if (-12) + 24 != 12: self.fail('long op')
- if (-12) + (-24) != -36: self.fail('long op')
- if not 12 < 24: self.fail('long op')
- if not -24 < -12: self.fail('long op')
x = sys.maxsize
- if int(int(x)) != x: self.fail('long op')
- try: y = int(int(x)+1)
- except OverflowError: self.fail('long op')
- if not isinstance(y, int): self.fail('long op')
- x = -x
- if int(int(x)) != x: self.fail('long op')
- x = x-1
- if int(int(x)) != x: self.fail('long op')
- try: y = int(int(x)-1)
- except OverflowError: self.fail('long op')
- if not isinstance(y, int): self.fail('long op')
+ self.assertTrue(isinstance(x + 1, int),
+ "(sys.maxsize + 1) should have returned int")
+ self.assertTrue(isinstance(-x - 1, int),
+ "(-sys.maxsize - 1) should have returned int")
+ self.assertTrue(isinstance(-x - 2, int),
+ "(-sys.maxsize - 2) should have returned int")
try: 5 << -5
except ValueError: pass
else: self.fail('int negative shift <<')
- try: 5 << -5
- except ValueError: pass
- else: self.fail('long negative shift <<')
-
try: 5 >> -5
except ValueError: pass
else: self.fail('int negative shift >>')
- try: 5 >> -5
- except ValueError: pass
- else: self.fail('long negative shift >>')
-
def test_floats(self):
if 12.0 + 24.0 != 36.0: self.fail('float op')
if 12.0 + (-24.0) != -12.0: self.fail('float op')
@@ -232,7 +203,7 @@
def test_int__format__(self):
def test(i, format_spec, result):
- # just make sure I'm not accidentally checking longs
+ # just make sure we have the unified type for integers
assert type(i) == int
assert type(format_spec) == str
self.assertEqual(i.__format__(format_spec), result)
@@ -353,6 +324,10 @@
# issue 5782, commas with no specifier type
test(1234, '010,', '00,001,234')
+ # Unified type for integers
+ test(10**100, 'd', '1' + '0' * 100)
+ test(10**100+100, 'd', '1' + '0' * 97 + '100')
+
# make sure these are errors
# precision disallowed
@@ -382,96 +357,6 @@
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 'eEfFgG%':
- for value in [0, 1, -1, 100, -100, 1234567890, -1234567890]:
- self.assertEqual(value.__format__(format_spec),
- float(value).__format__(format_spec))
-
@run_with_locale('LC_NUMERIC', 'en_US.UTF8')
def test_float__format__locale(self):
# test locale support for __format__ code 'n'