summaryrefslogtreecommitdiff
path: root/tests/test_plugin.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-06-21 15:04:16 -0600
committerkotfu <kotfu@kotfu.net>2018-06-21 15:04:16 -0600
commit7298501357504312e137180c99c05a40f49eb48a (patch)
tree46d0bb73c6addf20799ca386c154278f1c6b2429 /tests/test_plugin.py
parent37b2f68b7ec021d1bfca739b343460d4d97a49d1 (diff)
downloadcmd2-git-7298501357504312e137180c99c05a40f49eb48a.tar.gz
Revised postparsing hooks
Diffstat (limited to 'tests/test_plugin.py')
-rw-r--r--tests/test_plugin.py58
1 files changed, 52 insertions, 6 deletions
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index d4d6166e..39f35cb0 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -52,26 +52,47 @@ class Plugin:
# Postparsing hooks
#
###
- def postparse_hook(self, statement: cmd2.Statement) -> Tuple[bool, cmd2.Statement]:
+ def postparse_hook(self, params: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
"A postparsing hook"
self.called_postparsing += 1
- return False, statement
+ return params
- def postparse_hook_stop(self, statement: cmd2.Statement) -> Tuple[bool, cmd2.Statement]:
+ def postparse_hook_stop(self, params: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
"A postparsing hook with requests application exit"
self.called_postparsing += 1
- return True, statement
+ params.stop = True
+ return params
- def postparse_hook_emptystatement(self, statement: cmd2.Statement) -> Tuple[bool, cmd2.Statement]:
+ def postparse_hook_emptystatement(self, params: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
"A postparsing hook with raises an EmptyStatement exception"
self.called_postparsing += 1
raise cmd2.EmptyStatement
- def postparse_hook_exception(self, statement: cmd2.Statement) -> Tuple[bool, cmd2.Statement]:
+ def postparse_hook_exception(self, params: cmd2.plugin.PostparsingData) -> cmd2.plugin.PostparsingData:
"A postparsing hook which raises an exception"
self.called_postparsing += 1
raise ValueError
+ def postparse_hook_too_many_parameters(self, param1, param2) -> cmd2.plugin.PostparsingData:
+ "A postparsing hook with too many parameters"
+ pass
+
+ def postparse_hook_undeclared_parameter_type(self, param) -> cmd2.plugin.PostparsingData:
+ "A postparsing hook with an undeclared parameter type"
+ pass
+
+ def postparse_hook_wrong_parameter_type(self, params: str) -> cmd2.plugin.PostparsingData:
+ "A postparsing hook with the wrong parameter type"
+ pass
+
+ def postparse_hook_undeclared_return_type(self, params: cmd2.plugin.PostparsingData):
+ "A postparsing hook with an undeclared return type"
+ pass
+
+ def postparse_hook_wrong_return_type(self, params: cmd2.plugin.PostparsingData) -> str:
+ "A postparsing hook with the wrong return type"
+ pass
+
###
#
# precommand hooks, some valid, some invalid
@@ -202,6 +223,31 @@ def test_postloop_hooks(capsys):
# test postparsing hooks
#
###
+def test_postparsing_hook_too_many_parameters():
+ app = PluggedApp()
+ with pytest.raises(TypeError):
+ app.register_postparsing_hook(app.postparse_hook_too_many_parameters)
+
+def test_postparsing_hook_undeclared_parameter_type():
+ app = PluggedApp()
+ with pytest.raises(TypeError):
+ app.register_postparsing_hook(app.postparse_hook_undeclared_parameter_type)
+
+def test_postparsing_hook_wrong_parameter_type():
+ app = PluggedApp()
+ with pytest.raises(TypeError):
+ app.register_postparsing_hook(app.postparse_hook_wrong_parameter_type)
+
+def test_postparsing_hook_undeclared_return_type():
+ app = PluggedApp()
+ with pytest.raises(TypeError):
+ app.register_postparsing_hook(app.postparse_hook_undeclared_return_type)
+
+def test_postparsing_hook_wrong_return_type():
+ app = PluggedApp()
+ with pytest.raises(TypeError):
+ app.register_postparsing_hook(app.postparse_hook_wrong_return_type)
+
def test_postparsing_hook(capsys):
app = PluggedApp()
app.onecmd_plus_hooks('say hello')