MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / test_ns_provider

Function test_ns_provider

tests/test_commandset.py:1224–1239  ·  view source on GitHub ↗

This exercises code in with_argparser() decorator that calls namespace providers

()

Source from the content-addressed store, hash-verified

1222
1223
1224def test_ns_provider() -> None:
1225 """This exercises code in with_argparser() decorator that calls namespace providers"""
1226 ns_provider_set = NsProviderSet(1)
1227 app = NsProviderApp(auto_load_commands=False)
1228
1229 # First test the case in which a namespace provider function resides in a CommandSet class which is registered.
1230 # with_argparser() will pass the CommandSet instance to the ns_provider() function.
1231 app.register_command_set(ns_provider_set)
1232 run_cmd(app, "test_ns")
1233 assert app.last_result == ns_provider_set
1234
1235 # Now test the case in which a namespace provider function resides in a CommandSet class which is not registered.
1236 # with_argparser() will receive None from cmd2.Cmd._resolve_func_self() and therefore pass app as self to ns_provider().
1237 app.unregister_command_set(ns_provider_set)
1238 run_cmd(app, "test_ns")
1239 assert app.last_result == app

Callers

nothing calls this directly

Calls 5

NsProviderSetClass · 0.85
NsProviderAppClass · 0.85
run_cmdFunction · 0.85
register_command_setMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…