Skip to content

Commit

Permalink
Add test to check that subgroups are saved (#139)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice Normandin <fabrice.normandin@gmail.com>
  • Loading branch information
lebrice committed Dec 20, 2022
1 parent 561035f commit b34c9c9
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions test/test_subgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."""

Expand Down

0 comments on commit b34c9c9

Please sign in to comment.