Skip to content

Commit 076defc

Browse files
chore: clean up test
1 parent f140150 commit 076defc

1 file changed

Lines changed: 13 additions & 18 deletions

File tree

tests/test_annotated.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,27 +1369,22 @@ def test_subcommand_naming_enforced(self, subcommand_to, func_name) -> None:
13691369
with pytest.raises(TypeError, match="must be named"):
13701370
cmd2.with_annotated(subcommand_to=subcommand_to)(ns[func_name])
13711371

1372-
def test_subcommand_attributes_set(self) -> None:
1372+
@pytest.mark.parametrize(
1373+
("decorator_kwargs", "expected_help", "expected_aliases"),
1374+
[
1375+
pytest.param({"help": "create", "aliases": ["c"]}, "create", ("c",), id="with_help_and_aliases"),
1376+
pytest.param({}, None, (), id="without_help_or_aliases"),
1377+
],
1378+
)
1379+
def test_subcommand_spec_attributes(self, decorator_kwargs, expected_help, expected_aliases) -> None:
13731380
from cmd2 import constants
13741381

1375-
@cmd2.with_annotated(subcommand_to="team", help="create", aliases=["c"])
1376-
def team_create(self, name: str) -> None: ...
1382+
@cmd2.with_annotated(subcommand_to="team", **decorator_kwargs)
1383+
def team_create(self, name: str = "") -> None: ...
13771384

13781385
spec = getattr(team_create, constants.SUBCMD_ATTR_SPEC)
13791386
assert spec.command == "team"
13801387
assert spec.name == "create"
1381-
assert spec.help == "create"
1382-
assert spec.aliases == ("c",)
1383-
parser = spec.parser_source()
1384-
assert isinstance(parser, argparse.ArgumentParser)
1385-
1386-
def test_subcommand_without_help(self) -> None:
1387-
"""Subcommand with no help or aliases -- covers the None/empty branches."""
1388-
from cmd2 import constants
1389-
1390-
@cmd2.with_annotated(subcommand_to="team")
1391-
def team_delete(self) -> None: ...
1392-
1393-
spec = getattr(team_delete, constants.SUBCMD_ATTR_SPEC)
1394-
assert spec.help is None
1395-
assert spec.aliases == ()
1388+
assert spec.help == expected_help
1389+
assert spec.aliases == expected_aliases
1390+
assert isinstance(spec.parser_source(), argparse.ArgumentParser)

0 commit comments

Comments
 (0)