PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/stacklesslib/stacklesslib/test/teststdlibunittests.py

http://stacklessexamples.googlecode.com/
Python | 74 lines | 46 code | 19 blank | 9 comment | 10 complexity | 137175f28d9c625101c7fe5edae7e729 MD5 | raw file
  1. """
  2. This unit test script should not implement any unit tests of its own.
  3. Its goal is to wrap the running of standard library unit tests again the
  4. monkey-patched environment that stacklesslib provides.
  5. TODO:
  6. - pump() blocks for at least a second. why? where?
  7. """
  8. from __future__ import absolute_import
  9. # Ruin wonderful PEP-8 ordering with pre-emptive monkey-patch.
  10. import stacklesslib.magic
  11. stacklesslib.magic.monkeypatch()
  12. import asyncore
  13. import traceback
  14. import sys
  15. import stackless
  16. import stacklesslib.main
  17. elapsed_time = stacklesslib.main.elapsed_time
  18. def run_unittests():
  19. from test import test_socket
  20. from test import test_urllib
  21. from test import test_urllib2
  22. from test import test_xmlrpc
  23. print "** run_unittests.test_socket"
  24. test_socket.test_main()
  25. print "** run_unittests.test_urllib"
  26. test_urllib.test_main()
  27. print "** run_unittests.test_urllib2"
  28. test_urllib2.test_main()
  29. print "** run_unittests.test_xmlrpc"
  30. test_xmlrpc.test_main()
  31. print "** run_unittests - done"
  32. def new_tasklet(f, *args, **kwargs):
  33. try:
  34. f(*args, **kwargs)
  35. except Exception:
  36. traceback.print_exc()
  37. if __name__ == "__main__":
  38. run_unittests_tasklet = stackless.tasklet(new_tasklet)(run_unittests)
  39. while run_unittests_tasklet.alive:
  40. tick_time = elapsed_time()
  41. wait_time = stacklesslib.main.mainloop.get_wait_time(tick_time)
  42. try:
  43. stacklesslib.main.mainloop.pump()
  44. asyncore.poll(0.05)
  45. except Exception, e:
  46. import asyncore
  47. if isinstance(e, ReferenceError):
  48. print "run:EXCEPTION", str(e), asyncore.socket_map
  49. else:
  50. print "run:EXCEPTION", asyncore.socket_map
  51. traceback.print_exc()
  52. sys.exc_clear()
  53. if False and elapsed_time() - tick_time > 0.1:
  54. print "Pump took too long: %0.5f" % (elapsed_time() - tick_time)