python_test.py 780 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright Daniel Wallin 2006. Distributed under the
  2. # Boost Software License, Version 1.0. (See accompanying file
  3. # LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. '''
  5. >>> from python_test_ext import X
  6. >>> x = X(y = 'baz')
  7. >>> x.value
  8. 'foobaz'
  9. >>> x.f(1,2)
  10. 3
  11. >>> x.f(1,2,3)
  12. 6
  13. >>> x.f(1,2, z = 3)
  14. 6
  15. >>> x.f(z = 3, y = 2, x = 1)
  16. 6
  17. >>> x.g()
  18. 'foobar'
  19. >>> x.g(y = "baz")
  20. 'foobaz'
  21. >>> x.g(x = "baz")
  22. 'bazbar'
  23. >>> x.g(y = "foo", x = "bar")
  24. 'barfoo'
  25. >>> y = x.h(x = "bar", y = "foo")
  26. >>> assert x == y
  27. >>> y = x(0)
  28. >>> assert x == y
  29. '''
  30. def run(args = None):
  31. if args is not None:
  32. import sys
  33. sys.argv = args
  34. import doctest, python_test
  35. return doctest.testmod(python_test)
  36. if __name__ == '__main__':
  37. import sys
  38. sys.exit(run()[0])