From b34c9c93850b2788c4cbe7f4f6e782811b5d2a6d Mon Sep 17 00:00:00 2001 From: Fabrice Normandin Date: Mon, 19 Dec 2022 21:29:15 -0500 Subject: [PATCH] Add test to check that subgroups are saved (#139) Signed-off-by: Fabrice Normandin --- test/test_subgroups.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/test/test_subgroups.py b/test/test_subgroups.py index fcb41781..3f8edfbc 100644 --- a/test/test_subgroups.py +++ b/test/test_subgroups.py @@ -179,6 +179,19 @@ def test_parse(dataclass_type: type[TestClass], args: str, expected: TestClass): assert dataclass_type.setup(args) == expected +def test_subgroup_choice_is_saved_on_namespace(): + """test for https://github.com/lebrice/SimpleParsing/issues/139 + + Need to save the chosen subgroup name somewhere on the args. + """ + parser = ArgumentParser() + parser.add_arguments(AB, dest="config") + + args = parser.parse_args(shlex.split("--a_or_b b --b foobar")) + assert args.config == AB(a_or_b=B(b="foobar")) + assert args.subgroups == {"config.a_or_b": "b"} + + def test_remove_help_action(): # Test that it's possible to remove the '--help' action from a parser that had add_help=True @@ -317,20 +330,6 @@ class RequiredSubgroup(TestSetup): # assert args.foo == AB(a=123) -# def test_issue_139(): -# """test for https://github.com/lebrice/SimpleParsing/issues/139 - -# Need to save the chosen subgroup name somewhere on the args. -# """ - -# parser = ArgumentParser() -# parser.add_arguments(NestedSubgroups, dest="config") - -# args = parser.parse_args([]) -# assert args.config == NestedSubgroups(person=Daniel()) -# assert args.subgroups == {"config.person": "daniel"} - - # def test_deeper_nesting_prefixing(): # """Test that the prefixing mechanism works for deeper nesting of subgroups."""