56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import curses
|
|
import unittest
|
|
from unittest.mock import Mock, patch
|
|
|
|
from herdr_hub.cli import build_parser, command_keys
|
|
from herdr_hub.key_help import KEY_SECTIONS, KeyHelpPopup
|
|
|
|
|
|
class KeyHelpTests(unittest.TestCase):
|
|
def test_reference_contains_primary_hub_mappings(self) -> None:
|
|
mappings = {
|
|
mapping.keys: mapping.action
|
|
for _, section in KEY_SECTIONS
|
|
for mapping in section
|
|
}
|
|
for keys in (
|
|
"Ctrl+A ?",
|
|
"Ctrl+A g",
|
|
"Ctrl+A h",
|
|
"Ctrl+A r",
|
|
"Ctrl+A R",
|
|
"Ctrl+A q",
|
|
"Ctrl+A d",
|
|
):
|
|
self.assertIn(keys, mappings)
|
|
|
|
def test_narrow_layout_stacks_keys_and_actions(self) -> None:
|
|
wide = [value for value, _ in KeyHelpPopup.lines(70)]
|
|
narrow = [value for value, _ in KeyHelpPopup.lines(36)]
|
|
self.assertGreater(len(narrow), len(wide))
|
|
self.assertIn(" Ctrl+A ?", narrow)
|
|
self.assertIn(" 打开快捷键帮助", narrow)
|
|
|
|
def test_escape_closes_popup(self) -> None:
|
|
screen = Mock()
|
|
screen.getmaxyx.return_value = (24, 80)
|
|
screen.get_wch.return_value = "\x1b"
|
|
with patch("curses.set_escdelay"), patch("curses.curs_set"), patch(
|
|
"curses.use_default_colors"
|
|
), patch("curses.mousemask"):
|
|
self.assertEqual(KeyHelpPopup().run(screen), 0)
|
|
|
|
def test_cli_entry_uses_curses_wrapper(self) -> None:
|
|
arguments = build_parser().parse_args(["keys"])
|
|
self.assertEqual(arguments.command, "keys")
|
|
with patch("herdr_hub.cli.curses.wrapper", return_value=0) as wrapper:
|
|
self.assertEqual(command_keys(argparse.Namespace()), 0)
|
|
wrapper.assert_called_once()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|