class.py 883 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # 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 class_ext import *
  6. Ensure sanity:
  7. >>> x = X(42)
  8. >>> x_function(x)
  9. 42
  10. Demonstrate extraction in the presence of metaclass changes:
  11. >>> class MetaX(X.__class__):
  12. ... def __new__(cls, *args):
  13. ... return super(MetaX, cls).__new__(cls, *args)
  14. >>> class XPlusMetatype(X):
  15. ... __metaclass__ = MetaX
  16. >>> x = XPlusMetatype(42)
  17. >>> x_function(x)
  18. 42
  19. '''
  20. def run(args = None):
  21. import sys
  22. import doctest
  23. if args is not None:
  24. sys.argv = args
  25. return doctest.testmod(sys.modules.get(__name__))
  26. if __name__ == '__main__':
  27. print("running...")
  28. import sys
  29. status = run()[0]
  30. if (status == 0): print("Done.")
  31. sys.exit(status)