2323import pytest
2424
2525import cmd2
26- from cmd2 import (
27- CompletionItem ,
28- )
26+ from cmd2 import CompletionItem
2927from cmd2 .annotated import (
3028 Argument ,
3129 Group ,
@@ -1121,7 +1119,7 @@ class MyCompleter(ArgparseCompleter):
11211119 @with_annotated (ap_completer_type = MyCompleter )
11221120 def do_run (self , name : str ) -> None : ...
11231121
1124- builder = getattr (do_run , constants .CMD_ATTR_PARSER_SOURCE )
1122+ builder = getattr (do_run , constants .AP_COMMAND_ATTR_SPEC ). parser_source
11251123 assert builder ().ap_completer_type is MyCompleter
11261124
11271125 def test_ap_completer_type_threads_to_subcommand (self ) -> None :
@@ -1134,7 +1132,7 @@ class MyCompleter(ArgparseCompleter):
11341132 @with_annotated (subcommand_to = "team" , ap_completer_type = MyCompleter )
11351133 def team_create (self , name : str ) -> None : ...
11361134
1137- spec = getattr (team_create , constants .SUBCMD_ATTR_SPEC )
1135+ spec = getattr (team_create , constants .SUBCOMMAND_ATTR_SPEC )
11381136 assert spec .parser_source ().ap_completer_type is MyCompleter
11391137
11401138 def test_customization_via_decorator (self ) -> None :
@@ -1178,7 +1176,7 @@ def team_add(self, name: str) -> None:
11781176
11791177 from cmd2 import constants
11801178
1181- spec = getattr (App .team_add , constants .SUBCMD_ATTR_SPEC )
1179+ spec = getattr (App .team_add , constants .SUBCOMMAND_ATTR_SPEC )
11821180 subparser = spec .parser_source ()
11831181 assert subparser .description == "add desc"
11841182 assert subparser .epilog == "add epilog"
@@ -1678,12 +1676,12 @@ def test_int_subclass_uses_int_converter(self) -> None:
16781676
16791677class TestFilteredNamespaceKwargs :
16801678 def test_excludes_subcmd_handler_key (self ) -> None :
1679+ from cmd2 import constants
16811680 from cmd2 .annotated import _filtered_namespace_kwargs
1682- from cmd2 .constants import NS_ATTR_SUBCMD_HANDLER
16831681
1684- ns = argparse .Namespace (** {NS_ATTR_SUBCMD_HANDLER : lambda : None , "name" : "Alice" })
1682+ ns = argparse .Namespace (** {constants . NS_ATTR_SUBCOMMAND_FUNC : lambda : None , "name" : "Alice" })
16851683 result = _filtered_namespace_kwargs (ns )
1686- assert NS_ATTR_SUBCMD_HANDLER not in result
1684+ assert constants . NS_ATTR_SUBCOMMAND_FUNC not in result
16871685 assert result == {"name" : "Alice" }
16881686
16891687 def test_excludes_subcommand_key (self ) -> None :
@@ -2376,7 +2374,7 @@ def test_subcommand_spec_attributes(self, decorator_kwargs, expected_help, expec
23762374 @with_annotated (subcommand_to = "team" , ** decorator_kwargs )
23772375 def team_create (self , name : str = "" ) -> None : ...
23782376
2379- spec = getattr (team_create , constants .SUBCMD_ATTR_SPEC )
2377+ spec = getattr (team_create , constants .SUBCOMMAND_ATTR_SPEC )
23802378 assert spec .command == "team"
23812379 assert spec .name == "create"
23822380 assert spec .help == expected_help
@@ -2390,7 +2388,7 @@ def test_subcommand_deprecated_flows_to_spec(self, deprecated) -> None:
23902388 @with_annotated (subcommand_to = "team" , deprecated = deprecated )
23912389 def team_create (self , name : str = "" ) -> None : ...
23922390
2393- spec = getattr (team_create , constants .SUBCMD_ATTR_SPEC )
2391+ spec = getattr (team_create , constants .SUBCOMMAND_ATTR_SPEC )
23942392 assert spec .deprecated is deprecated
23952393
23962394
@@ -3026,7 +3024,7 @@ def _base_parser(**subcommand_kwargs):
30263024 @with_annotated (base_command = True , ** subcommand_kwargs )
30273025 def do_root (self , cmd2_handler ) -> None : ...
30283026
3029- builder = getattr (do_root , constants .CMD_ATTR_PARSER_SOURCE )
3027+ builder = getattr (do_root , constants .AP_COMMAND_ATTR_SPEC ). parser_source
30303028 return builder ()
30313029
30323030 @staticmethod
@@ -3139,7 +3137,7 @@ def do_run(self, name: str) -> None:
31393137 Extra detail.
31403138 """
31413139
3142- builder = getattr (do_run , constants .CMD_ATTR_PARSER_SOURCE )
3140+ builder = getattr (do_run , constants .AP_COMMAND_ATTR_SPEC ). parser_source
31433141 assert builder ().description == "Run the thing."
31443142
31453143 def test_subcommand_uses_docstring (self ) -> None :
@@ -3149,7 +3147,7 @@ def test_subcommand_uses_docstring(self) -> None:
31493147 def team_add (self , name : str ) -> None :
31503148 """Add a member to the team."""
31513149
3152- spec = getattr (team_add , constants .SUBCMD_ATTR_SPEC )
3150+ spec = getattr (team_add , constants .SUBCOMMAND_ATTR_SPEC )
31533151 assert spec .parser_source ().description == "Add a member to the team."
31543152
31553153
@@ -3240,7 +3238,7 @@ def test_decorator_passes_parser_kwargs(self) -> None:
32403238 @with_annotated (prog = "myprog" , usage = "usage line" )
32413239 def do_run (self , name : str ) -> None : ...
32423240
3243- builder = getattr (do_run , constants .CMD_ATTR_PARSER_SOURCE )
3241+ builder = getattr (do_run , constants .AP_COMMAND_ATTR_SPEC ). parser_source
32443242 parser = builder ()
32453243 assert parser .prog == "myprog"
32463244 assert parser .usage == "usage line"
@@ -3259,7 +3257,7 @@ def test_usage_allowed_on_subcommand(self) -> None:
32593257 @with_annotated (subcommand_to = "team" , usage = "team add NAME" )
32603258 def team_add (self , name : str ) -> None : ...
32613259
3262- spec = getattr (team_add , constants .SUBCMD_ATTR_SPEC )
3260+ spec = getattr (team_add , constants .SUBCOMMAND_ATTR_SPEC )
32633261 assert spec .parser_source ().usage == "team add NAME"
32643262
32653263 def test_parents_allowed_on_subcommand (self ) -> None :
@@ -3271,7 +3269,7 @@ def test_parents_allowed_on_subcommand(self) -> None:
32713269 @with_annotated (subcommand_to = "team" , parents = [parent ])
32723270 def team_add (self , name : str ) -> None : ...
32733271
3274- spec = getattr (team_add , constants .SUBCMD_ATTR_SPEC )
3272+ spec = getattr (team_add , constants .SUBCOMMAND_ATTR_SPEC )
32753273 dests = {a .dest for a in spec .parser_source ()._actions }
32763274 assert "shared" in dests
32773275
@@ -3354,7 +3352,7 @@ def test_decorator_threads_all_low_level_kwargs(self) -> None:
33543352 )
33553353 def do_run (self , name : str ) -> None : ...
33563354
3357- builder = getattr (do_run , constants .CMD_ATTR_PARSER_SOURCE )
3355+ builder = getattr (do_run , constants .AP_COMMAND_ATTR_SPEC ). parser_source
33583356 parser = builder ()
33593357 assert parser .prefix_chars == "+-"
33603358 assert parser .fromfile_prefix_chars == "@"
0 commit comments