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