Debian Codegraph @

tests/unit/test_numlock_command.py

raw ◀ ▶
1 Debian patch touch this file
1 import importlib.util
2 from pathlib import Path
3 from unittest.mock import Mock
4
5 import pytest
6
7
8 def load_numlock_command():
9 command_path = (
10 Path(__file__).parents[2]
11 / "fenrirscreenreader"
12 / "commands"
13 / "onKeyInput"
14 / "80500-numlock.py"
15 )
16 spec = importlib.util.spec_from_file_location(
17 "numlock_command", command_path
18 )
19 module = importlib.util.module_from_spec(spec)
20 spec.loader.exec_module(module)
21 return module.command
22
23
24 @pytest.mark.unit
25 def test_numlock_off_can_be_announced_from_release_event():
26 output_manager = Mock()
27 command = load_numlock_command()()
28 command.initialize(
29 {
30 "input": {
31 "old_num_lock": True,
32 "new_num_lock": False,
33 "curr_input": [],
34 "prev_input": ["KEY_NUMLOCK"],
35 },
36 "runtime": {"OutputManager": output_manager},
37 }
38 )
39
40 command.run()
41
42 output_manager.present_text.assert_called_once()
43 assert output_manager.present_text.call_args.args[0] == "Numlock off"
44
45
46 @pytest.mark.unit
47 def test_numlock_command_ignores_non_numlock_release():
48 output_manager = Mock()
49 command = load_numlock_command()()
50 command.initialize(
51 {
52 "input": {
53 "old_num_lock": True,
54 "new_num_lock": False,
55 "curr_input": [],
56 "prev_input": ["KEY_KP1"],
57 },
58 "runtime": {"OutputManager": output_manager},
59 }
60 )
61
62 command.run()
63
64 output_manager.present_text.assert_not_called()