mirror of https://github.com/chriskiehl/Gooey.git
Chris
4 years ago
17 changed files with 140 additions and 60 deletions
Split View
Diff Options
-
33gooey/gui/application.py
-
55gooey/gui/containers/application.py
-
43gooey/tests/__init__.py
-
20gooey/tests/harness.py
-
21gooey/tests/test_application.py
-
2gooey/tests/test_argparse_to_json.py
-
2gooey/tests/test_chooser_results.py
-
2gooey/tests/test_cmd_args.py
-
2gooey/tests/test_config_generator.py
-
2gooey/tests/test_constraints.py
-
2gooey/tests/test_dropdown.py
-
2gooey/tests/test_filterable_dropdown.py
-
2gooey/tests/test_header.py
-
2gooey/tests/test_parent_inheritance.py
-
4gooey/tests/test_radiogroup.py
-
4gooey/tests/test_time_remaining.py
-
2gooey/tests/test_util.py
@ -0,0 +1,43 @@ |
|||
""" |
|||
This weirdness exists to work around a very specific problem |
|||
with testing WX: you can only ever have one App() instance per |
|||
process. I've spent hours and hours trying to work around this and |
|||
figure out how to gracefully destroy and recreate them, but... no dice. |
|||
|
|||
This is echo'd in the docs: https://wxpython.org/Phoenix/docs/html/wx.App.html |
|||
|
|||
Destroying/recreating causes instability in the tests. We can work around that |
|||
by reusing the same App instance across tests and only destroying the top level |
|||
frame (which is fine). However, this causes a new problem: the last test which |
|||
runs will now always fail, cause we're not Destroying the App instance. |
|||
|
|||
Ideal world: UnitTest would expose a global "done" hook regardless of test |
|||
discovery type. That doesn't exist, so the best we can do is use the Module cleanup |
|||
methods. These aren't perfect, but destroying / recreating at the module boundary |
|||
gives slightly more reliable tests. These are picked up by the test runner |
|||
by their existence in the module's globals(). There's no other way to hook |
|||
things together. We need it in every test, and thus... that's the background |
|||
for why this weirdness is going on. |
|||
|
|||
It's a hack around a hack around a problem in Wx. |
|||
|
|||
Usage: |
|||
|
|||
In any tests which use WX, you must import this module's definitions |
|||
into the test's global scope |
|||
|
|||
``` |
|||
from gooey.tests import * |
|||
``` |
|||
""" |
|||
import wx |
|||
|
|||
app = None |
|||
|
|||
def setUpModule(): |
|||
global app |
|||
app = wx.App() |
|||
|
|||
def tearDownModule(): |
|||
global app |
|||
app.Destroy() |
@ -1,24 +1,38 @@ |
|||
from contextlib import contextmanager |
|||
|
|||
import time |
|||
from threading import Thread |
|||
|
|||
import wx |
|||
|
|||
from gui import application |
|||
from gooey.gui import application |
|||
from python_bindings.config_generator import create_from_parser |
|||
from python_bindings.gooey_decorator import defaults |
|||
from util.functional import merge |
|||
|
|||
|
|||
|
|||
|
|||
@contextmanager |
|||
def instrumentGooey(parser, **kwargs): |
|||
""" |
|||
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, "", **merge(defaults, kwargs)) |
|||
app, gooey = application.build_app(buildspec) |
|||
app, gooey = application._build_app(buildspec, app) |
|||
app.SetTopWindow(gooey) |
|||
try: |
|||
yield (app, gooey) |
|||
finally: |
|||
wx.CallAfter(app.ExitMainLoop) |
|||
gooey.Destroy() |
|||
app.Destroy() |
|||
app.SetTopWindow(None) |
|||
del gooey |
Write
Preview
Loading…
Cancel
Save