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.

54 lines
1.8 KiB

  1. import unittest
  2. from collections import namedtuple
  3. from tests.harness import instrumentGooey
  4. from gooey import GooeyParser
  5. from gooey.tests import *
  6. Case = namedtuple('Case', 'inputs initialExpected')
  7. class TestCommonProperties(unittest.TestCase):
  8. """
  9. Test options and functionality
  10. common across all widgets.
  11. """
  12. def makeParser(self, **kwargs):
  13. parser = GooeyParser(description='description')
  14. parser.add_argument('--widget', **kwargs)
  15. return parser
  16. def testInitialValue(self):
  17. widgets = ['ColourChooser',
  18. 'CommandField',
  19. 'DateChooser', 'DirChooser', 'FileChooser', 'FileSaver',
  20. 'FilterableDropdown', 'MultiDirChooser', 'MultiFileChooser',
  21. 'PasswordField', 'TextField', 'Textarea', 'TimeChooser']
  22. cases = [
  23. # initial_value supersedes, default
  24. Case(
  25. {'default': 'default', 'gooey_options': {'initial_value': 'some val'}},
  26. 'some val'),
  27. Case(
  28. {'gooey_options': {'initial_value': 'some val'}},
  29. 'some val'),
  30. Case(
  31. {'default': 'default', 'gooey_options': {}},
  32. 'default'),
  33. Case({'default': 'default'},
  34. 'default')
  35. ]
  36. for widgetName in widgets:
  37. with self.subTest(widgetName):
  38. for case in cases:
  39. parser = self.makeParser(widget=widgetName, **case.inputs)
  40. with instrumentGooey(parser) as (app, gooeyApp):
  41. widget = gooeyApp.configs[0].reifiedWidgets[0]
  42. self.assertEqual(widget.getValue()['rawValue'], case.initialExpected)
  43. if __name__ == '__main__':
  44. unittest.main()