tuple.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. from __future__ import print_function
  5. """
  6. >>> from tuple_ext import *
  7. >>> def printer(*args):
  8. ... for x in args: print(x,)
  9. ... print('')
  10. ...
  11. >>> print(convert_to_tuple("this is a test string"))
  12. ('t', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', 's', 't', ' ', 's', 't', 'r', 'i', 'n', 'g')
  13. >>> t1 = convert_to_tuple("this is")
  14. >>> t2 = (1,2,3,4)
  15. >>> test_operators(t1,t2,printer) #doctest: +NORMALIZE_WHITESPACE
  16. ('t', 'h', 'i', 's', ' ', 'i', 's', 1, 2, 3, 4)
  17. >>> make_tuple()
  18. ()
  19. >>> make_tuple(42)
  20. (42,)
  21. >>> make_tuple('hello', 42)
  22. ('hello', 42)
  23. """
  24. def run(args = None):
  25. import sys
  26. import doctest
  27. if args is not None:
  28. sys.argv = args
  29. return doctest.testmod(sys.modules.get(__name__))
  30. if __name__ == '__main__':
  31. print("running...")
  32. import sys
  33. status = run()[0]
  34. if (status == 0): print("Done.")
  35. sys.exit(status)