(manual_command_sets_app)
| 637 | |
| 638 | |
| 639 | def 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 | |
| 673 | def test_nested_subcommands(manual_command_sets_app) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…