@@ -3439,6 +3439,37 @@ def test_subcommand_title_and_description(self) -> None:
34393439 assert group is not None
34403440 assert group .description == "pick one"
34413441
3442+ def test_subparsers_default_to_positionals_group (self ) -> None :
3443+ """Without a title/description the subparsers belong to argparse's own positionals group."""
3444+ parser = self ._base_parser ()
3445+ action = self ._subparsers_action (parser )
3446+ assert action in parser ._positionals ._group_actions
3447+ # No untitled group is created to hold them.
3448+ assert [g for g in parser ._action_groups if g .title is None ] == []
3449+
3450+ def test_subparsers_listed_under_positional_arguments_in_help (self ) -> None :
3451+ """The subcommands are documented in --help like argparse and Cmd2ArgumentParser do."""
3452+ parser = self ._base_parser ()
3453+ help_text = parser .format_help ()
3454+ _ , header , rest = help_text .partition ("Positional Arguments:" )
3455+ assert header , f"no positional arguments section in:\n { help_text } "
3456+ assert "SUBCOMMAND" in rest .partition ("Options:" )[0 ]
3457+
3458+ @pytest .mark .parametrize (
3459+ ("kwargs" , "expected_title" ),
3460+ [
3461+ pytest .param ({"subcommand_title" : "Commands" }, "Commands" , id = "title-only" ),
3462+ pytest .param ({"subcommand_description" : "pick one" }, "subcommands" , id = "description-only" ),
3463+ ],
3464+ )
3465+ def test_subparsers_move_out_of_positionals_when_titled (self , kwargs , expected_title ) -> None :
3466+ """Supplying either knob still opts into a dedicated group, argparse's documented behavior."""
3467+ parser = self ._base_parser (** kwargs )
3468+ action = self ._subparsers_action (parser )
3469+ assert action not in parser ._positionals ._group_actions
3470+ group = next (g for g in parser ._action_groups if action in g ._group_actions )
3471+ assert group .title == expected_title
3472+
34423473
34433474# ---------------------------------------------------------------------------
34443475# Rich objects are accepted for description / epilog (HelpContent)
0 commit comments