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.

54 lines
2.2 KiB

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