Debian Codegraph @

tests/unit_tests/test_command_registry.py

raw
1 # Unit tests for verifying all Orca commands are properly registered.
2 #
3 # Copyright 2026 Igalia, S.L.
4 # Author: Joanmarie Diggs <[email protected]>
5 #
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the
18 # Free Software Foundation, Inc., Franklin Street, Fifth Floor,
19 # Boston MA 02110-1301 USA.
20
21 # pylint: disable=wrong-import-position
22 # pylint: disable=import-outside-toplevel
23 # pylint: disable=protected-access
24 # pylint: disable=too-many-lines
25 # pylint: disable=too-many-public-methods
26
27 """Unit tests for verifying all Orca commands are properly registered."""
28
29 from __future__ import annotations
30
31 from typing import TYPE_CHECKING
32
33 import pytest
34
35 if TYPE_CHECKING:
36 from unittest.mock import MagicMock
37
38 from .orca_test_context import OrcaTestContext
39
40
41 # Expected handler names for each module.
42 # These serve as the source of truth for what handlers should exist.
43
44 FLAT_REVIEW_PRESENTER_HANDLERS = frozenset(
45 {
46 "toggleFlatReviewModeHandler",
47 "reviewHomeHandler",
48 "reviewEndHandler",
49 "reviewBottomLeftHandler",
50 "reviewPreviousLineHandler",
51 "reviewCurrentLineHandler",
52 "reviewNextLineHandler",
53 "reviewSpellCurrentLineHandler",
54 "reviewPhoneticCurrentLineHandler",
55 "reviewEndOfLineHandler",
56 "reviewPreviousItemHandler",
57 "reviewCurrentItemHandler",
58 "reviewNextItemHandler",
59 "reviewSpellCurrentItemHandler",
60 "reviewPhoneticCurrentItemHandler",
61 "reviewPreviousCharacterHandler",
62 "reviewCurrentCharacterHandler",
63 "reviewNextCharacterHandler",
64 "reviewSpellCurrentCharacterHandler",
65 "reviewUnicodeCurrentCharacterHandler",
66 "reviewCurrentAccessibleHandler",
67 "reviewAboveHandler",
68 "reviewBelowHandler",
69 "showContentsHandler",
70 "flatReviewCopyHandler",
71 "flatReviewAppendHandler",
72 "flatReviewSayAllHandler",
73 "flatReviewToggleRestrictHandler",
74 },
75 )
76
77 FLAT_REVIEW_FINDER_HANDLERS = frozenset(
78 {
79 "findHandler",
80 "findNextHandler",
81 "findPreviousHandler",
82 },
83 )
84
85 WHERE_AM_I_PRESENTER_HANDLERS = frozenset(
86 {
87 "whereAmIBasicHandler",
88 "whereAmIDetailedHandler",
89 "getTitleHandler",
90 "getStatusBarHandler",
91 "whereAmILinkHandler",
92 "whereAmISelectionHandler",
93 "readCharAttributesHandler",
94 "presentSizeAndPositionHandler",
95 "present_default_button",
96 "present_cell_formula",
97 },
98 )
99
100 LIVE_REGION_PRESENTER_HANDLERS = frozenset(
101 {
102 "toggle_live_region_support",
103 "present_previous_live_region_message",
104 "advance_live_politeness",
105 "toggle_live_region_presentation",
106 "present_next_live_region_message",
107 },
108 )
109
110 NOTIFICATION_PRESENTER_HANDLERS = frozenset(
111 {
112 "present_last_notification",
113 "present_next_notification",
114 "present_previous_notification",
115 "show_notification_list",
116 },
117 )
118
119 CHAT_PRESENTER_HANDLERS = frozenset(
120 {
121 "chat_toggle_room_name_prefix",
122 "chat_toggle_buddy_typing",
123 "chat_toggle_message_histories",
124 "chat_previous_message",
125 "chat_next_message",
126 },
127 )
128
129 SYSTEM_INFORMATION_PRESENTER_HANDLERS = frozenset(
130 {
131 "presentTimeHandler",
132 "presentDateHandler",
133 "present_battery_status",
134 "present_cpu_and_memory_usage",
135 },
136 )
137
138 LEARN_MODE_PRESENTER_HANDLERS = frozenset(
139 {
140 "enterLearnModeHandler",
141 },
142 )
143
144 ACTION_PRESENTER_HANDLERS = frozenset(
145 {
146 "show_actions_list",
147 },
148 )
149
150 MOUSE_REVIEW_HANDLERS = frozenset(
151 {
152 "toggleMouseReviewHandler",
153 },
154 )
155
156 SLEEP_MODE_MANAGER_HANDLERS = frozenset(
157 {
158 "toggle_sleep_mode",
159 },
160 )
161
162 BYPASS_MODE_MANAGER_HANDLERS = frozenset(
163 {
164 "bypass_mode_toggle",
165 },
166 )
167
168 DEBUGGING_TOOLS_MANAGER_HANDLERS = frozenset(
169 {
170 "cycleDebugLevelHandler",
171 "clear_atspi_app_cache",
172 },
173 )
174
175 CLIPBOARD_HANDLERS = frozenset(
176 {
177 "present_clipboard_contents",
178 },
179 )
180
181 TYPING_ECHO_PRESENTER_HANDLERS = frozenset(
182 {
183 "cycleKeyEchoHandler",
184 },
185 )
186
187 CARET_NAVIGATOR_HANDLERS = frozenset(
188 {
189 "end_of_file",
190 "end_of_line",
191 "next_character",
192 "next_line",
193 "next_word",
194 "previous_character",
195 "previous_line",
196 "previous_word",
197 "start_of_file",
198 "start_of_line",
199 "toggle_enabled",
200 "toggle_layout_mode",
201 },
202 )
203
204 STRUCTURAL_NAVIGATOR_HANDLERS = frozenset(
205 {
206 "container_end",
207 "container_start",
208 "last_live_region",
209 "list_blockquotes",
210 "list_buttons",
211 "list_checkboxes",
212 "list_clickables",
213 "list_comboboxes",
214 "list_entries",
215 "list_form_fields",
216 "list_headings",
217 "list_headings_level_1",
218 "list_headings_level_2",
219 "list_headings_level_3",
220 "list_headings_level_4",
221 "list_headings_level_5",
222 "list_headings_level_6",
223 "list_iframes",
224 "list_images",
225 "list_landmarks",
226 "list_large_objects",
227 "list_links",
228 "list_list_items",
229 "list_lists",
230 "list_paragraphs",
231 "list_radio_buttons",
232 "list_tables",
233 "list_unvisited_links",
234 "list_visited_links",
235 "next_blockquote",
236 "next_button",
237 "next_checkbox",
238 "next_clickable",
239 "next_combobox",
240 "next_entry",
241 "next_form_field",
242 "next_heading",
243 "next_heading_level_1",
244 "next_heading_level_2",
245 "next_heading_level_3",
246 "next_heading_level_4",
247 "next_heading_level_5",
248 "next_heading_level_6",
249 "next_iframe",
250 "next_image",
251 "next_landmark",
252 "next_large_object",
253 "next_link",
254 "next_list",
255 "next_list_item",
256 "next_live_region",
257 "next_paragraph",
258 "next_radio_button",
259 "next_separator",
260 "next_table",
261 "next_unvisited_link",
262 "next_visited_link",
263 "previous_blockquote",
264 "previous_button",
265 "previous_checkbox",
266 "previous_clickable",
267 "previous_combobox",
268 "previous_entry",
269 "previous_form_field",
270 "previous_heading",
271 "previous_heading_level_1",
272 "previous_heading_level_2",
273 "previous_heading_level_3",
274 "previous_heading_level_4",
275 "previous_heading_level_5",
276 "previous_heading_level_6",
277 "previous_iframe",
278 "previous_image",
279 "previous_landmark",
280 "previous_large_object",
281 "previous_link",
282 "previous_list",
283 "previous_list_item",
284 "previous_live_region",
285 "previous_paragraph",
286 "previous_radio_button",
287 "previous_separator",
288 "previous_table",
289 "previous_unvisited_link",
290 "previous_visited_link",
291 "structural_navigator_mode_cycle",
292 },
293 )
294
295 TABLE_NAVIGATOR_HANDLERS = frozenset(
296 {
297 "clear_dynamic_column_headers_row",
298 "clear_dynamic_row_headers_column",
299 "set_dynamic_column_headers_row",
300 "set_dynamic_row_headers_column",
301 "table_cell_beginning_of_row",
302 "table_cell_bottom_of_column",
303 "table_cell_down",
304 "table_cell_end_of_row",
305 "table_cell_first",
306 "table_cell_last",
307 "table_cell_left",
308 "table_cell_right",
309 "table_cell_top_of_column",
310 "table_cell_up",
311 "table_navigator_toggle_enabled",
312 },
313 )
314
315 OBJECT_NAVIGATOR_HANDLERS = frozenset(
316 {
317 "object_navigator_down",
318 "object_navigator_next",
319 "object_navigator_perform_action",
320 "object_navigator_previous",
321 "object_navigator_toggle_simplify",
322 "object_navigator_up",
323 },
324 )
325
326 SAY_ALL_PRESENTER_HANDLERS = frozenset(
327 {
328 "sayAllHandler",
329 },
330 )
331
332 SPEECH_MANAGER_HANDLERS = frozenset(
333 {
334 "cycleCapitalizationStyleHandler",
335 "cycleSpeakingPunctuationLevelHandler",
336 "cycleSynthesizerHandler",
337 "decreaseSpeechPitchHandler",
338 "decreaseSpeechRateHandler",
339 "decreaseSpeechVolumeHandler",
340 "increaseSpeechPitchHandler",
341 "increaseSpeechRateHandler",
342 "increaseSpeechVolumeHandler",
343 "toggleSilenceSpeechHandler",
344 },
345 )
346
347 SPEECH_PRESENTER_HANDLERS = frozenset(
348 {
349 "changeNumberStyleHandler",
350 "toggleSpeakingIndentationJustificationHandler",
351 "toggleSpeechVerbosityHandler",
352 "toggleTableCellReadModeHandler",
353 },
354 )
355
356 # Script handlers - these will eventually move to presenter/manager modules
357 DEFAULT_SCRIPT_HANDLERS = frozenset(
358 {
359 "appPreferencesSettingsHandler",
360 "contractedBrailleHandler",
361 "cycleSettingsProfileHandler",
362 "goBrailleHomeHandler",
363 "leftClickReviewItemHandler",
364 "panBrailleLeftHandler",
365 "panBrailleRightHandler",
366 "preferencesSettingsHandler",
367 "processBrailleCutBeginHandler",
368 "processBrailleCutLineHandler",
369 "processRoutingKeyHandler",
370 "rightClickReviewItemHandler",
371 "routePointerToItemHandler",
372 "shutdownHandler",
373 },
374 )
375
376 DOCUMENT_PRESENTER_HANDLERS = frozenset(
377 {
378 "enable_sticky_browse_mode",
379 "enable_sticky_focus_mode",
380 "toggle_presentation_mode",
381 },
382 )
383
384 # Total expected command count for verification
385 EXPECTED_TOTAL_COMMANDS = (
386 len(FLAT_REVIEW_PRESENTER_HANDLERS)
387 + len(FLAT_REVIEW_FINDER_HANDLERS)
388 + len(WHERE_AM_I_PRESENTER_HANDLERS)
389 + len(LIVE_REGION_PRESENTER_HANDLERS)
390 + len(NOTIFICATION_PRESENTER_HANDLERS)
391 + len(CHAT_PRESENTER_HANDLERS)
392 + len(SYSTEM_INFORMATION_PRESENTER_HANDLERS)
393 + len(LEARN_MODE_PRESENTER_HANDLERS)
394 + len(ACTION_PRESENTER_HANDLERS)
395 + len(MOUSE_REVIEW_HANDLERS)
396 + len(SLEEP_MODE_MANAGER_HANDLERS)
397 + len(BYPASS_MODE_MANAGER_HANDLERS)
398 + len(DEBUGGING_TOOLS_MANAGER_HANDLERS)
399 + len(CLIPBOARD_HANDLERS)
400 + len(TYPING_ECHO_PRESENTER_HANDLERS)
401 + len(CARET_NAVIGATOR_HANDLERS)
402 + len(STRUCTURAL_NAVIGATOR_HANDLERS)
403 + len(TABLE_NAVIGATOR_HANDLERS)
404 + len(OBJECT_NAVIGATOR_HANDLERS)
405 + len(SAY_ALL_PRESENTER_HANDLERS)
406 + len(SPEECH_MANAGER_HANDLERS)
407 + len(SPEECH_PRESENTER_HANDLERS)
408 + len(DEFAULT_SCRIPT_HANDLERS)
409 + len(DOCUMENT_PRESENTER_HANDLERS)
410 )
411
412
413 class Fake:
414 """A simple class to use as a mock for Atspi constants and classes."""
415
416
417 @pytest.mark.unit
418 class TestCommandRegistry:
419 """Tests for verifying all Orca commands are properly registered."""
420
421 def _setup_dependencies(self, test_context: OrcaTestContext) -> dict[str, MagicMock]:
422 """Sets up dependencies for command registry testing."""
423
424 additional_modules = [
425 "gi",
426 "gi.repository",
427 "gi.repository.Atspi",
428 "gi.repository.Gtk",
429 "gi.repository.GLib",
430 "gi.repository.Wnck",
431 "dasbus",
432 "dasbus.connection",
433 "dasbus.error",
434 "dasbus.client",
435 "dasbus.client.proxy",
436 "orca.dbus_service",
437 "orca.flat_review",
438 "orca.sound",
439 "orca.speech",
440 "orca.braille",
441 "orca.braille_presenter",
442 "orca.focus_manager",
443 "orca.script_manager",
444 "orca.ax_table",
445 "orca.ax_text",
446 "orca.ax_event_synthesizer",
447 "orca.speech_manager",
448 "orca.speech_presenter",
449 "orca.orca_platform",
450 ]
451 essential_modules = test_context.setup_shared_dependencies(additional_modules)
452
453 gi_mock = essential_modules["gi"]
454 gi_mock.require_version = test_context.Mock()
455
456 gi_repository_mock = essential_modules["gi.repository"]
457 atspi_mock = essential_modules["gi.repository.Atspi"]
458 atspi_mock.Role = Fake
459 atspi_mock.Accessible = Fake
460 atspi_mock.MatchRule = Fake
461 atspi_mock.Relation = Fake
462 atspi_mock.get_version = test_context.Mock(return_value=(2, 52, 0))
463 gi_repository_mock.Atspi = atspi_mock
464
465 gtk_mock = essential_modules["gi.repository.Gtk"]
466 gtk_mock.Window = test_context.Mock()
467 gtk_mock.VBox = test_context.Mock()
468 gtk_mock.Label = test_context.Mock()
469 gtk_mock.Button = test_context.Mock()
470 gtk_mock.Entry = test_context.Mock()
471 gtk_mock.CheckButton = test_context.Mock()
472 gtk_mock.Dialog = test_context.Mock()
473 gtk_mock.ResponseType = test_context.Mock()
474 gtk_mock.ResponseType.OK = 1
475 gtk_mock.ResponseType.CANCEL = 0
476
477 glib_mock = essential_modules["gi.repository.GLib"]
478 glib_error_mock = type("GError", (Exception,), {})
479 glib_mock.GError = glib_error_mock
480
481 gio_wnck = essential_modules["gi.repository.Wnck"]
482
483 class Screen:
484 """Docstring for Screen."""
485
486 @staticmethod
487 def get_windows_stacked():
488 """Docstring for get_windows_stacked."""
489 return []
490
491 @staticmethod
492 def get_active_workspace():
493 """Docstring for get_active_workspace."""
494 return None
495
496 @staticmethod
497 def connect(_fill1, _fill2):
498 """Docstring for connect."""
499 return None
500
501 gio_wnck.Screen.get_default = test_context.Mock(return_value=Screen)
502 gi_repository_mock.Wnck = gio_wnck
503
504 debug_mock = essential_modules["orca.debug"]
505 debug_mock.debugFile = None
506
507 flat_review_mock = essential_modules["orca.flat_review"]
508 flat_review_mock.Context = Fake
509
510 return essential_modules
511
512 # pylint: disable-next=too-many-statements
513 def _setup_structural_navigator_dependencies(
514 self,
515 test_context: OrcaTestContext,
516 ) -> dict[str, MagicMock]:
517 """Sets up dependencies for structural navigator testing."""
518
519 additional_modules = [
520 "orca.cmdnames",
521 "orca.dbus_service",
522 "orca.debug",
523 "orca.focus_manager",
524 "orca.guilabels",
525 "orca.input_event_manager",
526 "orca.keybindings",
527 "orca.messages",
528 "orca.object_properties",
529 "orca.orca_gui_navlist",
530 "orca.orca_i18n",
531 "orca.script_manager",
532 "orca.AXHypertext",
533 "orca.AXObject",
534 "orca.AXTable",
535 "orca.AXText",
536 "orca.AXUtilities",
537 "orca.input_event",
538 ]
539 essential_modules = test_context.setup_shared_dependencies(additional_modules)
540
541 # Set up cmdnames with all required values
542 cmdnames = essential_modules["orca.cmdnames"]
543 cmdnames.STRUCTURAL_NAVIGATION_MODE_CYCLE = "cycle_mode"
544 cmdnames.BLOCKQUOTE_PREV = "previous_blockquote"
545 cmdnames.BLOCKQUOTE_NEXT = "next_blockquote"
546 cmdnames.BLOCKQUOTE_LIST = "list_blockquotes"
547 cmdnames.BUTTON_PREV = "previous_button"
548 cmdnames.BUTTON_NEXT = "next_button"
549 cmdnames.BUTTON_LIST = "list_buttons"
550 cmdnames.CHECK_BOX_PREV = "previous_checkbox"
551 cmdnames.CHECK_BOX_NEXT = "next_checkbox"
552 cmdnames.CHECK_BOX_LIST = "list_checkboxes"
553 cmdnames.COMBO_BOX_PREV = "previous_combobox"
554 cmdnames.COMBO_BOX_NEXT = "next_combobox"
555 cmdnames.COMBO_BOX_LIST = "list_comboboxes"
556 cmdnames.ENTRY_PREV = "previous_entry"
557 cmdnames.ENTRY_NEXT = "next_entry"
558 cmdnames.ENTRY_LIST = "list_entries"
559 cmdnames.FORM_FIELD_PREV = "previous_form_field"
560 cmdnames.FORM_FIELD_NEXT = "next_form_field"
561 cmdnames.FORM_FIELD_LIST = "list_form_fields"
562 cmdnames.HEADING_PREV = "previous_heading"
563 cmdnames.HEADING_NEXT = "next_heading"
564 cmdnames.HEADING_LIST = "list_headings"
565 cmdnames.HEADING_AT_LEVEL_PREV = "previous_heading_level_%d"
566 cmdnames.HEADING_AT_LEVEL_NEXT = "next_heading_level_%d"
567 cmdnames.HEADING_AT_LEVEL_LIST = "list_headings_level_%d"
568 cmdnames.IFRAME_PREV = "previous_iframe"
569 cmdnames.IFRAME_NEXT = "next_iframe"
570 cmdnames.IFRAME_LIST = "list_iframes"
571 cmdnames.IMAGE_PREV = "previous_image"
572 cmdnames.IMAGE_NEXT = "next_image"
573 cmdnames.IMAGE_LIST = "list_images"
574 cmdnames.LANDMARK_PREV = "previous_landmark"
575 cmdnames.LANDMARK_NEXT = "next_landmark"
576 cmdnames.LANDMARK_LIST = "list_landmarks"
577 cmdnames.LIST_PREV = "previous_list"
578 cmdnames.LIST_NEXT = "next_list"
579 cmdnames.LIST_LIST = "list_lists"
580 cmdnames.LIST_ITEM_PREV = "previous_list_item"
581 cmdnames.LIST_ITEM_NEXT = "next_list_item"
582 cmdnames.LIST_ITEM_LIST = "list_list_items"
583 cmdnames.LIVE_REGION_PREV = "previous_live_region"
584 cmdnames.LIVE_REGION_NEXT = "next_live_region"
585 cmdnames.LIVE_REGION_LAST = "last_live_region"
586 cmdnames.PARAGRAPH_PREV = "previous_paragraph"
587 cmdnames.PARAGRAPH_NEXT = "next_paragraph"
588 cmdnames.PARAGRAPH_LIST = "list_paragraphs"
589 cmdnames.RADIO_BUTTON_PREV = "previous_radio_button"
590 cmdnames.RADIO_BUTTON_NEXT = "next_radio_button"
591 cmdnames.RADIO_BUTTON_LIST = "list_radio_buttons"
592 cmdnames.SEPARATOR_PREV = "previous_separator"
593 cmdnames.SEPARATOR_NEXT = "next_separator"
594 cmdnames.TABLE_PREV = "previous_table"
595 cmdnames.TABLE_NEXT = "next_table"
596 cmdnames.TABLE_LIST = "list_tables"
597 cmdnames.UNVISITED_LINK_PREV = "previous_unvisited_link"
598 cmdnames.UNVISITED_LINK_NEXT = "next_unvisited_link"
599 cmdnames.UNVISITED_LINK_LIST = "list_unvisited_links"
600 cmdnames.VISITED_LINK_PREV = "previous_visited_link"
601 cmdnames.VISITED_LINK_NEXT = "next_visited_link"
602 cmdnames.VISITED_LINK_LIST = "list_visited_links"
603 cmdnames.LINK_PREV = "previous_link"
604 cmdnames.LINK_NEXT = "next_link"
605 cmdnames.LINK_LIST = "list_links"
606 cmdnames.CLICKABLE_PREV = "previous_clickable"
607 cmdnames.CLICKABLE_NEXT = "next_clickable"
608 cmdnames.CLICKABLE_LIST = "list_clickables"
609 cmdnames.LARGE_OBJECT_PREV = "previous_large_object"
610 cmdnames.LARGE_OBJECT_NEXT = "next_large_object"
611 cmdnames.LARGE_OBJECT_LIST = "list_large_objects"
612 cmdnames.CONTAINER_START = "container_start"
613 cmdnames.CONTAINER_END = "container_end"
614
615 essential_modules["orca.orca_i18n"]._ = lambda x: x
616 essential_modules["orca.debug"].print_message = test_context.Mock()
617 essential_modules["orca.debug"].LEVEL_INFO = 800
618
619 controller_mock = test_context.Mock()
620 controller_mock.register_decorated_module.return_value = None
621 essential_modules["orca.dbus_service"].get_remote_controller.return_value = controller_mock
622
623 focus_manager_instance = test_context.Mock()
624 focus_manager_instance.get_locus_of_focus.return_value = None
625 essential_modules["orca.focus_manager"].get_manager.return_value = focus_manager_instance
626
627 essential_modules["orca.AXObject"].supports_collection.return_value = True
628 essential_modules["orca.AXUtilities"].is_heading.return_value = False
629
630 return essential_modules
631
632 def _setup_speech_dependencies(self, test_context: OrcaTestContext) -> dict[str, MagicMock]:
633 """Sets up dependencies for speech manager and presenter testing."""
634
635 additional_modules = [
636 "orca.mathsymbols",
637 "orca.object_properties",
638 "orca.pronunciation_dictionary_manager",
639 "orca.speech",
640 "orca.speechserver",
641 "orca.acss",
642 "orca.ax_hypertext",
643 "orca.ax_table",
644 "orca.ax_text",
645 "orca.ax_utilities",
646 "orca.colornames",
647 "orca.ax_document",
648 ]
649 essential_modules = test_context.setup_shared_dependencies(additional_modules)
650
651 essential_modules["orca.orca_i18n"]._ = lambda x: x
652 essential_modules["orca.orca_i18n"].C_ = lambda c, x: x
653 essential_modules["orca.orca_i18n"].ngettext = lambda s, p, n: s if n == 1 else p
654
655 controller_mock = test_context.Mock()
656 controller_mock.register_decorated_module.return_value = None
657 essential_modules["orca.dbus_service"].get_remote_controller.return_value = controller_mock
658
659 def passthrough_decorator(func):
660 return func
661
662 essential_modules["orca.dbus_service"].getter = passthrough_decorator
663 essential_modules["orca.dbus_service"].setter = passthrough_decorator
664 essential_modules["orca.dbus_service"].command = passthrough_decorator
665 essential_modules["orca.dbus_service"].parameterized_command = passthrough_decorator
666
667 acss_mock = essential_modules["orca.acss"]
668 acss_mock.ACSS = test_context.Mock()
669 acss_mock.ACSS.RATE = "rate"
670 acss_mock.ACSS.AVERAGE_PITCH = "average-pitch"
671 acss_mock.ACSS.GAIN = "gain"
672
673 return essential_modules
674
675 def test_flat_review_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
676 """Test that all flat review presenter handlers are registered in CommandManager."""
677
678 self._setup_dependencies(test_context)
679 from orca import command_manager
680 from orca.flat_review_presenter import get_presenter
681
682 presenter = get_presenter()
683 presenter.set_up_commands()
684
685 cmd_manager = command_manager.get_manager()
686 missing = frozenset(
687 name
688 for name in FLAT_REVIEW_PRESENTER_HANDLERS
689 if cmd_manager.get_keyboard_command(name) is None
690 )
691 assert not missing, f"Missing commands in flat_review_presenter: {missing}"
692
693 def test_flat_review_finder_handlers_exist(self, test_context: OrcaTestContext) -> None:
694 """Test that all flat review finder handlers are registered in CommandManager."""
695
696 self._setup_dependencies(test_context)
697 from orca import command_manager
698 from orca.flat_review_finder import get_finder
699
700 finder = get_finder()
701 finder.set_up_commands()
702
703 cmd_manager = command_manager.get_manager()
704 missing = frozenset(
705 name
706 for name in FLAT_REVIEW_FINDER_HANDLERS
707 if cmd_manager.get_keyboard_command(name) is None
708 )
709 assert not missing, f"Missing commands in flat_review_finder: {missing}"
710
711 def test_where_am_i_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
712 """Test that all where am I presenter handlers are registered."""
713
714 self._setup_dependencies(test_context)
715 from orca import command_manager
716 from orca.where_am_i_presenter import get_presenter
717
718 presenter = get_presenter()
719 presenter.set_up_commands()
720 cmd_manager = command_manager.get_manager()
721
722 missing = frozenset(
723 name
724 for name in WHERE_AM_I_PRESENTER_HANDLERS
725 if cmd_manager.get_keyboard_command(name) is None
726 )
727 assert not missing, f"Missing commands in where_am_i_presenter: {missing}"
728
729 def test_notification_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
730 """Test that all notification presenter commands are registered with CommandManager."""
731
732 self._setup_dependencies(test_context)
733 from orca import command_manager
734 from orca.notification_presenter import get_presenter
735
736 presenter = get_presenter()
737 presenter.set_up_commands()
738 manager = command_manager.get_manager()
739
740 missing = frozenset(
741 name
742 for name in NOTIFICATION_PRESENTER_HANDLERS
743 if manager.get_keyboard_command(name) is None
744 )
745
746 assert not missing, f"Missing commands in notification_presenter: {missing}"
747
748 def test_system_information_presenter_handlers_exist(
749 self,
750 test_context: OrcaTestContext,
751 ) -> None:
752 """Test that all system info presenter commands are registered with CommandManager."""
753
754 self._setup_dependencies(test_context)
755 from orca import command_manager
756 from orca.system_information_presenter import get_presenter
757
758 presenter = get_presenter()
759 presenter.set_up_commands()
760 manager = command_manager.get_manager()
761
762 missing = frozenset(
763 name
764 for name in SYSTEM_INFORMATION_PRESENTER_HANDLERS
765 if manager.get_keyboard_command(name) is None
766 )
767
768 assert not missing, f"Missing commands in system_information_presenter: {missing}"
769
770 def test_sleep_mode_manager_handlers_exist(self, test_context: OrcaTestContext) -> None:
771 """Test that all sleep mode manager commands are registered with CommandManager."""
772
773 self._setup_dependencies(test_context)
774 from orca import command_manager
775 from orca.sleep_mode_manager import get_manager
776
777 manager = get_manager()
778 manager.set_up_commands()
779 cmd_manager = command_manager.get_manager()
780
781 missing = frozenset(
782 name
783 for name in SLEEP_MODE_MANAGER_HANDLERS
784 if cmd_manager.get_keyboard_command(name) is None
785 )
786
787 assert not missing, f"Missing commands in sleep_mode_manager: {missing}"
788
789 def test_live_region_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
790 """Test that all live region presenter handlers are registered."""
791
792 self._setup_dependencies(test_context)
793 from orca import command_manager
794 from orca.live_region_presenter import get_presenter
795
796 presenter = get_presenter()
797 presenter.set_up_commands()
798 cmd_manager = command_manager.get_manager()
799
800 missing = frozenset(
801 name
802 for name in LIVE_REGION_PRESENTER_HANDLERS
803 if cmd_manager.get_keyboard_command(name) is None
804 )
805 assert not missing, f"Missing commands in live_region_presenter: {missing}"
806
807 def test_chat_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
808 """Test that all chat presenter handlers are registered."""
809
810 self._setup_dependencies(test_context)
811 from orca import command_manager
812 from orca.chat_presenter import get_presenter
813
814 presenter = get_presenter()
815 presenter.set_up_commands()
816 cmd_manager = command_manager.get_manager()
817
818 missing = frozenset(
819 name
820 for name in CHAT_PRESENTER_HANDLERS
821 if cmd_manager.get_keyboard_command(name) is None
822 )
823 assert not missing, f"Missing commands in chat_presenter: {missing}"
824
825 def test_learn_mode_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
826 """Test that all learn mode presenter commands are registered with CommandManager."""
827
828 self._setup_dependencies(test_context)
829 from orca import command_manager
830 from orca.learn_mode_presenter import get_presenter
831
832 presenter = get_presenter()
833 presenter.set_up_commands()
834 manager = command_manager.get_manager()
835
836 missing = frozenset(
837 name
838 for name in LEARN_MODE_PRESENTER_HANDLERS
839 if manager.get_keyboard_command(name) is None
840 )
841
842 assert not missing, f"Missing commands in learn_mode_presenter: {missing}"
843
844 def test_action_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
845 """Test that all action presenter handlers are registered."""
846
847 self._setup_dependencies(test_context)
848 from orca import command_manager
849 from orca.action_presenter import get_presenter
850
851 presenter = get_presenter()
852 presenter.set_up_commands()
853 cmd_manager = command_manager.get_manager()
854
855 missing = frozenset(
856 name
857 for name in ACTION_PRESENTER_HANDLERS
858 if cmd_manager.get_keyboard_command(name) is None
859 )
860 assert not missing, f"Missing commands in action_presenter: {missing}"
861
862 def test_debugging_tools_manager_handlers_exist(self, test_context: OrcaTestContext) -> None:
863 """Test that all debugging tools manager handlers are registered."""
864
865 self._setup_dependencies(test_context)
866 from orca import command_manager
867 from orca.debugging_tools_manager import get_manager
868
869 manager = get_manager()
870 manager.set_up_commands()
871 cmd_manager = command_manager.get_manager()
872
873 missing = frozenset(
874 name
875 for name in DEBUGGING_TOOLS_MANAGER_HANDLERS
876 if cmd_manager.get_keyboard_command(name) is None
877 )
878 assert not missing, f"Missing commands in debugging_tools_manager: {missing}"
879
880 def test_bypass_mode_manager_handlers_exist(self, test_context: OrcaTestContext) -> None:
881 """Test that all bypass mode manager commands are registered with CommandManager."""
882
883 self._setup_dependencies(test_context)
884 from orca import command_manager
885 from orca.bypass_mode_manager import get_manager
886
887 manager = get_manager()
888 manager.set_up_commands()
889 cmd_manager = command_manager.get_manager()
890
891 missing = frozenset(
892 name
893 for name in BYPASS_MODE_MANAGER_HANDLERS
894 if cmd_manager.get_keyboard_command(name) is None
895 )
896
897 assert not missing, f"Missing commands in bypass_mode_manager: {missing}"
898
899 def test_mouse_review_handlers_exist(self, test_context: OrcaTestContext) -> None:
900 """Test that all mouse review handlers are registered."""
901
902 self._setup_dependencies(test_context)
903 from orca import command_manager
904 from orca.mouse_review import get_reviewer
905
906 reviewer = get_reviewer()
907 reviewer.set_up_commands()
908 cmd_manager = command_manager.get_manager()
909
910 missing = frozenset(
911 name for name in MOUSE_REVIEW_HANDLERS if cmd_manager.get_keyboard_command(name) is None
912 )
913 assert not missing, f"Missing commands in mouse_review: {missing}"
914
915 def test_typing_echo_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
916 """Test that all typing echo presenter handlers are registered."""
917
918 self._setup_dependencies(test_context)
919 from orca import command_manager
920 from orca.typing_echo_presenter import get_presenter
921
922 presenter = get_presenter()
923 presenter.set_up_commands()
924 cmd_manager = command_manager.get_manager()
925
926 missing = frozenset(
927 name
928 for name in TYPING_ECHO_PRESENTER_HANDLERS
929 if cmd_manager.get_keyboard_command(name) is None
930 )
931 assert not missing, f"Missing commands in typing_echo_presenter: {missing}"
932
933 def test_clipboard_handlers_exist(self, test_context: OrcaTestContext) -> None:
934 """Test that all clipboard handlers are registered."""
935
936 self._setup_dependencies(test_context)
937 from orca import command_manager
938 from orca.clipboard import get_presenter
939
940 presenter = get_presenter()
941 presenter.set_up_commands()
942 cmd_manager = command_manager.get_manager()
943
944 missing = frozenset(
945 name for name in CLIPBOARD_HANDLERS if cmd_manager.get_keyboard_command(name) is None
946 )
947 assert not missing, f"Missing commands in clipboard: {missing}"
948
949 def test_caret_navigator_handlers_exist(self, test_context: OrcaTestContext) -> None:
950 """Test that all caret navigator commands are registered with CommandManager.
951
952 Note: caret_navigator now registers Commands directly with CommandManager
953 instead of returning handlers from get_handlers(). This test verifies the
954 commands are properly registered.
955 """
956
957 self._setup_structural_navigator_dependencies(test_context)
958 from orca import command_manager
959 from orca.caret_navigator import get_navigator
960
961 navigator = get_navigator()
962 navigator.set_up_commands()
963 manager = command_manager.get_manager()
964
965 missing = frozenset(
966 name for name in CARET_NAVIGATOR_HANDLERS if manager.get_keyboard_command(name) is None
967 )
968
969 assert not missing, f"Missing commands in caret_navigator: {missing}"
970
971 def test_structural_navigator_handlers_exist(self, test_context: OrcaTestContext) -> None:
972 """Test that all structural navigator handlers are registered in CommandManager."""
973
974 self._setup_structural_navigator_dependencies(test_context)
975 from orca import command_manager
976 from orca.structural_navigator import get_navigator
977
978 navigator = get_navigator()
979 navigator.set_up_commands()
980
981 cmd_manager = command_manager.get_manager()
982 missing = frozenset(
983 name
984 for name in STRUCTURAL_NAVIGATOR_HANDLERS
985 if cmd_manager.get_keyboard_command(name) is None
986 )
987 assert not missing, f"Missing commands in structural_navigator: {missing}"
988
989 def test_table_navigator_handlers_exist(self, test_context: OrcaTestContext) -> None:
990 """Test that all table navigator handlers are registered in CommandManager."""
991
992 self._setup_dependencies(test_context)
993 from orca import command_manager
994 from orca.table_navigator import get_navigator
995
996 navigator = get_navigator()
997 navigator.set_up_commands()
998
999 cmd_manager = command_manager.get_manager()
1000 missing = frozenset(
1001 name
1002 for name in TABLE_NAVIGATOR_HANDLERS
1003 if cmd_manager.get_keyboard_command(name) is None
1004 )
1005 assert not missing, f"Missing commands in table_navigator: {missing}"
1006
1007 def test_object_navigator_handlers_exist(self, test_context: OrcaTestContext) -> None:
1008 """Test that all object navigator handlers are registered in CommandManager."""
1009
1010 self._setup_dependencies(test_context)
1011 from orca import command_manager
1012 from orca.object_navigator import get_navigator
1013
1014 navigator = get_navigator()
1015 navigator.set_up_commands()
1016
1017 cmd_manager = command_manager.get_manager()
1018 missing = frozenset(
1019 name
1020 for name in OBJECT_NAVIGATOR_HANDLERS
1021 if cmd_manager.get_keyboard_command(name) is None
1022 )
1023 assert not missing, f"Missing commands in object_navigator: {missing}"
1024
1025 def test_say_all_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
1026 """Test that all say all presenter handlers are registered."""
1027
1028 self._setup_structural_navigator_dependencies(test_context)
1029 from orca import command_manager
1030 from orca.say_all_presenter import get_presenter
1031
1032 presenter = get_presenter()
1033 presenter.set_up_commands()
1034 cmd_manager = command_manager.get_manager()
1035
1036 missing = frozenset(
1037 name
1038 for name in SAY_ALL_PRESENTER_HANDLERS
1039 if cmd_manager.get_keyboard_command(name) is None
1040 )
1041 assert not missing, f"Missing commands in say_all_presenter: {missing}"
1042
1043 def test_speech_manager_handlers_exist(self, test_context: OrcaTestContext) -> None:
1044 """Test that all speech manager handlers are registered in CommandManager."""
1045
1046 self._setup_speech_dependencies(test_context)
1047 from orca import command_manager
1048 from orca.speech_manager import get_manager
1049
1050 manager = get_manager()
1051 manager.set_up_commands()
1052
1053 cmd_manager = command_manager.get_manager()
1054 missing = frozenset(
1055 name
1056 for name in SPEECH_MANAGER_HANDLERS
1057 if cmd_manager.get_keyboard_command(name) is None
1058 )
1059 assert not missing, f"Missing commands in speech_manager: {missing}"
1060
1061 def test_speech_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
1062 """Test that all speech presenter handlers are registered in CommandManager."""
1063
1064 self._setup_speech_dependencies(test_context)
1065 from orca import command_manager
1066 from orca.speech_presenter import get_presenter
1067
1068 presenter = get_presenter()
1069 presenter.set_up_commands()
1070
1071 cmd_manager = command_manager.get_manager()
1072 missing = frozenset(
1073 name
1074 for name in SPEECH_PRESENTER_HANDLERS
1075 if cmd_manager.get_keyboard_command(name) is None
1076 )
1077 assert not missing, f"Missing commands in speech_presenter: {missing}"
1078
1079 def test_document_presenter_handlers_exist(self, test_context: OrcaTestContext) -> None:
1080 """Test that all document presenter handlers are registered."""
1081
1082 self._setup_structural_navigator_dependencies(test_context)
1083 from orca import command_manager
1084 from orca.document_presenter import get_presenter
1085
1086 presenter = get_presenter()
1087 presenter.set_up_commands()
1088 cmd_manager = command_manager.get_manager()
1089
1090 missing = frozenset(
1091 name
1092 for name in DOCUMENT_PRESENTER_HANDLERS
1093 if cmd_manager.get_keyboard_command(name) is None
1094 )
1095 assert not missing, f"Missing commands in document_presenter: {missing}"
1096
1097 def test_expected_total_command_count(self) -> None:
1098 """Test that the expected total command count is correct.
1099
1100 This test verifies the sum of all module handler counts matches
1101 the expected total. If this fails, a module's handlers may have
1102 been added or removed without updating the frozensets.
1103 """
1104
1105 # Calculate expected total from all frozensets
1106 calculated_total = (
1107 len(FLAT_REVIEW_PRESENTER_HANDLERS)
1108 + len(FLAT_REVIEW_FINDER_HANDLERS)
1109 + len(WHERE_AM_I_PRESENTER_HANDLERS)
1110 + len(LIVE_REGION_PRESENTER_HANDLERS)
1111 + len(NOTIFICATION_PRESENTER_HANDLERS)
1112 + len(CHAT_PRESENTER_HANDLERS)
1113 + len(SYSTEM_INFORMATION_PRESENTER_HANDLERS)
1114 + len(LEARN_MODE_PRESENTER_HANDLERS)
1115 + len(ACTION_PRESENTER_HANDLERS)
1116 + len(MOUSE_REVIEW_HANDLERS)
1117 + len(SLEEP_MODE_MANAGER_HANDLERS)
1118 + len(BYPASS_MODE_MANAGER_HANDLERS)
1119 + len(DEBUGGING_TOOLS_MANAGER_HANDLERS)
1120 + len(CLIPBOARD_HANDLERS)
1121 + len(TYPING_ECHO_PRESENTER_HANDLERS)
1122 + len(CARET_NAVIGATOR_HANDLERS)
1123 + len(STRUCTURAL_NAVIGATOR_HANDLERS)
1124 + len(TABLE_NAVIGATOR_HANDLERS)
1125 + len(OBJECT_NAVIGATOR_HANDLERS)
1126 + len(SAY_ALL_PRESENTER_HANDLERS)
1127 + len(SPEECH_MANAGER_HANDLERS)
1128 + len(SPEECH_PRESENTER_HANDLERS)
1129 + len(DEFAULT_SCRIPT_HANDLERS)
1130 + len(DOCUMENT_PRESENTER_HANDLERS)
1131 )
1132
1133 assert calculated_total == EXPECTED_TOTAL_COMMANDS, (
1134 f"Total command count mismatch: calculated {calculated_total}, "
1135 f"expected {EXPECTED_TOTAL_COMMANDS}"
1136 )