Debian Codegraph @

tests/unit/test_numlock_command.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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 / "src"
12 / "fenrirscreenreader"
13 / "commands"
14 / "onKeyInput"
15 / "80500-numlock.py"
16 )
17 spec = importlib.util.spec_from_file_location(
18 "numlock_command", command_path
19 )
20 module = importlib.util.module_from_spec(spec)
21 spec.loader.exec_module(module)
22 return module.command
23
24
25 @pytest.mark.unit
26 def test_numlock_off_can_be_announced_from_release_event():
27 output_manager = Mock()
28 command = load_numlock_command()()
29 command.initialize(
30 {
31 "input": {
32 "old_num_lock": True,
33 "new_num_lock": False,
34 "curr_input": [],
35 "prev_input": ["KEY_NUMLOCK"],
36 },
37 "runtime": {"OutputManager": output_manager},
38 }
39 )
40
41 command.run()
42
43 output_manager.present_text.assert_called_once()
44 assert output_manager.present_text.call_args.args[0] == "Numlock off"
45
46
47 @pytest.mark.unit
48 def test_numlock_command_ignores_non_numlock_release():
49 output_manager = Mock()
50 command = load_numlock_command()()
51 command.initialize(
52 {
53 "input": {
54 "old_num_lock": True,
55 "new_num_lock": False,
56 "curr_input": [],
57 "prev_input": ["KEY_KP1"],
58 },
59 "runtime": {"OutputManager": output_manager},
60 }
61 )
62
63 command.run()
64
65 output_manager.present_text.assert_not_called()