Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 1 | from test import support |
| 2 | from test.support import bigaddrspacetest, MAX_Py_ssize_t |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 3 | |
| 4 | import unittest |
| 5 | import operator |
| 6 | import sys |
| 7 | |
| 8 | |
| 9 | class StrTest(unittest.TestCase): |
| 10 | |
| 11 | @bigaddrspacetest |
| 12 | def test_concat(self): |
| 13 | s1 = 'x' * MAX_Py_ssize_t |
| 14 | self.assertRaises(OverflowError, operator.add, s1, '?') |
| 15 | |
| 16 | @bigaddrspacetest |
| 17 | def test_optimized_concat(self): |
| 18 | x = 'x' * MAX_Py_ssize_t |
| 19 | try: |
| 20 | x = x + '?' # this statement uses a fast path in ceval.c |
| 21 | except OverflowError: |
| 22 | pass |
| 23 | else: |
| 24 | self.fail("should have raised OverflowError") |
| 25 | try: |
| 26 | x += '?' # this statement uses a fast path in ceval.c |
| 27 | except OverflowError: |
| 28 | pass |
| 29 | else: |
| 30 | self.fail("should have raised OverflowError") |
| 31 | self.assertEquals(len(x), MAX_Py_ssize_t) |
| 32 | |
| 33 | ### the following test is pending a patch |
| 34 | # (http://mail.python.org/pipermail/python-dev/2006-July/067774.html) |
| 35 | #@bigaddrspacetest |
| 36 | #def test_repeat(self): |
| 37 | # self.assertRaises(OverflowError, operator.mul, 'x', MAX_Py_ssize_t + 1) |
| 38 | |
| 39 | |
| 40 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 41 | support.run_unittest(StrTest) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 42 | |
| 43 | if __name__ == '__main__': |
| 44 | if len(sys.argv) > 1: |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 45 | support.set_memlimit(sys.argv[1]) |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 46 | test_main() |