voidptr.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright Niall Douglas 2005.
  2. # Distributed under the Boost Software License, Version 1.0.
  3. # (See accompanying file LICENSE_1_0.txt or copy at
  4. # http://www.boost.org/LICENSE_1_0.txt)
  5. """
  6. >>> from voidptr_ext import *
  7. Check for correct conversion
  8. >>> use(get())
  9. Check that None is converted to a NULL void pointer
  10. >>> useany(get())
  11. 1
  12. >>> useany(None)
  13. 0
  14. Check that we don't lose type information by converting NULL
  15. opaque pointers to None
  16. >>> assert getnull() is None
  17. >>> useany(getnull())
  18. 0
  19. Check that there is no conversion from integers ...
  20. >>> try: use(0)
  21. ... except TypeError: pass
  22. ... else: print('expected a TypeError')
  23. ... and from strings to opaque objects
  24. >>> try: use("")
  25. ... except TypeError: pass
  26. ... else: print('expected a TypeError')
  27. """
  28. def run(args = None):
  29. import sys
  30. import doctest
  31. if args is not None:
  32. sys.argv = args
  33. return doctest.testmod(sys.modules.get(__name__))
  34. if __name__ == '__main__':
  35. print("running...")
  36. import sys
  37. status = run()[0]
  38. if (status == 0): print("Done.")
  39. sys.exit(status)