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