diff -r 8c8bb16eb3ff -r 2044f4e2728a Lib/test/test_bigaddrspace.py --- a/Lib/test/test_bigaddrspace.py Mon Nov 01 17:40:17 2010 +0100 +++ b/Lib/test/test_bigaddrspace.py Thu Nov 04 00:47:49 2010 +0100 @@ -6,39 +6,35 @@ import sys -class StrTest(unittest.TestCase): +class ByteTest(unittest.TestCase): @bigaddrspacetest def test_concat(self): - s1 = 'x' * MAX_Py_ssize_t - self.assertRaises(OverflowError, operator.add, s1, '?') + # this is a "dirty trick" - since just multiplying b"x" with + # MAX_Py_ssize_t generates an OverflowError before actually + # testing the operator.add, we multiply b"x" for a value 'a bit + # less than MAX_Py_ssize_t, and then readd the missing 'bit' later + s1 = b"x" * (MAX_Py_ssize_t - 128) + self.assertRaises(OverflowError, operator.add, s1, b"x" * 128) @bigaddrspacetest def test_optimized_concat(self): - x = 'x' * MAX_Py_ssize_t - try: - x = x + '?' # this statement uses a fast path in ceval.c - except OverflowError: - pass - else: - self.fail("should have raised OverflowError") - try: - x += '?' # this statement uses a fast path in ceval.c - except OverflowError: - pass - else: - self.fail("should have raised OverflowError") - self.assertEquals(len(x), MAX_Py_ssize_t) + x = b"x" * (MAX_Py_ssize_t - 128) - ### the following test is pending a patch - # (http://mail.python.org/pipermail/python-dev/2006-July/067774.html) - #@bigaddrspacetest - #def test_repeat(self): - # self.assertRaises(OverflowError, operator.mul, 'x', MAX_Py_ssize_t + 1) + with self.assertRaises(OverflowError) as cm: + x = x + b"x" * 128 # this statement uses a fast path in ceval.c + + with self.assertRaises(OverflowError) as cm: + x += b"x" * 128 # this statement uses a fast path in ceval.c + + @bigaddrspacetest + def test_repeat(self): + s1 = b"x" * (MAX_Py_ssize_t - 128) + self.assertRaises(OverflowError, operator.mul, s1, 128) def test_main(): - support.run_unittest(StrTest) + support.run_unittest(ByteTest) if __name__ == '__main__': if len(sys.argv) > 1: