Fix those parts in the testsuite that assumed that sys.maxint would cause...

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.
parent 19ac472b
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Common tests shared by test_str, test_unicode, test_userstring and test_string. 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 test import test_support
from UserList import UserList from UserList import UserList
...@@ -671,7 +671,7 @@ class CommonTest(unittest.TestCase): ...@@ -671,7 +671,7 @@ class CommonTest(unittest.TestCase):
def test_replace_overflow(self): def test_replace_overflow(self):
# Check for overflow checking on 32 bit machines # Check for overflow checking on 32 bit machines
if sys.maxint != 2147483647: if sys.maxint != 2147483647 or struct.calcsize("P") > 4:
return return
A2_16 = "A" * (2**16) A2_16 = "A" * (2**16)
self.checkraises(OverflowError, A2_16, "replace", "", A2_16) self.checkraises(OverflowError, A2_16, "replace", "", A2_16)
......
from test.test_support import verbose, have_unicode, TestFailed from test.test_support import verbose, have_unicode, TestFailed
import sys 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 # 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 # elsewhere but, surely, some of the given cases are *not* tested because
...@@ -238,11 +240,11 @@ class Foobar(long): ...@@ -238,11 +240,11 @@ class Foobar(long):
test_exc('%o', Foobar(), TypeError, test_exc('%o', Foobar(), TypeError,
"expected string or Unicode object, long found") "expected string or Unicode object, long found")
if sys.maxint == 2**31-1: if maxsize == 2**31-1:
# crashes 2.2.1 and earlier: # crashes 2.2.1 and earlier:
try: try:
"%*d"%(sys.maxint, -127) "%*d"%(maxsize, -127)
except MemoryError: except MemoryError:
pass pass
else: else:
raise TestFailed, '"%*d"%(sys.maxint, -127) should fail' raise TestFailed, '"%*d"%(maxsize, -127) should fail'
import unittest import unittest
from test import test_support from test import test_support
import operator import operator
import sys
from sys import maxint from sys import maxint
maxsize = test_support.MAX_Py_ssize_t
minsize = -maxsize-1
class oldstyle: class oldstyle:
def __index__(self): def __index__(self):
...@@ -185,7 +188,7 @@ class OverflowTestCase(unittest.TestCase): ...@@ -185,7 +188,7 @@ class OverflowTestCase(unittest.TestCase):
def _getitem_helper(self, base): def _getitem_helper(self, base):
class GetItem(base): class GetItem(base):
def __len__(self): def __len__(self):
return maxint return maxint #cannot return long here
def __getitem__(self, key): def __getitem__(self, key):
return key return key
def __getslice__(self, i, j): def __getslice__(self, i, j):
...@@ -193,8 +196,8 @@ class OverflowTestCase(unittest.TestCase): ...@@ -193,8 +196,8 @@ class OverflowTestCase(unittest.TestCase):
x = GetItem() x = GetItem()
self.assertEqual(x[self.pos], self.pos) self.assertEqual(x[self.pos], self.pos)
self.assertEqual(x[self.neg], self.neg) self.assertEqual(x[self.neg], self.neg)
self.assertEqual(x[self.neg:self.pos], (-1, maxint)) self.assertEqual(x[self.neg:self.pos], (maxint+minsize, maxsize))
self.assertEqual(x[self.neg:self.pos:1].indices(maxint), (0, maxint, 1)) self.assertEqual(x[self.neg:self.pos:1].indices(maxsize), (0, maxsize, 1))
def test_getitem(self): def test_getitem(self):
self._getitem_helper(object) self._getitem_helper(object)
......
...@@ -5,6 +5,8 @@ from weakref import proxy ...@@ -5,6 +5,8 @@ from weakref import proxy
import sys import sys
import operator import operator
import random import random
maxsize = test_support.MAX_Py_ssize_t
minsize = -maxsize-1
def onearg(x): def onearg(x):
'Test function of one argument' 'Test function of one argument'
...@@ -52,7 +54,7 @@ class TestBasicOps(unittest.TestCase): ...@@ -52,7 +54,7 @@ class TestBasicOps(unittest.TestCase):
self.assertEqual(take(2, zip('abc',count(3))), [('a', 3), ('b', 4)]) self.assertEqual(take(2, zip('abc',count(3))), [('a', 3), ('b', 4)])
self.assertRaises(TypeError, count, 2, 3) self.assertRaises(TypeError, count, 2, 3)
self.assertRaises(TypeError, count, 'a') 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) c = count(3)
self.assertEqual(repr(c), 'count(3)') self.assertEqual(repr(c), 'count(3)')
c.next() c.next()
...@@ -330,7 +332,7 @@ class TestBasicOps(unittest.TestCase): ...@@ -330,7 +332,7 @@ class TestBasicOps(unittest.TestCase):
self.assertRaises(ValueError, islice, xrange(10), 1, 'a') self.assertRaises(ValueError, islice, xrange(10), 1, 'a')
self.assertRaises(ValueError, islice, xrange(10), 'a', 1, 1) self.assertRaises(ValueError, islice, xrange(10), 'a', 1, 1)
self.assertRaises(ValueError, islice, xrange(10), 1, 'a', 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): def test_takewhile(self):
data = [1, 3, 5, 20, 2, 4, 6, 8] data = [1, 3, 5, 20, 2, 4, 6, 8]
......
...@@ -540,7 +540,8 @@ class Test_TestLoader(TestCase): ...@@ -540,7 +540,8 @@ class Test_TestLoader(TestCase):
# audioop should now be loaded, thanks to loadTestsFromName() # audioop should now be loaded, thanks to loadTestsFromName()
self.failUnless(module_name in sys.modules) self.failUnless(module_name in sys.modules)
finally: finally:
del sys.modules[module_name] if module_name in sys.modules:
del sys.modules[module_name]
################################################################ ################################################################
### Tests for TestLoader.loadTestsFromName() ### Tests for TestLoader.loadTestsFromName()
...@@ -936,7 +937,8 @@ class Test_TestLoader(TestCase): ...@@ -936,7 +937,8 @@ class Test_TestLoader(TestCase):
# audioop should now be loaded, thanks to loadTestsFromName() # audioop should now be loaded, thanks to loadTestsFromName()
self.failUnless(module_name in sys.modules) self.failUnless(module_name in sys.modules)
finally: finally:
del sys.modules[module_name] if module_name in sys.modules:
del sys.modules[module_name]
################################################################ ################################################################
### /Tests for TestLoader.loadTestsFromNames() ### /Tests for TestLoader.loadTestsFromNames()
......
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