Skip to content

Commit 82100df

Browse files
committed
Updated tests.
1 parent 31af376 commit 82100df

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

tests/test_argparse_custom.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,23 @@ def test_subcommand_attachment() -> None:
411411
assert "child" not in root_subparsers._name_parser_map
412412
assert "child_alias" not in root_subparsers._name_parser_map
413413

414-
###############################
415-
# Test error handling
416-
###############################
417414

418-
# Verify ValueError when path is invalid (find_parser fails)
415+
def test_subcommand_attachment_errors() -> None:
416+
root_parser = Cmd2ArgumentParser(prog="root", description="root command")
417+
child_parser = Cmd2ArgumentParser(prog="child", description="child command")
418+
419+
# Verify ValueError when subcommands are not supported
420+
with pytest.raises(ValueError, match="Command 'root' does not support subcommands"):
421+
root_parser.attach_subcommand([], "anything", child_parser)
422+
with pytest.raises(ValueError, match="Command 'root' does not support subcommands"):
423+
root_parser.detach_subcommand([], "anything")
424+
425+
# Allow subcommands for the next tests
426+
root_parser.add_subparsers()
427+
428+
# Verify ValueError when path is invalid (_find_parser() fails)
429+
with pytest.raises(ValueError, match="Subcommand 'nonexistent' not found"):
430+
root_parser.attach_subcommand(["nonexistent"], "anything", child_parser)
419431
with pytest.raises(ValueError, match="Subcommand 'nonexistent' not found"):
420432
root_parser.detach_subcommand(["nonexistent"], "anything")
421433

tests/test_cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4421,7 +4421,7 @@ def test_auto_suggest_default():
44214421
assert isinstance(app.main_session.auto_suggest, AutoSuggestFromHistory)
44224422

44234423

4424-
def test_attach_subcommand() -> None:
4424+
def test_subcommand_attachment() -> None:
44254425
import argparse
44264426

44274427
class SubcmdApp(cmd2.Cmd):
@@ -4470,7 +4470,7 @@ def do_root(self, _args: argparse.Namespace) -> None:
44704470
assert "child" not in root_subparsers_action._name_parser_map
44714471

44724472

4473-
def test_attach_subcommand_errors() -> None:
4473+
def test_subcommand_attachment_errors() -> None:
44744474
class SubcmdErrorApp(cmd2.Cmd):
44754475
def __init__(self) -> None:
44764476
super().__init__()

0 commit comments

Comments
 (0)