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