Debian Codegraph @

tests/unit/test_review_screen_boundary_sounds.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 from fenrirscreenreader.utils import char_utils
8
9
10 COMMANDS_DIR = (
11 Path(__file__).resolve().parents[2]
12 / "src"
13 / "fenrirscreenreader"
14 / "commands"
15 / "commands"
16 )
17
18
19 def load_command(name):
20 spec = importlib.util.spec_from_file_location(
21 f"fenrir_{name}", COMMANDS_DIR / f"{name}.py"
22 )
23 module = importlib.util.module_from_spec(spec)
24 spec.loader.exec_module(module)
25 return module.command()
26
27
28 def build_environment(cursor):
29 settings_manager = Mock()
30 settings_manager.get_setting_as_bool.return_value = True
31 output_manager = Mock()
32 cursor_manager = Mock()
33 cursor_manager.enter_review_mode_curr_text_cursor.return_value = None
34 cursor_manager.get_review_or_text_cursor.return_value = cursor
35
36 return {
37 "punctuation": {"PUNCTDICT": {" ": "space"}},
38 "screen": {
39 "newCursorReview": cursor.copy(),
40 "new_cursor": cursor.copy(),
41 "new_content_text": "abc\ndef",
42 },
43 "runtime": {
44 "AttributeManager": Mock(has_attributes=Mock(return_value=False)),
45 "CursorManager": cursor_manager,
46 "OutputManager": output_manager,
47 "SettingsManager": settings_manager,
48 "TableManager": Mock(is_table_mode=Mock(return_value=False)),
49 },
50 }
51
52
53 def run_command(name, cursor):
54 env = build_environment(cursor)
55 command = load_command(name)
56 command.initialize(env)
57 command.run()
58 return env["runtime"]["OutputManager"]
59
60
61 def boundary_call(output_manager):
62 return output_manager.present_text.call_args_list[-1]
63
64
65 @pytest.mark.unit
66 def test_previous_line_uses_start_of_screen_sound_at_top():
67 output_manager = run_command("review_prev_line", {"x": 0, "y": 0})
68
69 call = boundary_call(output_manager)
70 assert call.args[0] == "start of screen"
71 assert call.kwargs["sound_icon"] == "StartOfScreen"
72
73
74 @pytest.mark.unit
75 def test_next_line_uses_end_of_screen_sound_at_bottom():
76 output_manager = run_command("review_next_line", {"x": 0, "y": 1})
77
78 call = boundary_call(output_manager)
79 assert call.args[0] == "end of screen"
80 assert call.kwargs["sound_icon"] == "EndOfScreen"
81
82
83 @pytest.mark.unit
84 def test_previous_character_uses_start_of_screen_sound_at_top_left():
85 output_manager = run_command("review_prev_char", {"x": 0, "y": 0})
86
87 call = boundary_call(output_manager)
88 assert call.args[0] == "start of screen"
89 assert call.kwargs["sound_icon"] == "StartOfScreen"
90
91
92 @pytest.mark.unit
93 def test_next_character_uses_end_of_screen_sound_at_bottom_right():
94 output_manager = run_command("review_next_char", {"x": 2, "y": 1})
95
96 call = boundary_call(output_manager)
97 assert call.args[0] == "end of screen"
98 assert call.kwargs["sound_icon"] == "EndOfScreen"
99
100
101 @pytest.mark.unit
102 def test_vertical_character_navigation_reports_boundaries_only_at_edges():
103 assert char_utils.get_up_char(0, 1, "abc\ndef") == (
104 0,
105 0,
106 "a",
107 False,
108 )
109 assert char_utils.get_up_char(0, 0, "abc\ndef") == (
110 0,
111 0,
112 "",
113 True,
114 )
115 assert char_utils.get_down_char(0, 0, "abc\ndef") == (
116 0,
117 1,
118 "d",
119 False,
120 )
121 assert char_utils.get_down_char(0, 1, "abc\ndef") == (
122 0,
123 1,
124 "",
125 True,
126 )