Browse Source

closes #497 - fix show_header_title not corretly setting visibility

1.0.4-release--issue-470
Chris 4 years ago
parent
commit
36ab13c59d
4 changed files with 78 additions and 4 deletions
  1. 11
      gooey/gui/components/header.py
  2. 3
      gooey/tests/harness.py
  3. 66
      gooey/tests/test_header.py
  4. 2
      gooey/tests/test_radiogroup.py

11
gooey/gui/components/header.py

@ -95,7 +95,14 @@ class FrameHeader(wx.Panel):
def build_heading_sizer(self):
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.AddStretchSpacer(1)
sizer.Add(self._header, 0)
sizer.Add(self._subheader, 0)
if self.buildSpec['header_show_title']:
sizer.Add(self._header, 0)
else:
self._header.Hide()
if self.buildSpec['header_show_subtitle']:
sizer.Add(self._subheader, 0)
else:
self._subheader.Hide()
sizer.AddStretchSpacer(1)
return sizer

3
gooey/tests/harness.py

@ -5,6 +5,7 @@ import wx
from 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
@ -13,7 +14,7 @@ def instrumentGooey(parser, **kwargs):
Context manager used during testing for setup/tear down of the
WX infrastructure during subTests.
"""
buildspec = create_from_parser(parser, "", **defaults)
buildspec = create_from_parser(parser, "", **merge(defaults, kwargs))
app, gooey = application.build_app(buildspec)
try:
yield (app, gooey)

66
gooey/tests/test_header.py

@ -0,0 +1,66 @@
import unittest
from argparse import ArgumentParser
from itertools import *
from tests.harness import instrumentGooey
class TestGooeyHeader(unittest.TestCase):
def make_parser(self):
parser = ArgumentParser(description='description')
return parser
def test_header_visibility(self):
"""
Test that the title and subtitle components correctly show/hide
based on config settings.
Verifying Issue #497
"""
for testdata in self.testcases():
with self.subTest(testdata):
with instrumentGooey(self.make_parser(), **testdata) as (app, gooeyApp):
header = gooeyApp.header
self.assertEqual(
header._header.IsShown(),
testdata.get('header_show_title', True)
)
self.assertEqual(
header._subheader.IsShown(),
testdata.get('header_show_subtitle', True)
)
def test_header_string(self):
"""
Verify that string in the buildspec get correctly
placed into the UI.
"""
parser = ArgumentParser(description='Foobar')
with instrumentGooey(parser, program_name='BaZzEr') as (app, gooeyApp):
self.assertEqual(gooeyApp.header._header.GetLabelText(), 'BaZzEr')
self.assertEqual(gooeyApp.header._subheader.GetLabelText(), 'Foobar')
def testcases(self):
"""
Generate a powerset of all possible combinations of
the header parameters (empty, some present, all present, all combos)
"""
iterable = product(['header_show_title', 'header_show_subtitle'], [True, False])
allCombinations = list(powerset(iterable))
return [{k: v for k,v in args}
for args in allCombinations]
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
if __name__ == '__main__':
unittest.main()

2
gooey/tests/test_radiogroup.py

@ -94,7 +94,7 @@ class TestRadioGroupBehavior(unittest.TestCase):
for scenario in testcase['scenario']:
targetButton = scenario['clickButton']
event = wx.CommandEvent(wx.wxEVT_LEFT_DOWN, wx.NewId())
event = wx.CommandEvent(wx.wxEVT_LEFT_DOWN, wx.Window.NewControlId())
event.SetEventObject(radioGroup.radioButtons[targetButton])
radioGroup.radioButtons[targetButton].ProcessEvent(event)

Loading…
Cancel
Save