]> granicus.if.org Git - python/commitdiff
Merging change 55102 from the trunk:
authorKristján Valur Jónsson <kristjan@ccpgames.com>
Mon, 7 May 2007 13:33:39 +0000 (13:33 +0000)
committerKristján Valur Jónsson <kristjan@ccpgames.com>
Mon, 7 May 2007 13:33:39 +0000 (13:33 +0000)
Fix those parts in the testsuite that assumed that sys.maxint would cause overflow on x64.  Now the testsuite is well behaved on that platform.

Lib/test/string_tests.py
Lib/test/test_format.py
Lib/test/test_index.py
Lib/test/test_itertools.py

index 1aa68dedd0d88daa05da5615d3d3b824b793e392..b257d57b0e08c06d1f91cbb28b76891381e61603 100644 (file)
@@ -2,7 +2,7 @@
 Common tests shared by test_str, test_unicode, test_userstring and test_string.
 """
 
-import unittest, string, sys
+import unittest, string, sys, struct
 from test import test_support
 from UserList import UserList
 
@@ -671,7 +671,7 @@ class CommonTest(unittest.TestCase):
 
     def test_replace_overflow(self):
         # Check for overflow checking on 32 bit machines
-        if sys.maxint != 2147483647:
+        if sys.maxint != 2147483647 or struct.calcsize("P") > 4:
             return
         A2_16 = "A" * (2**16)
         self.checkraises(OverflowError, A2_16, "replace", "", A2_16)
index a9b31707a24917c8e357fb136998a9588a413630..fee3bf4a305a002ec2a0f77c9085cc288edf3912 100644 (file)
@@ -1,5 +1,7 @@
 from test.test_support import verbose, have_unicode, TestFailed
 import sys
+from test.test_support import MAX_Py_ssize_t
+maxsize = MAX_Py_ssize_t
 
 # test string formatting operator (I am not sure if this is being tested
 # elsewhere but, surely, some of the given cases are *not* tested because
@@ -238,11 +240,11 @@ class Foobar(long):
 test_exc('%o', Foobar(), TypeError,
          "expected string or Unicode object, long found")
 
-if sys.maxint == 2**31-1:
+if maxsize == 2**31-1:
     # crashes 2.2.1 and earlier:
     try:
-        "%*d"%(sys.maxint, -127)
+        "%*d"%(maxsize, -127)
     except MemoryError:
         pass
     else:
-        raise TestFailed, '"%*d"%(sys.maxint, -127) should fail'
+        raise TestFailed, '"%*d"%(maxsize, -127) should fail'
index ecb566d5d58235db76e9198b5cded208f4c76e8c..323b37b754ba94f62e20d057b32ef99bdb339d0c 100644 (file)
@@ -1,7 +1,10 @@
 import unittest
 from test import test_support
 import operator
+import sys
 from sys import maxint
+maxsize = test_support.MAX_Py_ssize_t
+minsize = -maxsize-1
 
 class oldstyle:
     def __index__(self):
@@ -185,7 +188,7 @@ class OverflowTestCase(unittest.TestCase):
     def _getitem_helper(self, base):
         class GetItem(base):
             def __len__(self):
-                return maxint
+                return maxint #cannot return long here
             def __getitem__(self, key):
                 return key
             def __getslice__(self, i, j):
@@ -193,8 +196,8 @@ class OverflowTestCase(unittest.TestCase):
         x = GetItem()
         self.assertEqual(x[self.pos], self.pos)
         self.assertEqual(x[self.neg], self.neg)
-        self.assertEqual(x[self.neg:self.pos], (-1, maxint))
-        self.assertEqual(x[self.neg:self.pos:1].indices(maxint), (0, maxint, 1))
+        self.assertEqual(x[self.neg:self.pos], (maxint+minsize, maxsize))
+        self.assertEqual(x[self.neg:self.pos:1].indices(maxsize), (0, maxsize, 1))
 
     def test_getitem(self):
         self._getitem_helper(object)
index c965d4c14efc3c126dbc71008069fa1bf7f49345..99f9077013c5a20fea8819dfa7d6f614755b0e97 100644 (file)
@@ -5,6 +5,8 @@ from weakref import proxy
 import sys
 import operator
 import random
+maxsize = test_support.MAX_Py_ssize_t
+minsize = -maxsize-1
 
 def onearg(x):
     'Test function of one argument'
@@ -52,7 +54,7 @@ class TestBasicOps(unittest.TestCase):
         self.assertEqual(take(2, zip('abc',count(3))), [('a', 3), ('b', 4)])
         self.assertRaises(TypeError, count, 2, 3)
         self.assertRaises(TypeError, count, 'a')
-        self.assertRaises(OverflowError, list, islice(count(sys.maxint-5), 10))
+        self.assertRaises(OverflowError, list, islice(count(maxsize-5), 10))
         c = count(3)
         self.assertEqual(repr(c), 'count(3)')
         c.next()
@@ -285,7 +287,7 @@ class TestBasicOps(unittest.TestCase):
         self.assertRaises(ValueError, islice, xrange(10), 1, 'a')
         self.assertRaises(ValueError, islice, xrange(10), 'a', 1, 1)
         self.assertRaises(ValueError, islice, xrange(10), 1, 'a', 1)
-        self.assertEqual(len(list(islice(count(), 1, 10, sys.maxint))), 1)
+        self.assertEqual(len(list(islice(count(), 1, 10, maxsize))), 1)
 
     def test_takewhile(self):
         data = [1, 3, 5, 20, 2, 4, 6, 8]