@@ -3470,6 +3470,37 @@ def test_subcommand_title_and_description(self) -> None:
34703470 assert group is not None
34713471 assert group .description == "pick one"
34723472
3473+ def test_subparsers_default_to_positionals_group (self ) -> None :
3474+ """Without a title/description the subparsers belong to argparse's own positionals group."""
3475+ parser = self ._base_parser ()
3476+ action = self ._subparsers_action (parser )
3477+ assert action in parser ._positionals ._group_actions
3478+ # No untitled group is created to hold them.
3479+ assert [g for g in parser ._action_groups if g .title is None ] == []
3480+
3481+ def test_subparsers_listed_under_positional_arguments_in_help (self ) -> None :
3482+ """The subcommands are documented in --help like argparse and Cmd2ArgumentParser do."""
3483+ parser = self ._base_parser ()
3484+ help_text = parser .format_help ()
3485+ _ , header , rest = help_text .partition ("Positional Arguments:" )
3486+ assert header , f"no positional arguments section in:\n { help_text } "
3487+ assert "SUBCOMMAND" in rest .partition ("Options:" )[0 ]
3488+
3489+ @pytest .mark .parametrize (
3490+ ("kwargs" , "expected_title" ),
3491+ [
3492+ pytest .param ({"subcommand_title" : "Commands" }, "Commands" , id = "title-only" ),
3493+ pytest .param ({"subcommand_description" : "pick one" }, "subcommands" , id = "description-only" ),
3494+ ],
3495+ )
3496+ def test_subparsers_move_out_of_positionals_when_titled (self , kwargs , expected_title ) -> None :
3497+ """Supplying either knob still opts into a dedicated group, argparse's documented behavior."""
3498+ parser = self ._base_parser (** kwargs )
3499+ action = self ._subparsers_action (parser )
3500+ assert action not in parser ._positionals ._group_actions
3501+ group = next (g for g in parser ._action_groups if action in g ._group_actions )
3502+ assert group .title == expected_title
3503+
34733504
34743505# ---------------------------------------------------------------------------
34753506# Rich objects are accepted for description / epilog (HelpContent)
0 commit comments