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.

46 lines
1.7 KiB

  1. import os
  2. import time
  3. from concurrent import futures
  4. from gooey.gui.util.freeze import getResourcePath
  5. from gooey.python_bindings import config_generator
  6. from gooey.util.functional import merge
  7. def run_integration(module, assertionFunction, **kwargs):
  8. """
  9. Integration test harness.
  10. WXPython is *super* finicky when it comes to integration tests. It needs
  11. the main Python thread for its app loop, which means we have to integration
  12. test on a separate thread. The causes further strangeness in how Unittest
  13. and WXPython interact. In short, each test must be in its own module and
  14. thus import its own wx instance, and be run in its own "space."
  15. So long as the above is satisfied, then integration tests can run reliably.
  16. """
  17. from gooey.gui import application
  18. options = merge({
  19. 'image_dir': '::gooey/default',
  20. 'language_dir': getResourcePath('languages'),
  21. 'show_success_modal': False
  22. }, kwargs)
  23. module_path = os.path.abspath(module.__file__)
  24. parser = module.get_parser()
  25. build_spec = config_generator.create_from_parser(parser, module_path, **options)
  26. time.sleep(2)
  27. app = application.build_app(build_spec=build_spec)
  28. executor = futures.ThreadPoolExecutor(max_workers=1)
  29. # executor runs in parallel and will submit a wx.Destroy request
  30. # when done making its assertions
  31. testResult = executor.submit(assertionFunction, app, build_spec)
  32. # main loop blocks the main thread
  33. app.MainLoop()
  34. # .result() blocks as well while we wait for the thread to finish
  35. # any waiting it may be doing.
  36. testResult.result()
  37. del app