From d437955b65ae25e7235a8b621a1f0ad69ba0112c Mon Sep 17 00:00:00 2001 From: Andy Lee Date: Sun, 10 Mar 2019 10:07:06 -0400 Subject: [PATCH] Adding tests for mutex groups --- gooey/python_bindings/argparse_to_json.py | 2 +- gooey/tests/test_argparse_to_json.py | 26 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gooey/python_bindings/argparse_to_json.py b/gooey/python_bindings/argparse_to_json.py index 9a4af6b..f20b0ac 100644 --- a/gooey/python_bindings/argparse_to_json.py +++ b/gooey/python_bindings/argparse_to_json.py @@ -228,7 +228,7 @@ def reapply_mutex_groups(mutex_groups, action_groups): # insert the _ArgumentGroup container actions[targetindex] = mutexgroup # remove the duplicated individual actions - return [action for action in actions + actions = [action for action in actions if action not in mutex_actions] return actions diff --git a/gooey/tests/test_argparse_to_json.py b/gooey/tests/test_argparse_to_json.py index 8d18680..e64dac6 100644 --- a/gooey/tests/test_argparse_to_json.py +++ b/gooey/tests/test_argparse_to_json.py @@ -9,6 +9,32 @@ from gooey.util.functional import getin class TestArgparse(unittest.TestCase): + def test_mutex_groups_conversion(self): + """ + Ensure multiple mutex groups are processed correctly. + """ + parser = ArgumentParser() + g1 = parser.add_mutually_exclusive_group(required=True) + g1.add_argument('--choose1') + g1.add_argument('--choose2') + + g2 = parser.add_mutually_exclusive_group(required=True) + g2.add_argument('--choose3') + g2.add_argument('--choose4') + + output = argparse_to_json.process(parser, {}, {}, {}) + + # assert that we get two groups of two choices back + items = output[0]['items'] + self.assertTrue(len(items) == 2) + group1 = items[0] + group2 = items[1] + self.assertTrue(['--choose1'] in group1['data']['commands']) + self.assertTrue(['--choose2'] in group1['data']['commands']) + self.assertTrue(['--choose3'] in group2['data']['commands']) + self.assertTrue(['--choose4'] in group2['data']['commands']) + self.assertTrue(group1['type'] == 'RadioGroup') + self.assertTrue(group2['type'] == 'RadioGroup') def test_json_iterable_conversion(self): """