mirror of https://github.com/python/cpython
Merged revisions 86175 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r86175 | antoine.pitrou | 2010-11-04 21:48:37 +0100 (jeu., 04 nov. 2010) | 4 lines Issue #3699: Fix test_bigaddrspace and extend it to test bytestrings as well as unicode strings. Initial patch by Sandro Tosi. ........
This commit is contained in:
parent
650c085740
commit
020e09a5b4
|
@ -1,3 +1,13 @@
|
||||||
|
"""
|
||||||
|
These tests are meant to exercise that requests to create objects bigger
|
||||||
|
than what the address space allows are properly met with an OverflowError
|
||||||
|
(rather than crash weirdly).
|
||||||
|
|
||||||
|
Primarily, this means 32-bit builds with at least 2 GB of available memory.
|
||||||
|
You need to pass the -M option to regrtest (e.g. "-M 2.1G") for tests to
|
||||||
|
be enabled.
|
||||||
|
"""
|
||||||
|
|
||||||
from test import support
|
from test import support
|
||||||
from test.support import bigaddrspacetest, MAX_Py_ssize_t
|
from test.support import bigaddrspacetest, MAX_Py_ssize_t
|
||||||
|
|
||||||
|
@ -6,39 +16,66 @@ import operator
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class StrTest(unittest.TestCase):
|
class BytesTest(unittest.TestCase):
|
||||||
|
|
||||||
@bigaddrspacetest
|
@bigaddrspacetest
|
||||||
def test_concat(self):
|
def test_concat(self):
|
||||||
s1 = 'x' * MAX_Py_ssize_t
|
# Allocate a bytestring that's near the maximum size allowed by
|
||||||
self.assertRaises(OverflowError, operator.add, s1, '?')
|
# 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)
|
||||||
|
|
||||||
@bigaddrspacetest
|
@bigaddrspacetest
|
||||||
def test_optimized_concat(self):
|
def test_optimized_concat(self):
|
||||||
x = 'x' * MAX_Py_ssize_t
|
x = b"x" * (MAX_Py_ssize_t - 128)
|
||||||
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)
|
|
||||||
|
|
||||||
### the following test is pending a patch
|
with self.assertRaises(OverflowError) as cm:
|
||||||
# (http://mail.python.org/pipermail/python-dev/2006-July/067774.html)
|
# this statement uses a fast path in ceval.c
|
||||||
#@bigaddrspacetest
|
x = x + b"x" * 128
|
||||||
#def test_repeat(self):
|
|
||||||
# self.assertRaises(OverflowError, operator.mul, 'x', MAX_Py_ssize_t + 1)
|
with self.assertRaises(OverflowError) as cm:
|
||||||
|
# this statement uses a fast path in ceval.c
|
||||||
|
x += b"x" * 128
|
||||||
|
|
||||||
|
@bigaddrspacetest
|
||||||
|
def test_repeat(self):
|
||||||
|
x = b"x" * (MAX_Py_ssize_t - 128)
|
||||||
|
self.assertRaises(OverflowError, operator.mul, x, 128)
|
||||||
|
|
||||||
|
|
||||||
|
class StrTest(unittest.TestCase):
|
||||||
|
|
||||||
|
unicodesize = 2 if sys.maxunicode < 65536 else 4
|
||||||
|
|
||||||
|
@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)
|
||||||
|
|
||||||
|
@bigaddrspacetest
|
||||||
|
def test_optimized_concat(self):
|
||||||
|
x = "x" * (MAX_Py_ssize_t // (2 * 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
|
||||||
|
|
||||||
|
@bigaddrspacetest
|
||||||
|
def test_repeat(self):
|
||||||
|
x = "x" * (MAX_Py_ssize_t // (2 * self.unicodesize))
|
||||||
|
self.assertRaises(MemoryError, operator.mul, x, 2)
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
support.run_unittest(StrTest)
|
support.run_unittest(BytesTest, StrTest)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
|
|
|
@ -702,6 +702,9 @@ Build
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
- Issue #3699: Fix test_bigaddrspace and extend it to test bytestrings
|
||||||
|
as well as unicode strings. Initial patch by Sandro Tosi.
|
||||||
|
|
||||||
- Issue #9628: fix runtests.sh -x option so more than one test can be excluded.
|
- Issue #9628: fix runtests.sh -x option so more than one test can be excluded.
|
||||||
|
|
||||||
- Issue #9894: Do not hardcode ENOENT in test_subprocess.
|
- Issue #9894: Do not hardcode ENOENT in test_subprocess.
|
||||||
|
|
Loading…
Reference in New Issue