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.

57 lines
1.7 KiB

2 years ago
  1. import unittest
  2. from gooey.tests.harness import instrumentGooey
  3. from gooey import GooeyParser
  4. from gooey.tests import *
  5. class TestCheckbox(unittest.TestCase):
  6. def makeParser(self, **kwargs):
  7. parser = GooeyParser(description='description')
  8. parser.add_argument(
  9. '--widget',
  10. action='store_true',
  11. **kwargs)
  12. return parser
  13. def testInitialValue(self):
  14. cases = [
  15. # `initial` should supersede `default`
  16. {'inputs': {'default': False,
  17. 'widget': 'CheckBox',
  18. 'gooey_options': {'initial_value': True}},
  19. 'expect': True},
  20. {'inputs': {'gooey_options': {'initial_value': True},
  21. 'widget': 'CheckBox'},
  22. 'expect': True},
  23. {'inputs': {'gooey_options': {'initial_value': False},
  24. 'widget': 'CheckBox'},
  25. 'expect': False},
  26. {'inputs': {'default': True,
  27. 'widget': 'CheckBox',
  28. 'gooey_options': {}},
  29. 'expect': True},
  30. {'inputs': {'default': True,
  31. 'widget': 'CheckBox'},
  32. 'expect': True},
  33. {'inputs': {'widget': 'CheckBox'},
  34. 'expect': False}
  35. ]
  36. for case in cases:
  37. with self.subTest(case):
  38. parser = self.makeParser(**case['inputs'])
  39. with instrumentGooey(parser) as (app, frame, gapp):
  40. widget = gapp.getActiveConfig().reifiedWidgets[0]
  41. self.assertEqual(widget.getValue()['rawValue'], case['expect'])
  42. if __name__ == '__main__':
  43. unittest.main()