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.

50 lines
1.3 KiB

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