/Lib/test/test_bigaddrspace.py

http://unladen-swallow.googlecode.com/ · Python · 46 lines · 32 code · 9 blank · 5 comment · 8 complexity · 530fc44827c7df723f4edde2e1b3be74 MD5 · raw file

  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 eval.cc
  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 eval.cc
  22. except OverflowError:
  23. pass
  24. else:
  25. self.fail("should have raised OverflowError")
  26. self.assertEquals(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()