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.1 KiB

  1. import unittest
  2. from argparse import ArgumentParser
  3. from itertools import *
  4. from 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, gooeyApp):
  19. header = gooeyApp.header
  20. self.assertEqual(
  21. header._header.IsShown(),
  22. testdata.get('header_show_title', True)
  23. )
  24. self.assertEqual(
  25. header._subheader.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, gooeyApp):
  35. self.assertEqual(gooeyApp.header._header.GetLabelText(), 'BaZzEr')
  36. self.assertEqual(gooeyApp.header._subheader.GetLabelText(), '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()