1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
from __future__ import annotations
import cmd2
from .conftest import normalize, run_cmd
def test_hooks_work_with_future_annotations() -> None:
class HookApp(cmd2.Cmd):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.register_cmdfinalization_hook(self.hook)
def hook(self: cmd2.Cmd, data: cmd2.plugin.CommandFinalizationData) -> cmd2.plugin.CommandFinalizationData:
if self.in_script():
self.poutput("WE ARE IN SCRIPT")
return data
hook_app = HookApp()
out, _err = run_cmd(hook_app, '')
expected = normalize('')
assert out == expected
|