Browse Source

closes #480 - program_description not overriding parser description

1.0.4-release--issue-470
Chris 4 years ago
parent
commit
f22fdcd7af
2 changed files with 32 additions and 1 deletions
  1. 2
      gooey/python_bindings/config_generator.py
  2. 31
      gooey/tests/test_config_generator.py

2
gooey/python_bindings/config_generator.py

@ -103,7 +103,7 @@ def create_from_parser(parser, source_path, **kwargs):
'over Gooey\'s text formatting')
build_spec['program_description'] = parser.description or build_spec['program_description']
build_spec['program_description'] = build_spec['program_description'] or parser.description or ''
layout_data = (argparse_to_json.convert(parser, **build_spec)
if build_spec['show_advanced']

31
gooey/tests/test_config_generator.py

@ -0,0 +1,31 @@
import unittest
from argparse import ArgumentParser
from python_bindings.config_generator import create_from_parser
class TextConfigGenerator(unittest.TestCase):
def test_program_description(self):
"""
Should use `program_description` if supplied, otherwise
fallback to the description on the `parser`
"""
parser = ArgumentParser(description="Parser Description")
# when supplied explicitly, we assign it as the description
buildspec = create_from_parser(parser, "", program_description='Custom Description')
self.assertEqual(buildspec['program_description'], 'Custom Description')
# when no explicit program_definition supplied, we fallback to the parser's description
buildspec = create_from_parser(parser, "")
self.assertEqual(buildspec['program_description'], 'Parser Description')
# if no description is provided anywhere, we just set it to be an empty string.
blank_parser = ArgumentParser()
buildspec = create_from_parser(blank_parser, "")
self.assertEqual(buildspec['program_description'], '')
if __name__ == '__main__':
unittest.main()
Loading…
Cancel
Save