diff --git a/gooey/python_bindings/argparse_to_json.py b/gooey/python_bindings/argparse_to_json.py index 10d381b..79d93db 100644 --- a/gooey/python_bindings/argparse_to_json.py +++ b/gooey/python_bindings/argparse_to_json.py @@ -403,6 +403,8 @@ def action_to_json(action, widget, options): }) default = coerce_default(action.default, widget) + if default == argparse.SUPPRESS: + default = None return { 'id': action.option_strings[0] if action.option_strings else action.dest, diff --git a/gooey/tests/harness.py b/gooey/tests/harness.py index 935f0bf..1237936 100644 --- a/gooey/tests/harness.py +++ b/gooey/tests/harness.py @@ -20,4 +20,5 @@ def instrumentGooey(parser, **kwargs): yield (app, gooey) finally: wx.CallAfter(app.ExitMainLoop) - app.Destroy() \ No newline at end of file + gooey.Destroy() + app.Destroy() diff --git a/gooey/tests/test_argparse_to_json.py b/gooey/tests/test_argparse_to_json.py index e64dac6..25fe77c 100644 --- a/gooey/tests/test_argparse_to_json.py +++ b/gooey/tests/test_argparse_to_json.py @@ -1,3 +1,4 @@ +import argparse import sys import unittest from argparse import ArgumentParser @@ -138,3 +139,17 @@ class TestArgparse(unittest.TestCase): self.assertEqual(result, None) + def test_suppress_is_removed_as_default_value(self): + """ + Issue #469 + Argparse uses the literal string ==SUPPRESS== as an internal flag. + When encountered in Gooey, these should be dropped and mapped to `None`. + """ + parser = ArgumentParser(prog='test_program') + parser.add_argument("--foo", default=argparse.SUPPRESS) + parser.add_argument('--version', action='version', version='1.0') + + result = argparse_to_json.convert(parser, num_required_cols=2, num_optional_cols=2) + groups = getin(result, ['widgets', 'test_program', 'contents']) + for item in groups[0]['items']: + self.assertEqual(getin(item, ['data', 'default']), None) \ No newline at end of file