Ejemplo n.º 1
0
def instrumentGooey(parser, **kwargs) -> Tuple[wx.App, wx.Frame, RGooey]:
    """
    Context manager used during testing for setup/tear down of the
    WX infrastructure during subTests.

    Weirdness warning: this uses a globally reused wx.App instance.
    """
    from gooey.tests import app
    if app == None:
        raise Exception(
            "App instance has not been created! This is likely due to "
            "you forgetting to add the magical import which makes all these "
            "tests work. See the module doc in gooey.tests.__init__ for guidance"
        )
    buildspec = create_from_parser(parser, "", **gooey_params(**kwargs))
    app, frame = bootstrap._build_app(buildspec, app)
    app.SetTopWindow(frame)
    try:
        # we need to run the main loop temporarily to get it to
        # apply any pending updates from the initial creation.
        # The UI state will be stale otherwise
        # this works because CallLater just enqueues the message to
        # be processed. The MainLoop starts running, picks it up, and
        # then exists
        wx.CallLater(1, app.ExitMainLoop)
        app.MainLoop()
        yield (app, frame, frame._instance)
    finally:
        frame.Destroy()
        del frame
Ejemplo n.º 2
0
def do_build_script(module_path):
  with open(module_path, 'r') as f:
    if not source_parser.has_argparse(f.read()):
      raise AssertionError('Argparse not found in module. Unable to continue')

  gooey_config = config_generator.create_from_parser(module_path, show_config=True)
  outfile = os.path.join(os.getcwd(), 'gooey_config.json')

  print 'Writing config file to: {}'.format(outfile)

  with open(outfile, 'w') as f:
    f.write(json.dumps(gooey_config, indent=2))
Ejemplo n.º 3
0
def do_build_script(module_path):
    with open(module_path, 'r') as f:
        if not source_parser.has_argparse(f.read()):
            raise AssertionError(
                'Argparse not found in module. Unable to continue')

    gooey_config = config_generator.create_from_parser(module_path,
                                                       show_config=True)
    outfile = os.path.join(os.getcwd(), 'gooey_config.json')

    print 'Writing config file to: {}'.format(outfile)

    with open(outfile, 'w') as f:
        f.write(json.dumps(gooey_config, indent=2))
Ejemplo n.º 4
0
def run_integration(module, assertionFunction, **kwargs):
    """
    Integration test harness.

    WXPython is *super* finicky when it comes to integration tests. It needs
    the main Python thread for its app loop, which means we have to integration
    test on a separate thread. The causes further strangeness in how Unittest
    and WXPython interact. In short, each test must be in its own module and
    thus import its own wx instance, and be run in its own "space."

    So long as the above is satisfied, then integration tests can run reliably.

    """
    from gooey.gui import application
    options = merge(
        {
            'image_dir': '::gooey/default',
            'language_dir': getResourcePath('languages'),
            'show_success_modal': False
        }, kwargs)
    module_path = os.path.abspath(module.__file__)
    parser = module.get_parser()
    build_spec = config_generator.create_from_parser(parser, module_path,
                                                     **options)

    time.sleep(2)
    app = application.build_app(build_spec=build_spec)
    executor = futures.ThreadPoolExecutor(max_workers=1)
    # executor runs in parallel and will submit a wx.Destroy request
    # when done making its assertions
    testResult = executor.submit(assertionFunction, app, build_spec)
    # main loop blocks the main thread
    app.MainLoop()
    # .result() blocks as well while we wait for the thread to finish
    # any waiting it may be doing.
    testResult.result()
    del app
Ejemplo n.º 5
0
def build_spec_subparser(subparser):
  return config_generator.create_from_parser(subparser, sys.argv[0])
Ejemplo n.º 6
0
def build_spec(complete_parser):
  return config_generator.create_from_parser(complete_parser, sys.argv[0])
Ejemplo n.º 7
0
def build_spec_subparser(subparser):
    return config_generator.create_from_parser(subparser, sys.argv[0])
Ejemplo n.º 8
0
def build_spec(complete_parser):
    return config_generator.create_from_parser(complete_parser, sys.argv[0])