You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

  1. from contextlib import contextmanager
  2. import time
  3. from threading import Thread
  4. import wx
  5. from gooey.gui import application
  6. from python_bindings.config_generator import create_from_parser
  7. from python_bindings.gooey_decorator import defaults
  8. from util.functional import merge
  9. @contextmanager
  10. def instrumentGooey(parser, **kwargs):
  11. """
  12. Context manager used during testing for setup/tear down of the
  13. WX infrastructure during subTests.
  14. Weirdness warning: this uses a globally reused wx.App instance.
  15. """
  16. from gooey.tests import app
  17. if app == None:
  18. raise Exception("App instance has not been created! This is likely due to "
  19. "you forgetting to add the magical import which makes all these "
  20. "tests work. See the module doc in gooey.tests.__init__ for guidance")
  21. buildspec = create_from_parser(parser, "", **merge(defaults, kwargs))
  22. app, gooey = application._build_app(buildspec, app)
  23. app.SetTopWindow(gooey)
  24. try:
  25. yield (app, gooey)
  26. finally:
  27. wx.CallAfter(app.ExitMainLoop)
  28. gooey.Destroy()
  29. app.SetTopWindow(None)
  30. del gooey