dict.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 dict_ext import *
  7. >>> def printer(*args):
  8. ... for x in args: print(x, end='')
  9. ... print('')
  10. ...
  11. >>> print(new_dict())
  12. {}
  13. >>> print(data_dict())
  14. {1: {'key2': 'value2'}, 'key1': 'value1'}
  15. >>> tmp = data_dict()
  16. >>> print(dict_keys(tmp))
  17. [1, 'key1']
  18. >>> print(dict_values(tmp))
  19. [{'key2': 'value2'}, 'value1']
  20. >>> print(dict_items(tmp))
  21. [(1, {'key2': 'value2'}), ('key1', 'value1')]
  22. >>> print(dict_from_sequence([(1,1),(2,2),(3,3)]))
  23. {1: 1, 2: 2, 3: 3}
  24. >>> test_templates(printer) #doctest: +NORMALIZE_WHITESPACE
  25. a test string
  26. 13
  27. None
  28. {1.5: 13, 1: 'a test string'}
  29. default
  30. default
  31. """
  32. def run(args = None):
  33. import sys
  34. import doctest
  35. if args is not None:
  36. sys.argv = args
  37. return doctest.testmod(sys.modules.get(__name__))
  38. if __name__ == '__main__':
  39. print("running...")
  40. import sys
  41. status = run()[0]
  42. if (status == 0): print("Done.")
  43. sys.exit(status)