slice.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright David Abrahams 2004. Distributed under the Boost
  2. # Software License, Version 1.0. (See accompanying
  3. # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. """
  5. >>> from slice_ext import *
  6. >>> accept_slice(slice(1, None, (1,2)))
  7. 1
  8. >>> try:
  9. ... accept_slice(list((1,2)))
  10. ... print("test failed")
  11. ... except:
  12. ... print("test passed")
  13. ...
  14. test passed
  15. >>> import sys
  16. >>> if sys.version_info[0] == 2 and sys.version_info[1] >= 3:
  17. ... check_string_rich_slice()
  18. ... elif sys.version_info[0] > 2:
  19. ... check_string_rich_slice()
  20. ... else:
  21. ... print(1)
  22. ...
  23. 1
  24. >>> check_slice_get_indices( slice(None))
  25. 0
  26. >>> check_slice_get_indices( slice(2,-2))
  27. 0
  28. >>> check_slice_get_indices( slice(2, None, 2))
  29. 5
  30. >>> check_slice_get_indices( slice(2, None, -1))
  31. -12
  32. >>> check_slice_get_indices( slice( 20, None))
  33. 0
  34. >>> check_slice_get_indices( slice( -2, -5, -2))
  35. 6
  36. """
  37. # Performs an affirmative and negative argument resolution check.
  38. # checks the operation of extended slicing in new strings (Python 2.3 only).
  39. def run(args = None):
  40. import sys
  41. import doctest
  42. if args is not None:
  43. sys.argv = args
  44. return doctest.testmod(sys.modules.get(__name__))
  45. if __name__ == '__main__':
  46. print("running...")
  47. import sys
  48. status = run()[0]
  49. if (status == 0): print("Done.")
  50. sys.exit(status)