diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-01-12 22:02:45 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-01-12 22:02:45 (GMT) |
commit | 1e28513d256ff8a378f44cbc3c4e451b12113eca (patch) | |
tree | 0cbd2919e8382e968bba1f7c789cc543e6562069 /Lib/test/test_bigaddrspace.py | |
parent | 98c62bd1c8facd131a21d7ae7bcf077e0a774acd (diff) | |
download | cpython-1e28513d256ff8a378f44cbc3c4e451b12113eca.zip cpython-1e28513d256ff8a378f44cbc3c4e451b12113eca.tar.gz cpython-1e28513d256ff8a378f44cbc3c4e451b12113eca.tar.bz2 |
Fix test_bigaddrspace (some tests didn't trigger the expected MemoryError)
Diffstat (limited to 'Lib/test/test_bigaddrspace.py')
-rw-r--r-- | Lib/test/test_bigaddrspace.py | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/Lib/test/test_bigaddrspace.py b/Lib/test/test_bigaddrspace.py index d383440..b8c59d4 100644 --- a/Lib/test/test_bigaddrspace.py +++ b/Lib/test/test_bigaddrspace.py @@ -23,25 +23,34 @@ class BytesTest(unittest.TestCase): # Allocate a bytestring that's near the maximum size allowed by # the address space, and then try to build a new, larger one through # concatenation. - x = b"x" * (MAX_Py_ssize_t - 128) - self.assertRaises(OverflowError, operator.add, x, b"x" * 128) + try: + x = b"x" * (MAX_Py_ssize_t - 128) + self.assertRaises(OverflowError, operator.add, x, b"x" * 128) + finally: + x = None @bigaddrspacetest def test_optimized_concat(self): - x = b"x" * (MAX_Py_ssize_t - 128) + try: + x = b"x" * (MAX_Py_ssize_t - 128) - with self.assertRaises(OverflowError) as cm: - # this statement uses a fast path in ceval.c - x = x + b"x" * 128 + with self.assertRaises(OverflowError) as cm: + # this statement used a fast path in ceval.c + x = x + b"x" * 128 - with self.assertRaises(OverflowError) as cm: - # this statement uses a fast path in ceval.c - x += b"x" * 128 + with self.assertRaises(OverflowError) as cm: + # this statement used a fast path in ceval.c + x += b"x" * 128 + finally: + x = None @bigaddrspacetest def test_repeat(self): - x = b"x" * (MAX_Py_ssize_t - 128) - self.assertRaises(OverflowError, operator.mul, x, 128) + try: + x = b"x" * (MAX_Py_ssize_t - 128) + self.assertRaises(OverflowError, operator.mul, x, 128) + finally: + x = None class StrTest(unittest.TestCase): @@ -50,28 +59,37 @@ class StrTest(unittest.TestCase): @bigaddrspacetest def test_concat(self): - # Create a string half the size that would fill the address space - x = "x" * (MAX_Py_ssize_t // (2 * self.unicodesize)) - # Unicode objects trigger MemoryError in case an operation that's - # going to cause a size overflow is executed - self.assertRaises(MemoryError, operator.add, x, x) + try: + # Create a string that would fill almost the address space + x = "x" * int(MAX_Py_ssize_t // (1.1 * self.unicodesize)) + # Unicode objects trigger MemoryError in case an operation that's + # going to cause a size overflow is executed + self.assertRaises(MemoryError, operator.add, x, x) + finally: + x = None @bigaddrspacetest def test_optimized_concat(self): - x = "x" * (MAX_Py_ssize_t // (2 * self.unicodesize)) + try: + x = "x" * int(MAX_Py_ssize_t // (1.1 * self.unicodesize)) - with self.assertRaises(MemoryError) as cm: - # this statement uses a fast path in ceval.c - x = x + x + with self.assertRaises(MemoryError) as cm: + # this statement uses a fast path in ceval.c + x = x + x - with self.assertRaises(MemoryError) as cm: - # this statement uses a fast path in ceval.c - x += x + with self.assertRaises(MemoryError) as cm: + # this statement uses a fast path in ceval.c + x += x + finally: + x = None @bigaddrspacetest def test_repeat(self): - x = "x" * (MAX_Py_ssize_t // (2 * self.unicodesize)) - self.assertRaises(MemoryError, operator.mul, x, 2) + try: + x = "x" * int(MAX_Py_ssize_t // (1.1 * self.unicodesize)) + self.assertRaises(MemoryError, operator.mul, x, 2) + finally: + x = None def test_main(): |