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.

59 lines
2.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import unittest
  2. from argparse import ArgumentParser
  3. from python_bindings import constants
  4. from python_bindings.config_generator import create_from_parser
  5. from gooey.tests import *
  6. from gooey.python_bindings.parameters import gooey_params
  7. class TextConfigGenerator(unittest.TestCase):
  8. def test_program_description(self):
  9. """
  10. Should use `program_description` if supplied, otherwise
  11. fallback to the description on the `parser`
  12. """
  13. parser = ArgumentParser(description="Parser Description")
  14. # when supplied explicitly, we assign it as the description
  15. params = gooey_params(program_description='Custom Description')
  16. buildspec = create_from_parser(parser, "", **params)
  17. self.assertEqual(buildspec['program_description'], 'Custom Description')
  18. # when no explicit program_definition supplied, we fallback to the parser's description
  19. buildspec = create_from_parser(parser, "", **gooey_params())
  20. self.assertEqual(buildspec['program_description'], 'Parser Description')
  21. # if no description is provided anywhere, we just set it to be an empty string.
  22. blank_parser = ArgumentParser()
  23. buildspec = create_from_parser(blank_parser, "", **gooey_params())
  24. self.assertEqual(buildspec['program_description'], '')
  25. def test_valid_font_weights(self):
  26. """
  27. Asserting that only valid font-weights are allowable.
  28. """
  29. all_valid_weights = range(100, 1001, 100)
  30. for weight in all_valid_weights:
  31. parser = ArgumentParser(description="test parser")
  32. params = gooey_params(terminal_font_weight=weight)
  33. buildspec = create_from_parser(parser, "", **params)
  34. self.assertEqual(buildspec['terminal_font_weight'], weight)
  35. def test_font_weight_defaults_to_normal(self):
  36. parser = ArgumentParser(description="test parser")
  37. # no font_weight explicitly provided
  38. buildspec = create_from_parser(parser, "", **gooey_params())
  39. self.assertEqual(buildspec['terminal_font_weight'], constants.FONTWEIGHT_NORMAL)
  40. def test_invalid_font_weights_throw_error(self):
  41. parser = ArgumentParser(description="test parser")
  42. with self.assertRaises(ValueError):
  43. invalid_weight = 9123
  44. params = gooey_params(terminal_font_weight=invalid_weight)
  45. buildspec = create_from_parser(parser, "", **params)
  46. if __name__ == '__main__':
  47. unittest.main()