MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / test_custom_construct_commandsets

Function test_custom_construct_commandsets

tests/test_commandset.py:198–237  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

196
197
198def test_custom_construct_commandsets() -> None:
199 command_set_b = CommandSetB("foo")
200
201 # Verify that _cmd cannot be accessed until CommandSet is registered.
202 with pytest.raises(CommandSetRegistrationError) as excinfo:
203 command_set_b._cmd.poutput("test")
204 assert "is not registered" in str(excinfo.value)
205
206 # Verifies that a custom initialized CommandSet loads correctly when passed into the constructor
207 app = WithCommandSets(command_sets=[command_set_b])
208
209 cmds_cats, _help_topics = app._build_command_info()
210 assert "Command Set B" in cmds_cats
211
212 # Verifies that the same CommandSet cannot be loaded twice
213 command_set_2 = CommandSetB("bar")
214 with pytest.raises(CommandSetRegistrationError):
215 assert app.register_command_set(command_set_2)
216
217 # Verify that autoload doesn't conflict with a manually loaded CommandSet that could be autoloaded.
218 command_set_a = CommandSetA()
219 app2 = WithCommandSets(command_sets=[command_set_a])
220
221 with pytest.raises(CommandSetRegistrationError):
222 app2.register_command_set(command_set_b)
223
224 app.unregister_command_set(command_set_b)
225
226 app2.register_command_set(command_set_b)
227
228 assert hasattr(app2, "do_apple")
229 assert hasattr(app2, "do_aardvark")
230
231 assert app2.find_commandset_for_command("aardvark") is command_set_b
232 assert app2.find_commandset_for_command("apple") is command_set_a
233
234 matches = app2.find_commandsets(CommandSetBase, subclass_match=True)
235 assert command_set_a in matches
236 assert command_set_b in matches
237 assert command_set_2 not in matches
238
239
240def test_load_commands(manual_command_sets_app, capsys) -> None:

Callers

nothing calls this directly

Calls 9

CommandSetBClass · 0.85
poutputMethod · 0.80
_build_command_infoMethod · 0.80
register_command_setMethod · 0.80
find_commandsetsMethod · 0.80
WithCommandSetsClass · 0.70
CommandSetAClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…