implicit.py 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 implicit_ext import *
  6. >>> x_value(X(42))
  7. 42
  8. >>> x_value(42)
  9. 42
  10. >>> x = make_x(X(42))
  11. >>> x.value()
  12. 42
  13. >>> try: make_x('fool')
  14. ... except TypeError: pass
  15. ... else: print('no error')
  16. >>> print(x_value.__doc__.splitlines()[1])
  17. x_value( (X)arg1) -> int :
  18. >>> print(make_x.__doc__.splitlines()[1])
  19. make_x( (object)arg1) -> X :
  20. >>> print(X.value.__doc__.splitlines()[1])
  21. value( (X)arg1) -> int :
  22. >>> print(X.set.__doc__.splitlines()[1])
  23. set( (X)arg1, (object)arg2) -> None :
  24. '''
  25. def run(args = None):
  26. import sys
  27. import doctest
  28. if args is not None:
  29. sys.argv = args
  30. return doctest.testmod(sys.modules.get(__name__))
  31. if __name__ == '__main__':
  32. print("running...")
  33. import sys
  34. status = run()[0]
  35. if (status == 0): print("Done.")
  36. sys.exit(status)