Skip to content

Commit 2c91df0

Browse files
committed
Added a new test file to cover the case representing the whole reason for this change
I first verified that this test fails on the current master branch
1 parent e8653da commit 2c91df0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_future_annotations.py

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

0 commit comments

Comments
 (0)