diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-09-25 00:10:13 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-09-25 00:10:13 -0400 |
commit | 67aa13c732b331e700c8bd16c77fabfe6c90c75c (patch) | |
tree | b7bb35ca64b16ee79b8070ceb29dda7f0269d729 /tests | |
parent | 3c51b9f32d35c05847c302646575dab576430a01 (diff) | |
download | cmd2-git-67aa13c732b331e700c8bd16c77fabfe6c90c75c.tar.gz |
Deleted the hook methods which were deprecated in the previous release
The following methods of cmd2.Cmd have been deleted:
- preparse
- postparsing_precmd
- postparsing_postcmd
The new application lifecycle hook framework allows for registering callbacks to be called at various points in the application lifecycle and is more powerful and flexible than the old system of fixed hook methods.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd2.py | 7 | ||||
-rw-r--r-- | tests/test_plugin.py | 5 |
2 files changed, 8 insertions, 4 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 99c30af4..17c19f2a 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -993,10 +993,13 @@ def test_cmdloop_without_rawinput(): class HookFailureApp(cmd2.Cmd): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + # register a postparsing hook method + self.register_postparsing_hook(self.postparsing_precmd) - def postparsing_precmd(self, statement): + def postparsing_precmd(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData: """Simulate precmd hook failure.""" - return True, statement + data.stop = True + return data @pytest.fixture def hook_failure(): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 20f2f32c..81dd7683 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -51,10 +51,10 @@ class Plugin: # preparse hook # ### - def preparse(self, line: str) -> str: + def preparse(self, data: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData: """Preparsing hook""" self.called_preparse += 1 - return line + return data ### # @@ -322,6 +322,7 @@ def test_postloop_hooks(capsys): ### def test_preparse(capsys): app = PluggedApp() + app.register_postparsing_hook(app.preparse) app.onecmd_plus_hooks('say hello') out, err = capsys.readouterr() assert out == 'hello\n' |