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.

63 lines
2.3 KiB

  1. import unittest
  2. from unittest.mock import patch
  3. from tests.harness import instrumentGooey
  4. from gooey import GooeyParser
  5. from gooey.tests import *
  6. class TestGooeySlider(unittest.TestCase):
  7. def makeParser(self, **kwargs):
  8. parser = GooeyParser(description='description')
  9. parser.add_argument('--slider', widget="Slider", **kwargs)
  10. return parser
  11. def testSliderDefault(self):
  12. cases = [
  13. [{}, 0],
  14. [{'default': 0}, 0],
  15. [{'default': 10}, 10],
  16. [{'default': 76}, 76],
  17. # note that WX caps the value
  18. # unless explicitly widened via gooey_options
  19. [{'default': 81234}, 100],
  20. # here we set the max to something higher than
  21. # the default and all works as expected.
  22. # this is a TODO for validation
  23. [{'default': 81234, 'gooey_options': {'max': 99999}}, 81234],
  24. # Initial Value cases
  25. [{}, 0],
  26. [{'gooey_options': {'initial_value': 0}}, 0],
  27. [{'gooey_options': {'initial_value': 10}}, 10],
  28. [{'gooey_options': {'initial_value': 76}}, 76],
  29. # note that WX caps the value
  30. # unless explicitly widened via gooey_options
  31. [{'gooey_options': {'initial_value': 81234}}, 100],
  32. # here we set the max to something higher than
  33. # the default and all works as expected.
  34. # this is a TODO for validation
  35. [{'gooey_options': {'initial_value': 81234, 'max': 99999}}, 81234],
  36. ]
  37. for inputs, expected in cases:
  38. with self.subTest(inputs):
  39. parser = self.makeParser(**inputs)
  40. with instrumentGooey(parser) as (app, gooeyApp):
  41. slider = gooeyApp.configs[0].reifiedWidgets[0]
  42. self.assertEqual(slider.getValue()['rawValue'], expected)
  43. def testZerosAreReturned(self):
  44. """
  45. Originally the formatter was dropping '0' due to
  46. it being interpreted as falsey
  47. """
  48. parser = self.makeParser()
  49. with instrumentGooey(parser) as (app, gooeyApp):
  50. field = gooeyApp.configs[0].reifiedWidgets[0]
  51. result = field.getValue()
  52. self.assertEqual(result['rawValue'], 0)
  53. self.assertIsNotNone(result['cmd'])
  54. if __name__ == '__main__':
  55. unittest.main()