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.

65 lines
2.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
  1. import unittest
  2. from argparse import ArgumentParser
  3. from itertools import *
  4. from gooey.tests.harness import instrumentGooey
  5. from gooey.tests import *
  6. class TestGooeyHeader(unittest.TestCase):
  7. def make_parser(self):
  8. parser = ArgumentParser(description='description')
  9. return parser
  10. def test_header_visibility(self):
  11. """
  12. Test that the title and subtitle components correctly show/hide
  13. based on config settings.
  14. Verifying Issue #497
  15. """
  16. for testdata in self.testcases():
  17. with self.subTest(testdata):
  18. with instrumentGooey(self.make_parser(), **testdata) as (app, frame, gapp):
  19. frame: wx.Frame = frame
  20. self.assertEqual(
  21. frame.FindWindowByName("header_title").IsShown(),
  22. testdata.get('header_show_title', True)
  23. )
  24. self.assertEqual(
  25. frame.FindWindowByName("header_subtitle").IsShown(),
  26. testdata.get('header_show_subtitle', True)
  27. )
  28. def test_header_string(self):
  29. """
  30. Verify that string in the buildspec get correctly
  31. placed into the UI.
  32. """
  33. parser = ArgumentParser(description='Foobar')
  34. with instrumentGooey(parser, program_name='BaZzEr') as (app, frame, gapp):
  35. self.assertEqual(frame.FindWindowByName("header_title").GetLabel(), 'BaZzEr')
  36. self.assertEqual(frame.FindWindowByName("header_subtitle").GetLabel(), 'Foobar')
  37. def testcases(self):
  38. """
  39. Generate a powerset of all possible combinations of
  40. the header parameters (empty, some present, all present, all combos)
  41. """
  42. iterable = product(['header_show_title', 'header_show_subtitle'], [True, False])
  43. allCombinations = list(powerset(iterable))
  44. return [{k: v for k,v in args}
  45. for args in allCombinations]
  46. def powerset(iterable):
  47. "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
  48. s = list(iterable)
  49. return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
  50. if __name__ == '__main__':
  51. unittest.main()