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.

44 lines
1.6 KiB

  1. import argparse
  2. import unittest
  3. from gooey.gui import formatters
  4. class TestFormatters(unittest.TestCase):
  5. def test_counter_formatter(self):
  6. """
  7. Should return the first option repeated N times
  8. None if N is unspecified
  9. Issue #316 - using long-form argument caused formatter to produce incorrect output
  10. """
  11. expected_outputs = [
  12. (['-v', '--verbose'], '-v', 1),
  13. (['-v', '--verbose'], '-v -v', 2),
  14. (['-v', '--verbose'], '-v -v -v', 3),
  15. (['-v', '--verbose'], '', 0),
  16. # ensuring that log-forms are handled correctly
  17. (['--verbose', '-v'], '--verbose', 1),
  18. (['--verbose', '-v'], '--verbose --verbose', 2),
  19. (['--verbose', '-v'], '--verbose --verbose --verbose', 3),
  20. # single args
  21. (['-v'], '-v', 1),
  22. (['-v'], '-v -v', 2),
  23. (['--verbose'], '--verbose', 1),
  24. # bad inputs
  25. (['-v'], None, None),
  26. (['-v'], None, 'some-garbage'),
  27. (['-v'], None, 'af3gd'),
  28. ]
  29. for commands, expected, vebosity_level in expected_outputs:
  30. result = formatters.counter({'commands': commands}, vebosity_level)
  31. self.assertEqual(result, expected)
  32. # make sure that argparse actually accepts it as valid.
  33. if result:
  34. parser = argparse.ArgumentParser()
  35. parser.add_argument('-v', '--verbose', action='count')
  36. parser.parse_args(result.split())