test_bigaddrspace.py 1.3 KB

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