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

Function test_commandset_sigint

tests/test_commandset.py:639–670  ·  view source on GitHub ↗
(manual_command_sets_app)

Source from the content-addressed store, hash-verified

637
638
639def test_commandset_sigint(manual_command_sets_app) -> None:
640 # shows that the command is able to continue execution if the sigint_handler
641 # returns True that we've handled interrupting the command.
642 class SigintHandledCommandSet(cmd2.CommandSet):
643 def do_foo(self, _) -> None:
644 """Foo Command"""
645 self._cmd.poutput("in foo")
646 self._cmd.sigint_handler(signal.SIGINT, None)
647 self._cmd.poutput("end of foo")
648
649 def sigint_handler(self) -> bool:
650 return True
651
652 cs1 = SigintHandledCommandSet()
653 manual_command_sets_app.register_command_set(cs1)
654 out = manual_command_sets_app.app_cmd("foo")
655 assert "in foo" in out.stdout
656 assert "end of foo" in out.stdout
657
658 # shows that the command is interrupted if we don't report we've handled the sigint
659 class SigintUnhandledCommandSet(cmd2.CommandSet):
660 def do_bar(self, _) -> None:
661 """Bar Command"""
662 self._cmd.poutput("in do bar")
663 self._cmd.sigint_handler(signal.SIGINT, None)
664 self._cmd.poutput("end of do bar")
665
666 cs2 = SigintUnhandledCommandSet()
667 manual_command_sets_app.register_command_set(cs2)
668 out = manual_command_sets_app.app_cmd("bar")
669 assert "in do bar" in out.stdout
670 assert "end of do bar" not in out.stdout
671
672
673def test_nested_subcommands(manual_command_sets_app) -> None:

Callers

nothing calls this directly

Calls 4

register_command_setMethod · 0.80
app_cmdMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…