(manual_command_sets_app, capsys)
| 334 | |
| 335 | |
| 336 | def test_load_commandset_errors(manual_command_sets_app, capsys) -> None: |
| 337 | cmd_set = CommandSetA() |
| 338 | |
| 339 | # create a conflicting command before installing CommandSet to verify rollback behavior |
| 340 | manual_command_sets_app._install_command_function("do_durian", cmd_set.do_durian) |
| 341 | with pytest.raises(CommandSetRegistrationError): |
| 342 | manual_command_sets_app.register_command_set(cmd_set) |
| 343 | |
| 344 | # verify that the commands weren't installed |
| 345 | cmds_cats, _help_topics = manual_command_sets_app._build_command_info() |
| 346 | |
| 347 | assert "Alone" not in cmds_cats |
| 348 | assert "Fruits" not in cmds_cats |
| 349 | assert not manual_command_sets_app._installed_command_sets |
| 350 | |
| 351 | delattr(manual_command_sets_app, "do_durian") |
| 352 | |
| 353 | # pre-create intentionally conflicting macro and alias names |
| 354 | manual_command_sets_app.app_cmd("macro create apple run_pyscript") |
| 355 | manual_command_sets_app.app_cmd("alias create banana run_pyscript") |
| 356 | |
| 357 | # now install a command set and verify the commands are now present |
| 358 | manual_command_sets_app.register_command_set(cmd_set) |
| 359 | _out, err = capsys.readouterr() |
| 360 | |
| 361 | # verify aliases and macros are deleted with warning if they conflict with a command |
| 362 | assert "Deleting alias 'banana'" in err |
| 363 | assert "Deleting macro 'apple'" in err |
| 364 | |
| 365 | # verify command functions which don't start with "do_" raise an exception |
| 366 | with pytest.raises(CommandSetRegistrationError): |
| 367 | manual_command_sets_app._install_command_function("new_cmd", cmd_set.do_banana) |
| 368 | |
| 369 | # verify methods which don't start with "do_" raise an exception |
| 370 | with pytest.raises(CommandSetRegistrationError): |
| 371 | manual_command_sets_app._install_command_function("do_new_cmd", cmd_set.on_register) |
| 372 | |
| 373 | # verify duplicate commands are detected |
| 374 | with pytest.raises(CommandSetRegistrationError): |
| 375 | manual_command_sets_app._install_command_function("do_banana", cmd_set.do_banana) |
| 376 | |
| 377 | # verify bad command names are detected |
| 378 | with pytest.raises(CommandSetRegistrationError): |
| 379 | manual_command_sets_app._install_command_function("do_bad command", cmd_set.do_banana) |
| 380 | |
| 381 | # verify error conflict with existing completer function |
| 382 | with pytest.raises(CommandSetRegistrationError): |
| 383 | manual_command_sets_app._install_completer_function("durian", cmd_set.complete_durian) |
| 384 | |
| 385 | # verify error conflict with existing help function |
| 386 | with pytest.raises(CommandSetRegistrationError): |
| 387 | manual_command_sets_app._install_help_function("cranberry", cmd_set.help_cranberry) |
| 388 | |
| 389 | |
| 390 | class LoadableBase(cmd2.CommandSet): |
nothing calls this directly
no test coverage detected
searching dependent graphs…