summaryrefslogtreecommitdiff
path: root/tests/test_plugin.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-06-03 15:59:19 -0600
committerkotfu <kotfu@kotfu.net>2018-06-03 15:59:19 -0600
commit18b290ffa3d57f09b13a4b11c8af5e08bb00a92c (patch)
tree76d1f1a7745d1ae98f0b078795058a0e39f8f6d1 /tests/test_plugin.py
parent242742b94ea2c11db3929aa1de8b21deadb6fe5c (diff)
downloadcmd2-git-18b290ffa3d57f09b13a4b11c8af5e08bb00a92c.tar.gz
Preloop and postloop hooks now validate signature
Diffstat (limited to 'tests/test_plugin.py')
-rw-r--r--tests/test_plugin.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 26eb88bb..f3db853b 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -33,6 +33,14 @@ class Plugin:
"Another method used for preloop or postloop hooks"
self.poutput("two")
+ def prepost_hook_too_many_parameters(self, param):
+ "A preloop or postloop hook with too many parameters"
+ pass
+
+ def prepost_hook_with_return_type(self) -> bool:
+ "A preloop or postloop hook with a declared return type"
+ pass
+
def postparse_hook(self, statement: cmd2.Statement) -> Tuple[bool, cmd2.Statement]:
"A postparsing hook"
self.called_postparsing += 1
@@ -116,6 +124,16 @@ class PluggedApp(Plugin, cmd2.Cmd):
# test pre and postloop hooks
#
###
+def test_register_preloop_hook_too_many_parameters():
+ app = PluggedApp()
+ with pytest.raises(TypeError):
+ app.register_preloop_hook(app.prepost_hook_too_many_parameters)
+
+def test_register_preloop_hook_with_return_type():
+ app = PluggedApp()
+ with pytest.raises(TypeError):
+ app.register_preloop_hook(app.prepost_hook_with_return_type)
+
def test_preloop_hook(capsys):
app = PluggedApp()
app.register_preloop_hook(app.prepost_hook_one)
@@ -137,6 +155,16 @@ def test_preloop_hooks(capsys):
assert out == 'one\ntwo\nhello\n'
assert not err
+def test_register_postloop_hook_too_many_parameters():
+ app = PluggedApp()
+ with pytest.raises(TypeError):
+ app.register_postloop_hook(app.prepost_hook_too_many_parameters)
+
+def test_register_postloop_hook_with_return_type():
+ app = PluggedApp()
+ with pytest.raises(TypeError):
+ app.register_postloop_hook(app.prepost_hook_with_return_type)
+
def test_postloop_hook(capsys):
app = PluggedApp()
app.register_postloop_hook(app.prepost_hook_one)