Debian Codegraph @

tests/unit_tests/test_ax_utilities_role.py

raw
1 # Unit tests for ax_utilities_role.py methods.
2 #
3 # Copyright 2025 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=too-many-lines
22 # pylint: disable=too-many-public-methods
23 # pylint: disable=wrong-import-position
24 # pylint: disable=import-outside-toplevel
25 # pylint: disable=too-many-arguments
26 # pylint: disable=too-many-positional-arguments
27
28 """Unit tests for ax_utilities_role.py methods."""
29
30 from __future__ import annotations
31
32 from typing import TYPE_CHECKING
33
34 import gi
35 import pytest
36
37 gi.require_version("Atspi", "2.0")
38 from gi.repository import Atspi
39
40 if TYPE_CHECKING:
41 from unittest.mock import MagicMock
42
43 from .orca_test_context import OrcaTestContext
44
45
46 @pytest.mark.unit
47 class TestAXUtilitiesRole:
48 """Test AXUtilitiesRole class methods."""
49
50 def _setup_dependencies(self, test_context: OrcaTestContext) -> dict[str, MagicMock]:
51 """Set up mocks for ax_utilities_role dependencies."""
52
53 additional_modules = [
54 "orca.ax_utilities_object",
55 "orca.ax_utilities_state",
56 "orca.object_properties",
57 ]
58 essential_modules = test_context.setup_shared_dependencies(additional_modules)
59
60 debug_mock = essential_modules["orca.debug"]
61 debug_mock.print_tokens = test_context.Mock()
62 debug_mock.LEVEL_INFO = 800
63
64 object_props_mock = essential_modules["orca.object_properties"]
65 object_props_mock.ROLE_SLIDER_HORIZONTAL = "slider horizontal"
66 object_props_mock.ROLE_SLIDER_VERTICAL = "slider vertical"
67 object_props_mock.ROLE_SCROLL_BAR_HORIZONTAL = "scroll bar horizontal"
68 object_props_mock.ROLE_SCROLL_BAR_VERTICAL = "scroll bar vertical"
69 object_props_mock.ROLE_SPLITTER_HORIZONTAL = "splitter horizontal"
70 object_props_mock.ROLE_SPLITTER_VERTICAL = "splitter vertical"
71 object_props_mock.ROLE_CONTENT_SUGGESTION = "content suggestion"
72 object_props_mock.ROLE_FEED = "feed"
73 object_props_mock.ROLE_FIGURE = "figure"
74 object_props_mock.ROLE_SWITCH = "switch"
75 object_props_mock.ROLE_ACKNOWLEDGMENTS = "acknowledgments"
76 object_props_mock.ROLE_ABSTRACT = "abstract"
77 object_props_mock.ROLE_BIBLIOENTRY = "biblioentry"
78 object_props_mock.ROLE_LANDMARK_BANNER = "banner"
79 object_props_mock.ROLE_LANDMARK_COMPLEMENTARY = "complementary"
80 object_props_mock.ROLE_LANDMARK_CONTENTINFO = "contentinfo"
81 object_props_mock.ROLE_LANDMARK_MAIN = "main"
82 object_props_mock.ROLE_LANDMARK_NAVIGATION = "navigation"
83 object_props_mock.ROLE_LANDMARK_REGION = "region"
84 object_props_mock.ROLE_LANDMARK_SEARCH = "search"
85
86 ax_object_class_mock = test_context.Mock()
87 ax_object_class_mock.get_role = test_context.Mock(return_value=Atspi.Role.UNKNOWN)
88 ax_object_class_mock.get_role_name = test_context.Mock(return_value="unknown")
89 ax_object_class_mock.get_attributes_dict = test_context.Mock(return_value={})
90 ax_object_class_mock.has_state = test_context.Mock(return_value=False)
91 ax_object_class_mock.find_ancestor = test_context.Mock(return_value=None)
92 ax_object_class_mock.find_descendant = test_context.Mock(return_value=None)
93 ax_object_class_mock.supports_value = test_context.Mock(return_value=False)
94 ax_object_class_mock.get_attribute = test_context.Mock(return_value=None)
95 essential_modules["orca.ax_object"].AXObject = ax_object_class_mock
96
97 state_class_mock = test_context.Mock()
98 state_class_mock.has_popup = test_context.Mock(return_value=False)
99 state_class_mock.is_editable = test_context.Mock(return_value=False)
100 state_class_mock.is_single_line = test_context.Mock(return_value=False)
101 state_class_mock.supports_autocompletion = test_context.Mock(return_value=False)
102 essential_modules["orca.ax_utilities_state"].AXUtilitiesState = state_class_mock
103
104 return essential_modules
105
106 @pytest.mark.parametrize(
107 "case",
108 [
109 {
110 "id": "color_chooser_role",
111 "method_name": "is_color_chooser",
112 "matching_role": Atspi.Role.COLOR_CHOOSER,
113 "non_matching_role": Atspi.Role.BUTTON,
114 },
115 {
116 "id": "column_header_role",
117 "method_name": "is_column_header",
118 "matching_role": Atspi.Role.COLUMN_HEADER,
119 "non_matching_role": Atspi.Role.ROW_HEADER,
120 },
121 {
122 "id": "alert_role",
123 "method_name": "is_alert",
124 "matching_role": Atspi.Role.ALERT,
125 "non_matching_role": Atspi.Role.DIALOG,
126 },
127 {
128 "id": "animation_role",
129 "method_name": "is_animation",
130 "matching_role": Atspi.Role.ANIMATION,
131 "non_matching_role": Atspi.Role.IMAGE,
132 },
133 {
134 "id": "application_role",
135 "method_name": "is_application",
136 "matching_role": Atspi.Role.APPLICATION,
137 "non_matching_role": Atspi.Role.FRAME,
138 },
139 {
140 "id": "arrow_role",
141 "method_name": "is_arrow",
142 "matching_role": Atspi.Role.ARROW,
143 "non_matching_role": Atspi.Role.BUTTON,
144 },
145 {
146 "id": "article_role",
147 "method_name": "is_article",
148 "matching_role": Atspi.Role.ARTICLE,
149 "non_matching_role": Atspi.Role.SECTION,
150 },
151 {
152 "id": "audio_role",
153 "method_name": "is_audio",
154 "matching_role": Atspi.Role.AUDIO,
155 "non_matching_role": Atspi.Role.VIDEO,
156 },
157 {
158 "id": "block_quote_role",
159 "method_name": "is_block_quote",
160 "matching_role": Atspi.Role.BLOCK_QUOTE,
161 "non_matching_role": Atspi.Role.PARAGRAPH,
162 },
163 {
164 "id": "calendar_role",
165 "method_name": "is_calendar",
166 "matching_role": Atspi.Role.CALENDAR,
167 "non_matching_role": Atspi.Role.DATE_EDITOR,
168 },
169 {
170 "id": "canvas_role",
171 "method_name": "is_canvas",
172 "matching_role": Atspi.Role.CANVAS,
173 "non_matching_role": Atspi.Role.IMAGE,
174 },
175 {
176 "id": "caption_role",
177 "method_name": "is_caption",
178 "matching_role": Atspi.Role.CAPTION,
179 "non_matching_role": Atspi.Role.LABEL,
180 },
181 {
182 "id": "chart_role",
183 "method_name": "is_chart",
184 "matching_role": Atspi.Role.CHART,
185 "non_matching_role": Atspi.Role.IMAGE,
186 },
187 {
188 "id": "check_box_role",
189 "method_name": "is_check_box",
190 "matching_role": Atspi.Role.CHECK_BOX,
191 "non_matching_role": Atspi.Role.RADIO_BUTTON,
192 },
193 {
194 "id": "check_menu_item_role",
195 "method_name": "is_check_menu_item",
196 "matching_role": Atspi.Role.CHECK_MENU_ITEM,
197 "non_matching_role": Atspi.Role.MENU_ITEM,
198 },
199 {
200 "id": "combo_box_role",
201 "method_name": "is_combo_box",
202 "matching_role": Atspi.Role.COMBO_BOX,
203 "non_matching_role": Atspi.Role.LIST_BOX,
204 },
205 {
206 "id": "date_editor_role",
207 "method_name": "is_date_editor",
208 "matching_role": Atspi.Role.DATE_EDITOR,
209 "non_matching_role": Atspi.Role.SPIN_BUTTON,
210 },
211 {
212 "id": "definition_role",
213 "method_name": "is_definition",
214 "matching_role": Atspi.Role.DEFINITION,
215 "non_matching_role": Atspi.Role.DESCRIPTION_VALUE,
216 },
217 {
218 "id": "description_list_role",
219 "method_name": "is_description_list",
220 "matching_role": Atspi.Role.DESCRIPTION_LIST,
221 "non_matching_role": Atspi.Role.LIST,
222 },
223 {
224 "id": "description_term_role",
225 "method_name": "is_description_term",
226 "matching_role": Atspi.Role.DESCRIPTION_TERM,
227 "non_matching_role": Atspi.Role.DESCRIPTION_VALUE,
228 },
229 {
230 "id": "description_value_role",
231 "method_name": "is_description_value",
232 "matching_role": Atspi.Role.DESCRIPTION_VALUE,
233 "non_matching_role": Atspi.Role.DESCRIPTION_TERM,
234 },
235 {
236 "id": "desktop_icon_role",
237 "method_name": "is_desktop_icon",
238 "matching_role": Atspi.Role.DESKTOP_ICON,
239 "non_matching_role": Atspi.Role.ICON,
240 },
241 {
242 "id": "dial_role",
243 "method_name": "is_dial",
244 "matching_role": Atspi.Role.DIAL,
245 "non_matching_role": Atspi.Role.SLIDER,
246 },
247 {
248 "id": "dialog_role",
249 "method_name": "is_dialog",
250 "matching_role": Atspi.Role.DIALOG,
251 "non_matching_role": Atspi.Role.FRAME,
252 },
253 {
254 "id": "directory_pane_role",
255 "method_name": "is_directory_pane",
256 "matching_role": Atspi.Role.DIRECTORY_PANE,
257 "non_matching_role": Atspi.Role.TREE,
258 },
259 {
260 "id": "document_email_role",
261 "method_name": "is_document_email",
262 "matching_role": Atspi.Role.DOCUMENT_EMAIL,
263 "non_matching_role": Atspi.Role.DOCUMENT_TEXT,
264 },
265 {
266 "id": "document_frame_role",
267 "method_name": "is_document_frame",
268 "matching_role": Atspi.Role.DOCUMENT_FRAME,
269 "non_matching_role": Atspi.Role.FRAME,
270 },
271 {
272 "id": "document_presentation_role",
273 "method_name": "is_document_presentation",
274 "matching_role": Atspi.Role.DOCUMENT_PRESENTATION,
275 "non_matching_role": Atspi.Role.DOCUMENT_TEXT,
276 },
277 {
278 "id": "document_spreadsheet_role",
279 "method_name": "is_document_spreadsheet",
280 "matching_role": Atspi.Role.DOCUMENT_SPREADSHEET,
281 "non_matching_role": Atspi.Role.DOCUMENT_TEXT,
282 },
283 {
284 "id": "document_text_role",
285 "method_name": "is_document_text",
286 "matching_role": Atspi.Role.DOCUMENT_TEXT,
287 "non_matching_role": Atspi.Role.TEXT,
288 },
289 {
290 "id": "document_web_role",
291 "method_name": "is_document_web",
292 "matching_role": Atspi.Role.DOCUMENT_WEB,
293 "non_matching_role": Atspi.Role.DOCUMENT_TEXT,
294 },
295 {
296 "id": "drawing_area_role",
297 "method_name": "is_drawing_area",
298 "matching_role": Atspi.Role.DRAWING_AREA,
299 "non_matching_role": Atspi.Role.CANVAS,
300 },
301 {
302 "id": "editbar_role",
303 "method_name": "is_editbar",
304 "matching_role": Atspi.Role.EDITBAR,
305 "non_matching_role": Atspi.Role.TOOL_BAR,
306 },
307 {
308 "id": "embedded_role",
309 "method_name": "is_embedded",
310 "matching_role": Atspi.Role.EMBEDDED,
311 "non_matching_role": Atspi.Role.PANEL,
312 },
313 {
314 "id": "entry_role",
315 "method_name": "is_entry",
316 "matching_role": Atspi.Role.ENTRY,
317 "non_matching_role": Atspi.Role.TEXT,
318 },
319 {
320 "id": "extended_role",
321 "method_name": "is_extended",
322 "matching_role": Atspi.Role.EXTENDED,
323 "non_matching_role": Atspi.Role.UNKNOWN,
324 },
325 {
326 "id": "file_chooser_role",
327 "method_name": "is_file_chooser",
328 "matching_role": Atspi.Role.FILE_CHOOSER,
329 "non_matching_role": Atspi.Role.DIALOG,
330 },
331 {
332 "id": "filler_role",
333 "method_name": "is_filler",
334 "matching_role": Atspi.Role.FILLER,
335 "non_matching_role": Atspi.Role.PANEL,
336 },
337 {
338 "id": "focus_traversable_role",
339 "method_name": "is_focus_traversable",
340 "matching_role": Atspi.Role.FOCUS_TRAVERSABLE,
341 "non_matching_role": Atspi.Role.PANEL,
342 },
343 {
344 "id": "font_chooser_role",
345 "method_name": "is_font_chooser",
346 "matching_role": Atspi.Role.FONT_CHOOSER,
347 "non_matching_role": Atspi.Role.COLOR_CHOOSER,
348 },
349 {
350 "id": "footer_role",
351 "method_name": "is_footer",
352 "matching_role": Atspi.Role.FOOTER,
353 "non_matching_role": Atspi.Role.HEADER,
354 },
355 {
356 "id": "footnote_role",
357 "method_name": "is_footnote",
358 "matching_role": Atspi.Role.FOOTNOTE,
359 "non_matching_role": Atspi.Role.STATIC,
360 },
361 {
362 "id": "form_role",
363 "method_name": "is_form",
364 "matching_role": Atspi.Role.FORM,
365 "non_matching_role": Atspi.Role.PANEL,
366 },
367 {
368 "id": "frame_role",
369 "method_name": "is_frame",
370 "matching_role": Atspi.Role.FRAME,
371 "non_matching_role": Atspi.Role.WINDOW,
372 },
373 {
374 "id": "glass_pane_role",
375 "method_name": "is_glass_pane",
376 "matching_role": Atspi.Role.GLASS_PANE,
377 "non_matching_role": Atspi.Role.PANEL,
378 },
379 {
380 "id": "header_role",
381 "method_name": "is_header",
382 "matching_role": Atspi.Role.HEADER,
383 "non_matching_role": Atspi.Role.FOOTER,
384 },
385 {
386 "id": "heading_role",
387 "method_name": "is_heading",
388 "matching_role": Atspi.Role.HEADING,
389 "non_matching_role": Atspi.Role.LABEL,
390 },
391 {
392 "id": "html_container_role",
393 "method_name": "is_html_container",
394 "matching_role": Atspi.Role.HTML_CONTAINER,
395 "non_matching_role": Atspi.Role.SECTION,
396 },
397 {
398 "id": "icon_role",
399 "method_name": "is_icon",
400 "matching_role": Atspi.Role.ICON,
401 "non_matching_role": Atspi.Role.IMAGE,
402 },
403 {
404 "id": "image_role",
405 "method_name": "is_image",
406 "matching_role": Atspi.Role.IMAGE,
407 "non_matching_role": Atspi.Role.ICON,
408 },
409 {
410 "id": "image_map_role",
411 "method_name": "is_image_map",
412 "matching_role": Atspi.Role.IMAGE_MAP,
413 "non_matching_role": Atspi.Role.IMAGE,
414 },
415 {
416 "id": "info_bar_role",
417 "method_name": "is_info_bar",
418 "matching_role": Atspi.Role.INFO_BAR,
419 "non_matching_role": Atspi.Role.TOOL_BAR,
420 },
421 {
422 "id": "input_method_window_role",
423 "method_name": "is_input_method_window",
424 "matching_role": Atspi.Role.INPUT_METHOD_WINDOW,
425 "non_matching_role": Atspi.Role.WINDOW,
426 },
427 {
428 "id": "internal_frame_role",
429 "method_name": "is_internal_frame",
430 "matching_role": Atspi.Role.INTERNAL_FRAME,
431 "non_matching_role": Atspi.Role.FRAME,
432 },
433 {
434 "id": "invalid_role",
435 "method_name": "is_invalid_role",
436 "matching_role": Atspi.Role.INVALID,
437 "non_matching_role": Atspi.Role.UNKNOWN,
438 },
439 {
440 "id": "label_role",
441 "method_name": "is_label",
442 "matching_role": Atspi.Role.LABEL,
443 "non_matching_role": Atspi.Role.STATIC,
444 },
445 {
446 "id": "landmark_role",
447 "method_name": "is_landmark",
448 "matching_role": Atspi.Role.LANDMARK,
449 "non_matching_role": Atspi.Role.SECTION,
450 },
451 {
452 "id": "layered_pane_role",
453 "method_name": "is_layered_pane",
454 "matching_role": Atspi.Role.LAYERED_PANE,
455 "non_matching_role": Atspi.Role.PANEL,
456 },
457 {
458 "id": "level_bar_role",
459 "method_name": "is_level_bar",
460 "matching_role": Atspi.Role.LEVEL_BAR,
461 "non_matching_role": Atspi.Role.PROGRESS_BAR,
462 },
463 {
464 "id": "link_role",
465 "method_name": "is_link",
466 "matching_role": Atspi.Role.LINK,
467 "non_matching_role": Atspi.Role.TEXT,
468 },
469 {
470 "id": "list_role",
471 "method_name": "is_list",
472 "matching_role": Atspi.Role.LIST,
473 "non_matching_role": Atspi.Role.LIST_BOX,
474 },
475 {
476 "id": "list_box_role",
477 "method_name": "is_list_box",
478 "matching_role": Atspi.Role.LIST_BOX,
479 "non_matching_role": Atspi.Role.LIST,
480 },
481 {
482 "id": "list_item_role",
483 "method_name": "is_list_item",
484 "matching_role": Atspi.Role.LIST_ITEM,
485 "non_matching_role": Atspi.Role.LIST,
486 },
487 {
488 "id": "log_role",
489 "method_name": "is_log",
490 "matching_role": Atspi.Role.LOG,
491 "non_matching_role": Atspi.Role.TEXT,
492 },
493 {
494 "id": "marquee_role",
495 "method_name": "is_marquee",
496 "matching_role": Atspi.Role.MARQUEE,
497 "non_matching_role": Atspi.Role.ANIMATION,
498 },
499 {
500 "id": "math_role",
501 "method_name": "is_math",
502 "matching_role": Atspi.Role.MATH,
503 "non_matching_role": Atspi.Role.STATIC,
504 },
505 {
506 "id": "math_fraction_role",
507 "method_name": "is_math_fraction",
508 "matching_role": Atspi.Role.MATH_FRACTION,
509 "non_matching_role": Atspi.Role.MATH,
510 },
511 {
512 "id": "math_root_role",
513 "method_name": "is_math_root",
514 "matching_role": Atspi.Role.MATH_ROOT,
515 "non_matching_role": Atspi.Role.MATH,
516 },
517 {
518 "id": "menu_role",
519 "method_name": "is_menu",
520 "matching_role": Atspi.Role.MENU,
521 "non_matching_role": Atspi.Role.MENU_BAR,
522 },
523 {
524 "id": "menu_bar_role",
525 "method_name": "is_menu_bar",
526 "matching_role": Atspi.Role.MENU_BAR,
527 "non_matching_role": Atspi.Role.MENU,
528 },
529 {
530 "id": "menu_item_role",
531 "method_name": "is_menu_item",
532 "matching_role": Atspi.Role.MENU_ITEM,
533 "non_matching_role": Atspi.Role.CHECK_MENU_ITEM,
534 },
535 {
536 "id": "notification_role",
537 "method_name": "is_notification",
538 "matching_role": Atspi.Role.NOTIFICATION,
539 "non_matching_role": Atspi.Role.ALERT,
540 },
541 {
542 "id": "option_pane_role",
543 "method_name": "is_option_pane",
544 "matching_role": Atspi.Role.OPTION_PANE,
545 "non_matching_role": Atspi.Role.PANEL,
546 },
547 {
548 "id": "page_role",
549 "method_name": "is_page",
550 "matching_role": Atspi.Role.PAGE,
551 "non_matching_role": Atspi.Role.SECTION,
552 },
553 {
554 "id": "page_tab_role",
555 "method_name": "is_page_tab",
556 "matching_role": Atspi.Role.PAGE_TAB,
557 "non_matching_role": Atspi.Role.PAGE_TAB_LIST,
558 },
559 {
560 "id": "page_tab_list_role",
561 "method_name": "is_page_tab_list",
562 "matching_role": Atspi.Role.PAGE_TAB_LIST,
563 "non_matching_role": Atspi.Role.PAGE_TAB,
564 },
565 {
566 "id": "panel_role",
567 "method_name": "is_panel",
568 "matching_role": Atspi.Role.PANEL,
569 "non_matching_role": Atspi.Role.FILLER,
570 },
571 {
572 "id": "paragraph_role",
573 "method_name": "is_paragraph",
574 "matching_role": Atspi.Role.PARAGRAPH,
575 "non_matching_role": Atspi.Role.TEXT,
576 },
577 {
578 "id": "password_text_role",
579 "method_name": "is_password_text",
580 "matching_role": Atspi.Role.PASSWORD_TEXT,
581 "non_matching_role": Atspi.Role.TEXT,
582 },
583 {
584 "id": "popup_menu_role",
585 "method_name": "is_popup_menu",
586 "matching_role": Atspi.Role.POPUP_MENU,
587 "non_matching_role": Atspi.Role.MENU,
588 },
589 {
590 "id": "progress_bar_role",
591 "method_name": "is_progress_bar",
592 "matching_role": Atspi.Role.PROGRESS_BAR,
593 "non_matching_role": Atspi.Role.LEVEL_BAR,
594 },
595 {
596 "id": "push_button_role",
597 "method_name": "is_push_button",
598 "matching_role": Atspi.Role.BUTTON,
599 "non_matching_role": Atspi.Role.TOGGLE_BUTTON,
600 },
601 {
602 "id": "push_button_menu_role",
603 "method_name": "is_push_button_menu",
604 "matching_role": Atspi.Role.PUSH_BUTTON_MENU,
605 "non_matching_role": Atspi.Role.BUTTON,
606 },
607 {
608 "id": "radio_button_role",
609 "method_name": "is_radio_button",
610 "matching_role": Atspi.Role.RADIO_BUTTON,
611 "non_matching_role": Atspi.Role.CHECK_BOX,
612 },
613 {
614 "id": "radio_menu_item_role",
615 "method_name": "is_radio_menu_item",
616 "matching_role": Atspi.Role.RADIO_MENU_ITEM,
617 "non_matching_role": Atspi.Role.CHECK_MENU_ITEM,
618 },
619 {
620 "id": "rating_role",
621 "method_name": "is_rating",
622 "matching_role": Atspi.Role.RATING,
623 "non_matching_role": Atspi.Role.SLIDER,
624 },
625 {
626 "id": "redundant_object_role",
627 "method_name": "is_redundant_object_role",
628 "matching_role": Atspi.Role.REDUNDANT_OBJECT,
629 "non_matching_role": Atspi.Role.UNKNOWN,
630 },
631 {
632 "id": "root_pane_role",
633 "method_name": "is_root_pane",
634 "matching_role": Atspi.Role.ROOT_PANE,
635 "non_matching_role": Atspi.Role.PANEL,
636 },
637 {
638 "id": "row_header_role",
639 "method_name": "is_row_header",
640 "matching_role": Atspi.Role.ROW_HEADER,
641 "non_matching_role": Atspi.Role.COLUMN_HEADER,
642 },
643 {
644 "id": "ruler_role",
645 "method_name": "is_ruler",
646 "matching_role": Atspi.Role.RULER,
647 "non_matching_role": Atspi.Role.SEPARATOR,
648 },
649 {
650 "id": "scroll_bar_role",
651 "method_name": "is_scroll_bar",
652 "matching_role": Atspi.Role.SCROLL_BAR,
653 "non_matching_role": Atspi.Role.SLIDER,
654 },
655 {
656 "id": "scroll_pane_role",
657 "method_name": "is_scroll_pane",
658 "matching_role": Atspi.Role.SCROLL_PANE,
659 "non_matching_role": Atspi.Role.PANEL,
660 },
661 {
662 "id": "section_role",
663 "method_name": "is_section",
664 "matching_role": Atspi.Role.SECTION,
665 "non_matching_role": Atspi.Role.ARTICLE,
666 },
667 {
668 "id": "separator_role",
669 "method_name": "is_separator",
670 "matching_role": Atspi.Role.SEPARATOR,
671 "non_matching_role": Atspi.Role.RULER,
672 },
673 {
674 "id": "slider_role",
675 "method_name": "is_slider",
676 "matching_role": Atspi.Role.SLIDER,
677 "non_matching_role": Atspi.Role.SCROLL_BAR,
678 },
679 {
680 "id": "spin_button_role",
681 "method_name": "is_spin_button",
682 "matching_role": Atspi.Role.SPIN_BUTTON,
683 "non_matching_role": Atspi.Role.ENTRY,
684 },
685 {
686 "id": "split_pane_role",
687 "method_name": "is_split_pane",
688 "matching_role": Atspi.Role.SPLIT_PANE,
689 "non_matching_role": Atspi.Role.PANEL,
690 },
691 {
692 "id": "static_role",
693 "method_name": "is_static",
694 "matching_role": Atspi.Role.STATIC,
695 "non_matching_role": Atspi.Role.LABEL,
696 },
697 {
698 "id": "status_bar_role",
699 "method_name": "is_status_bar",
700 "matching_role": Atspi.Role.STATUS_BAR,
701 "non_matching_role": Atspi.Role.TOOL_BAR,
702 },
703 {
704 "id": "subscript_role",
705 "method_name": "is_subscript",
706 "matching_role": Atspi.Role.SUBSCRIPT,
707 "non_matching_role": Atspi.Role.SUPERSCRIPT,
708 },
709 {
710 "id": "superscript_role",
711 "method_name": "is_superscript",
712 "matching_role": Atspi.Role.SUPERSCRIPT,
713 "non_matching_role": Atspi.Role.SUBSCRIPT,
714 },
715 {
716 "id": "table_role",
717 "method_name": "is_table",
718 "matching_role": Atspi.Role.TABLE,
719 "non_matching_role": Atspi.Role.TREE_TABLE,
720 },
721 {
722 "id": "table_cell_role",
723 "method_name": "is_table_cell",
724 "matching_role": Atspi.Role.TABLE_CELL,
725 "non_matching_role": Atspi.Role.COLUMN_HEADER,
726 },
727 {
728 "id": "terminal_role",
729 "method_name": "is_terminal",
730 "matching_role": Atspi.Role.TERMINAL,
731 "non_matching_role": Atspi.Role.TEXT,
732 },
733 {
734 "id": "text_role",
735 "method_name": "is_text",
736 "matching_role": Atspi.Role.TEXT,
737 "non_matching_role": Atspi.Role.LABEL,
738 },
739 {
740 "id": "timer_role",
741 "method_name": "is_timer",
742 "matching_role": Atspi.Role.TIMER,
743 "non_matching_role": Atspi.Role.STATIC,
744 },
745 {
746 "id": "title_bar_role",
747 "method_name": "is_title_bar",
748 "matching_role": Atspi.Role.TITLE_BAR,
749 "non_matching_role": Atspi.Role.TOOL_BAR,
750 },
751 {
752 "id": "toggle_button_role",
753 "method_name": "is_toggle_button",
754 "matching_role": Atspi.Role.TOGGLE_BUTTON,
755 "non_matching_role": Atspi.Role.BUTTON,
756 },
757 {
758 "id": "tool_bar_role",
759 "method_name": "is_tool_bar",
760 "matching_role": Atspi.Role.TOOL_BAR,
761 "non_matching_role": Atspi.Role.PANEL,
762 },
763 {
764 "id": "tool_tip_role",
765 "method_name": "is_tool_tip",
766 "matching_role": Atspi.Role.TOOL_TIP,
767 "non_matching_role": Atspi.Role.LABEL,
768 },
769 {
770 "id": "tree_role",
771 "method_name": "is_tree",
772 "matching_role": Atspi.Role.TREE,
773 "non_matching_role": Atspi.Role.TREE_TABLE,
774 },
775 {
776 "id": "tree_item_role",
777 "method_name": "is_tree_item",
778 "matching_role": Atspi.Role.TREE_ITEM,
779 "non_matching_role": Atspi.Role.LIST_ITEM,
780 },
781 {
782 "id": "tree_table_role",
783 "method_name": "is_tree_table",
784 "matching_role": Atspi.Role.TREE_TABLE,
785 "non_matching_role": Atspi.Role.TABLE,
786 },
787 {
788 "id": "unknown_role",
789 "method_name": "is_unknown",
790 "matching_role": Atspi.Role.UNKNOWN,
791 "non_matching_role": Atspi.Role.INVALID,
792 },
793 {
794 "id": "video_role",
795 "method_name": "is_video",
796 "matching_role": Atspi.Role.VIDEO,
797 "non_matching_role": Atspi.Role.AUDIO,
798 },
799 {
800 "id": "viewport_role",
801 "method_name": "is_viewport",
802 "matching_role": Atspi.Role.VIEWPORT,
803 "non_matching_role": Atspi.Role.PANEL,
804 },
805 {
806 "id": "window_role",
807 "method_name": "is_window",
808 "matching_role": Atspi.Role.WINDOW,
809 "non_matching_role": Atspi.Role.FRAME,
810 },
811 ],
812 ids=lambda case: case["id"],
813 )
814 def test_simple_role_methods(self, test_context, case: dict) -> None:
815 """Test AXUtilitiesRole simple role methods."""
816
817 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
818 mock_obj = test_context.Mock(spec=Atspi.Accessible)
819 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
820 mock_ax_object_class.get_role = test_context.Mock(return_value=case["matching_role"])
821 from orca.ax_utilities_role import AXUtilitiesRole
822
823 method = getattr(AXUtilitiesRole, case["method_name"])
824 assert method(mock_obj)
825 mock_ax_object_class.get_role = test_context.Mock(return_value=case["non_matching_role"])
826
827 method = getattr(AXUtilitiesRole, case["method_name"])
828 assert not method(mock_obj)
829
830 @pytest.mark.parametrize(
831 "case",
832 [
833 {"id": "push_button_true", "role": Atspi.Role.BUTTON, "expected": True},
834 {"id": "toggle_button_true", "role": Atspi.Role.TOGGLE_BUTTON, "expected": True},
835 {"id": "label_false", "role": Atspi.Role.LABEL, "expected": False},
836 ],
837 ids=lambda case: case["id"],
838 )
839 def test_is_button(self, test_context: OrcaTestContext, case: dict) -> None:
840 """Test AXUtilitiesRole.is_button with various roles."""
841
842 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
843 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
844 mock_ax_object_class.get_role = test_context.Mock(return_value=case["role"])
845 from orca.ax_utilities_role import AXUtilitiesRole
846
847 mock_obj = test_context.Mock(spec=Atspi.Accessible)
848 result = AXUtilitiesRole.is_button(mock_obj)
849 assert result is case["expected"]
850
851 def test_children_are_presentational(self, test_context: OrcaTestContext) -> None:
852 """Test AXUtilitiesRole.children_are_presentational."""
853
854 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
855 mock_obj = test_context.Mock(spec=Atspi.Accessible)
856
857 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
858 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.BUTTON)
859 from orca.ax_utilities_role import AXUtilitiesRole
860
861 assert AXUtilitiesRole.children_are_presentational(mock_obj)
862
863 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.SWITCH)
864 assert AXUtilitiesRole.children_are_presentational(mock_obj)
865
866 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.LABEL)
867 assert not AXUtilitiesRole.children_are_presentational(mock_obj)
868
869 def test_get_localized_role_name_with_atspi_role(self, test_context: OrcaTestContext) -> None:
870 """Test AXUtilitiesRole.get_localized_role_name with standard Atspi.Role."""
871
872 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
873 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
874 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
875 mock_ax_object_class.supports_value = test_context.Mock(return_value=False)
876 from orca.ax_utilities_role import AXUtilitiesRole
877
878 mock_obj = test_context.Mock(spec=Atspi.Accessible)
879 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=False)
880 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
881 test_context.patch_object(AXUtilitiesRole, "is_comment", return_value=False)
882 if hasattr(Atspi, "role_get_localized_name"):
883 test_context.patch_object(
884 Atspi,
885 "role_get_localized_name",
886 return_value="LocalizedRole",
887 )
888 else:
889 test_context.patch_object(Atspi, "role_get_name", return_value="LocalizedRole")
890 assert (
891 AXUtilitiesRole.get_localized_role_name(mock_obj, Atspi.Role.BUTTON) == "LocalizedRole"
892 )
893
894 def test_get_localized_role_name_with_non_atspi_role(
895 self,
896 test_context: OrcaTestContext,
897 ) -> None:
898 """Test AXUtilitiesRole.get_localized_role_name with non-Atspi.Role value."""
899
900 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
901 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
902 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
903 mock_ax_object_class.get_role_name = test_context.Mock(return_value="role_name")
904 mock_ax_object_class.supports_value = test_context.Mock(return_value=False)
905 from orca.ax_utilities_role import AXUtilitiesRole
906
907 mock_obj = test_context.Mock(spec=Atspi.Accessible)
908 assert AXUtilitiesRole.get_localized_role_name(mock_obj, "not_a_role") == "role_name"
909
910 def test_get_localized_role_name_with_dpub_roles(self, test_context: OrcaTestContext) -> None:
911 """Test AXUtilitiesRole.get_localized_role_name for DPUB roles."""
912
913 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
914 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
915 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
916 mock_ax_object_class.supports_value = test_context.Mock(return_value=False)
917 from orca import object_properties
918 from orca.ax_utilities_role import AXUtilitiesRole
919
920 mock_obj = test_context.Mock(spec=Atspi.Accessible)
921 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=True)
922 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=True)
923 test_context.patch_object(AXUtilitiesRole, "is_dpub_acknowledgments", return_value=True)
924 assert (
925 AXUtilitiesRole.get_localized_role_name(mock_obj, Atspi.Role.LANDMARK)
926 == object_properties.ROLE_ACKNOWLEDGMENTS
927 )
928 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
929 test_context.patch_object(AXUtilitiesRole, "is_dpub_abstract", return_value=True)
930 assert (
931 AXUtilitiesRole.get_localized_role_name(mock_obj, "ROLE_DPUB_SECTION")
932 == object_properties.ROLE_ABSTRACT
933 )
934 test_context.patch_object(AXUtilitiesRole, "is_list_item", return_value=True)
935 test_context.patch_object(AXUtilitiesRole, "is_dpub_biblioref", return_value=True)
936 assert (
937 AXUtilitiesRole.get_localized_role_name(mock_obj, Atspi.Role.LIST_ITEM)
938 == object_properties.ROLE_BIBLIOENTRY
939 )
940
941 @pytest.mark.parametrize(
942 "case",
943 [
944 {
945 "id": "horizontal_slider",
946 "supports_value": True,
947 "role_check_method": "is_horizontal_slider",
948 "role": Atspi.Role.SLIDER,
949 "expected_result": "object_properties.ROLE_SLIDER_HORIZONTAL",
950 },
951 {
952 "id": "vertical_slider",
953 "supports_value": True,
954 "role_check_method": "is_vertical_slider",
955 "role": Atspi.Role.SLIDER,
956 "expected_result": "object_properties.ROLE_SLIDER_VERTICAL",
957 },
958 {
959 "id": "horizontal_scrollbar",
960 "supports_value": True,
961 "role_check_method": "is_horizontal_scrollbar",
962 "role": Atspi.Role.SCROLL_BAR,
963 "expected_result": "object_properties.ROLE_SCROLL_BAR_HORIZONTAL",
964 },
965 {
966 "id": "vertical_scrollbar",
967 "supports_value": True,
968 "role_check_method": "is_vertical_scrollbar",
969 "role": Atspi.Role.SCROLL_BAR,
970 "expected_result": "object_properties.ROLE_SCROLL_BAR_VERTICAL",
971 },
972 {
973 "id": "horizontal_separator",
974 "supports_value": True,
975 "role_check_method": "is_horizontal_separator",
976 "role": Atspi.Role.SEPARATOR,
977 "expected_result": "object_properties.ROLE_SPLITTER_HORIZONTAL",
978 },
979 {
980 "id": "vertical_separator",
981 "supports_value": True,
982 "role_check_method": "is_vertical_separator",
983 "role": Atspi.Role.SEPARATOR,
984 "expected_result": "object_properties.ROLE_SPLITTER_VERTICAL",
985 },
986 ],
987 ids=lambda case: case["id"],
988 )
989 def test_get_localized_role_name_value_based_roles(
990 self,
991 test_context: OrcaTestContext,
992 case: dict,
993 ) -> None:
994 """Test AXUtilitiesRole.get_localized_role_name for value-based roles."""
995
996 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
997 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
998 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
999 mock_ax_object_class.supports_value = test_context.Mock(return_value=case["supports_value"])
1000 from orca import object_properties
1001 from orca.ax_utilities_role import AXUtilitiesRole
1002
1003 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1004 role_methods = [
1005 "is_horizontal_slider",
1006 "is_vertical_slider",
1007 "is_horizontal_scrollbar",
1008 "is_vertical_scrollbar",
1009 "is_horizontal_separator",
1010 "is_vertical_separator",
1011 "is_split_pane",
1012 ]
1013 for method in role_methods:
1014 test_context.patch_object(
1015 AXUtilitiesRole,
1016 method,
1017 side_effect=lambda obj, role=None, m=method: m == case["role_check_method"],
1018 )
1019
1020 test_context.patch_object(AXUtilitiesRole, "is_suggestion", return_value=False)
1021 test_context.patch_object(AXUtilitiesRole, "is_feed", return_value=False)
1022 test_context.patch_object(AXUtilitiesRole, "is_figure", return_value=False)
1023 test_context.patch_object(AXUtilitiesRole, "is_switch", return_value=False)
1024 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=False)
1025 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
1026 test_context.patch_object(AXUtilitiesRole, "is_comment", return_value=False)
1027
1028 result = AXUtilitiesRole.get_localized_role_name(mock_obj, case["role"])
1029 expected = getattr(object_properties, case["expected_result"].split(".")[1])
1030 assert result == expected
1031
1032 @pytest.mark.parametrize(
1033 "case",
1034 [
1035 {
1036 "id": "horizontal_state",
1037 "has_horizontal_state": True,
1038 "has_vertical_state": False,
1039 "expected_result": "object_properties.ROLE_SPLITTER_VERTICAL",
1040 },
1041 {
1042 "id": "vertical_state",
1043 "has_horizontal_state": False,
1044 "has_vertical_state": True,
1045 "expected_result": "object_properties.ROLE_SPLITTER_HORIZONTAL",
1046 },
1047 {
1048 "id": "no_orientation",
1049 "has_horizontal_state": False,
1050 "has_vertical_state": False,
1051 "expected_result": None,
1052 },
1053 ],
1054 ids=lambda case: case["id"],
1055 )
1056 def test_get_localized_role_name_split_pane_orientation(
1057 self,
1058 test_context: OrcaTestContext,
1059 case: dict,
1060 ) -> None:
1061 """Test AXUtilitiesRole.get_localized_role_name for split pane orientation."""
1062
1063 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1064 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1065 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1066 mock_ax_object_class.supports_value = test_context.Mock(return_value=True)
1067 mock_ax_object_class.has_state = test_context.Mock(
1068 side_effect=lambda obj, state: (
1069 (state == Atspi.StateType.HORIZONTAL and case["has_horizontal_state"])
1070 or (state == Atspi.StateType.VERTICAL and case["has_vertical_state"])
1071 ),
1072 )
1073 from orca import object_properties
1074 from orca.ax_utilities_role import AXUtilitiesRole
1075
1076 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1077 test_context.patch_object(AXUtilitiesRole, "is_split_pane", return_value=True)
1078 test_context.patch_object(AXUtilitiesRole, "is_horizontal_slider", return_value=False)
1079 test_context.patch_object(AXUtilitiesRole, "is_vertical_slider", return_value=False)
1080 test_context.patch_object(AXUtilitiesRole, "is_horizontal_scrollbar", return_value=False)
1081 test_context.patch_object(AXUtilitiesRole, "is_vertical_scrollbar", return_value=False)
1082 test_context.patch_object(AXUtilitiesRole, "is_horizontal_separator", return_value=False)
1083 test_context.patch_object(AXUtilitiesRole, "is_vertical_separator", return_value=False)
1084
1085 test_context.patch_object(AXUtilitiesRole, "is_suggestion", return_value=False)
1086 test_context.patch_object(AXUtilitiesRole, "is_feed", return_value=False)
1087 test_context.patch_object(AXUtilitiesRole, "is_figure", return_value=False)
1088 test_context.patch_object(AXUtilitiesRole, "is_switch", return_value=False)
1089 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=False)
1090 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
1091 test_context.patch_object(AXUtilitiesRole, "is_comment", return_value=False)
1092 test_context.patch_object(Atspi, "role_get_localized_name", return_value="fallback_role")
1093
1094 result = AXUtilitiesRole.get_localized_role_name(mock_obj, Atspi.Role.SPLIT_PANE)
1095 if case["expected_result"]:
1096 expected = getattr(object_properties, case["expected_result"].split(".")[1])
1097 assert result == expected
1098 else:
1099 assert result == "fallback_role"
1100
1101 @pytest.mark.parametrize(
1102 "case",
1103 [
1104 {
1105 "id": "suggestion",
1106 "role_check_method": "is_suggestion",
1107 "expected_result": "object_properties.ROLE_CONTENT_SUGGESTION",
1108 },
1109 {
1110 "id": "feed",
1111 "role_check_method": "is_feed",
1112 "expected_result": "object_properties.ROLE_FEED",
1113 },
1114 {
1115 "id": "figure",
1116 "role_check_method": "is_figure",
1117 "expected_result": "object_properties.ROLE_FIGURE",
1118 },
1119 {
1120 "id": "switch",
1121 "role_check_method": "is_switch",
1122 "expected_result": "object_properties.ROLE_SWITCH",
1123 },
1124 ],
1125 ids=lambda case: case["id"],
1126 )
1127 def test_get_localized_role_name_simple_roles(
1128 self,
1129 test_context: OrcaTestContext,
1130 case: dict,
1131 ) -> None:
1132 """Test AXUtilitiesRole.get_localized_role_name for simple role mappings."""
1133
1134 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1135 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1136 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1137 mock_ax_object_class.supports_value = test_context.Mock(return_value=False)
1138 from orca import object_properties
1139 from orca.ax_utilities_role import AXUtilitiesRole
1140
1141 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1142 simple_methods = ["is_suggestion", "is_feed", "is_figure", "is_switch"]
1143 for method in simple_methods:
1144 test_context.patch_object(
1145 AXUtilitiesRole,
1146 method,
1147 side_effect=lambda obj, role=None, m=method: m == case["role_check_method"],
1148 )
1149
1150 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=False)
1151 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
1152 test_context.patch_object(AXUtilitiesRole, "is_comment", return_value=False)
1153
1154 result = AXUtilitiesRole.get_localized_role_name(mock_obj, Atspi.Role.UNKNOWN)
1155 expected = getattr(object_properties, case["expected_result"].split(".")[1])
1156 assert result == expected
1157
1158 @pytest.mark.parametrize(
1159 "case",
1160 [
1161 {
1162 "id": "landmark_banner",
1163 "role_check_method": "is_landmark_banner",
1164 "expected_result": "object_properties.ROLE_LANDMARK_BANNER",
1165 },
1166 {
1167 "id": "landmark_complementary",
1168 "role_check_method": "is_landmark_complementary",
1169 "expected_result": "object_properties.ROLE_LANDMARK_COMPLEMENTARY",
1170 },
1171 {
1172 "id": "landmark_contentinfo",
1173 "role_check_method": "is_landmark_contentinfo",
1174 "expected_result": "object_properties.ROLE_LANDMARK_CONTENTINFO",
1175 },
1176 {
1177 "id": "landmark_main",
1178 "role_check_method": "is_landmark_main",
1179 "expected_result": "object_properties.ROLE_LANDMARK_MAIN",
1180 },
1181 {
1182 "id": "landmark_navigation",
1183 "role_check_method": "is_landmark_navigation",
1184 "expected_result": "object_properties.ROLE_LANDMARK_NAVIGATION",
1185 },
1186 {
1187 "id": "landmark_region",
1188 "role_check_method": "is_landmark_region",
1189 "expected_result": "object_properties.ROLE_LANDMARK_REGION",
1190 },
1191 {
1192 "id": "landmark_search",
1193 "role_check_method": "is_landmark_search",
1194 "expected_result": "object_properties.ROLE_LANDMARK_SEARCH",
1195 },
1196 {
1197 "id": "landmark_without_type",
1198 "role_check_method": "is_landmark_without_type",
1199 "expected_result": "",
1200 },
1201 ],
1202 ids=lambda case: case["id"],
1203 )
1204 def test_get_localized_role_name_landmark_roles(
1205 self,
1206 test_context: OrcaTestContext,
1207 case: dict,
1208 ) -> None:
1209 """Test AXUtilitiesRole.get_localized_role_name for landmark roles."""
1210
1211 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1212 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1213 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1214 mock_ax_object_class.supports_value = test_context.Mock(return_value=False)
1215 from orca import object_properties
1216 from orca.ax_utilities_role import AXUtilitiesRole
1217
1218 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1219 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=True)
1220
1221 landmark_methods = [
1222 "is_landmark_without_type",
1223 "is_landmark_banner",
1224 "is_landmark_complementary",
1225 "is_landmark_contentinfo",
1226 "is_landmark_main",
1227 "is_landmark_navigation",
1228 "is_landmark_region",
1229 "is_landmark_search",
1230 "is_landmark_form",
1231 ]
1232 for method in landmark_methods:
1233 test_context.patch_object(
1234 AXUtilitiesRole,
1235 method,
1236 side_effect=lambda obj, role=None, m=method: m == case["role_check_method"],
1237 )
1238
1239 test_context.patch_object(AXUtilitiesRole, "is_suggestion", return_value=False)
1240 test_context.patch_object(AXUtilitiesRole, "is_feed", return_value=False)
1241 test_context.patch_object(AXUtilitiesRole, "is_figure", return_value=False)
1242 test_context.patch_object(AXUtilitiesRole, "is_switch", return_value=False)
1243 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=False)
1244 test_context.patch_object(AXUtilitiesRole, "is_comment", return_value=False)
1245
1246 result = AXUtilitiesRole.get_localized_role_name(mock_obj, Atspi.Role.LANDMARK)
1247 if case["expected_result"]:
1248 if case["expected_result"] == "":
1249 assert result == ""
1250 else:
1251 expected = getattr(object_properties, case["expected_result"].split(".")[1])
1252 assert result == expected
1253
1254 def test_get_localized_role_name_landmark_form_fallback(
1255 self,
1256 test_context: OrcaTestContext,
1257 ) -> None:
1258 """Test AXUtilitiesRole.get_localized_role_name landmark form fallback to FORM role."""
1259
1260 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1261 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1262 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1263 mock_ax_object_class.supports_value = test_context.Mock(return_value=False)
1264 from orca.ax_utilities_role import AXUtilitiesRole
1265
1266 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1267 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=True)
1268 test_context.patch_object(AXUtilitiesRole, "is_landmark_form", return_value=True)
1269 test_context.patch_object(AXUtilitiesRole, "is_landmark_without_type", return_value=False)
1270 test_context.patch_object(AXUtilitiesRole, "is_landmark_banner", return_value=False)
1271 test_context.patch_object(AXUtilitiesRole, "is_landmark_complementary", return_value=False)
1272 test_context.patch_object(AXUtilitiesRole, "is_landmark_contentinfo", return_value=False)
1273 test_context.patch_object(AXUtilitiesRole, "is_landmark_main", return_value=False)
1274 test_context.patch_object(AXUtilitiesRole, "is_landmark_navigation", return_value=False)
1275 test_context.patch_object(AXUtilitiesRole, "is_landmark_region", return_value=False)
1276 test_context.patch_object(AXUtilitiesRole, "is_landmark_search", return_value=False)
1277
1278 test_context.patch_object(AXUtilitiesRole, "is_suggestion", return_value=False)
1279 test_context.patch_object(AXUtilitiesRole, "is_feed", return_value=False)
1280 test_context.patch_object(AXUtilitiesRole, "is_figure", return_value=False)
1281 test_context.patch_object(AXUtilitiesRole, "is_switch", return_value=False)
1282 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=False)
1283 test_context.patch_object(AXUtilitiesRole, "is_comment", return_value=False)
1284 test_context.patch_object(Atspi, "role_get_localized_name", return_value="form_localized")
1285
1286 result = AXUtilitiesRole.get_localized_role_name(mock_obj, Atspi.Role.LANDMARK)
1287 assert result == "form_localized"
1288
1289 def test_get_localized_role_name_comment_fallback(self, test_context: OrcaTestContext) -> None:
1290 """Test AXUtilitiesRole.get_localized_role_name comment fallback to COMMENT role."""
1291
1292 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1293 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1294 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1295 mock_ax_object_class.supports_value = test_context.Mock(return_value=False)
1296 from orca.ax_utilities_role import AXUtilitiesRole
1297
1298 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1299 test_context.patch_object(AXUtilitiesRole, "is_comment", return_value=True)
1300 test_context.patch_object(AXUtilitiesRole, "is_suggestion", return_value=False)
1301 test_context.patch_object(AXUtilitiesRole, "is_feed", return_value=False)
1302 test_context.patch_object(AXUtilitiesRole, "is_figure", return_value=False)
1303 test_context.patch_object(AXUtilitiesRole, "is_switch", return_value=False)
1304 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=False)
1305 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
1306 test_context.patch_object(
1307 Atspi,
1308 "role_get_localized_name",
1309 return_value="comment_localized",
1310 )
1311
1312 result = AXUtilitiesRole.get_localized_role_name(mock_obj, Atspi.Role.SECTION)
1313 assert result == "comment_localized"
1314
1315 @pytest.mark.parametrize(
1316 "case",
1317 [
1318 {
1319 "id": "dpub_acknowledgments",
1320 "dpub_method": "is_dpub_acknowledgments",
1321 "expected_result": "object_properties.ROLE_ACKNOWLEDGMENTS",
1322 "role_context": "landmark",
1323 },
1324 {
1325 "id": "dpub_afterword",
1326 "dpub_method": "is_dpub_afterword",
1327 "expected_result": "object_properties.ROLE_AFTERWORD",
1328 "role_context": "landmark",
1329 },
1330 {
1331 "id": "dpub_appendix",
1332 "dpub_method": "is_dpub_appendix",
1333 "expected_result": "object_properties.ROLE_APPENDIX",
1334 "role_context": "landmark",
1335 },
1336 {
1337 "id": "dpub_bibliography",
1338 "dpub_method": "is_dpub_bibliography",
1339 "expected_result": "object_properties.ROLE_BIBLIOGRAPHY",
1340 "role_context": "landmark",
1341 },
1342 {
1343 "id": "dpub_chapter",
1344 "dpub_method": "is_dpub_chapter",
1345 "expected_result": "object_properties.ROLE_CHAPTER",
1346 "role_context": "landmark",
1347 },
1348 {
1349 "id": "dpub_conclusion",
1350 "dpub_method": "is_dpub_conclusion",
1351 "expected_result": "object_properties.ROLE_CONCLUSION",
1352 "role_context": "landmark",
1353 },
1354 {
1355 "id": "dpub_credits",
1356 "dpub_method": "is_dpub_credits",
1357 "expected_result": "object_properties.ROLE_CREDITS",
1358 "role_context": "landmark",
1359 },
1360 {
1361 "id": "dpub_endnotes",
1362 "dpub_method": "is_dpub_endnotes",
1363 "expected_result": "object_properties.ROLE_ENDNOTES",
1364 "role_context": "landmark",
1365 },
1366 {
1367 "id": "dpub_epilogue",
1368 "dpub_method": "is_dpub_epilogue",
1369 "expected_result": "object_properties.ROLE_EPILOGUE",
1370 "role_context": "landmark",
1371 },
1372 {
1373 "id": "dpub_errata",
1374 "dpub_method": "is_dpub_errata",
1375 "expected_result": "object_properties.ROLE_ERRATA",
1376 "role_context": "landmark",
1377 },
1378 {
1379 "id": "dpub_foreword",
1380 "dpub_method": "is_dpub_foreword",
1381 "expected_result": "object_properties.ROLE_FOREWORD",
1382 "role_context": "landmark",
1383 },
1384 {
1385 "id": "dpub_glossary",
1386 "dpub_method": "is_dpub_glossary",
1387 "expected_result": "object_properties.ROLE_GLOSSARY",
1388 "role_context": "landmark",
1389 },
1390 {
1391 "id": "dpub_index",
1392 "dpub_method": "is_dpub_index",
1393 "expected_result": "object_properties.ROLE_INDEX",
1394 "role_context": "landmark",
1395 },
1396 {
1397 "id": "dpub_introduction",
1398 "dpub_method": "is_dpub_introduction",
1399 "expected_result": "object_properties.ROLE_INTRODUCTION",
1400 "role_context": "landmark",
1401 },
1402 {
1403 "id": "dpub_pagelist",
1404 "dpub_method": "is_dpub_pagelist",
1405 "expected_result": "object_properties.ROLE_PAGELIST",
1406 "role_context": "landmark",
1407 },
1408 {
1409 "id": "dpub_part",
1410 "dpub_method": "is_dpub_part",
1411 "expected_result": "object_properties.ROLE_PART",
1412 "role_context": "landmark",
1413 },
1414 {
1415 "id": "dpub_preface",
1416 "dpub_method": "is_dpub_preface",
1417 "expected_result": "object_properties.ROLE_PREFACE",
1418 "role_context": "landmark",
1419 },
1420 {
1421 "id": "dpub_prologue",
1422 "dpub_method": "is_dpub_prologue",
1423 "expected_result": "object_properties.ROLE_PROLOGUE",
1424 "role_context": "landmark",
1425 },
1426 {
1427 "id": "dpub_toc",
1428 "dpub_method": "is_dpub_toc",
1429 "expected_result": "object_properties.ROLE_TOC",
1430 "role_context": "landmark",
1431 },
1432 {
1433 "id": "dpub_abstract",
1434 "dpub_method": "is_dpub_abstract",
1435 "expected_result": "object_properties.ROLE_ABSTRACT",
1436 "role_context": "section",
1437 },
1438 {
1439 "id": "dpub_colophon",
1440 "dpub_method": "is_dpub_colophon",
1441 "expected_result": "object_properties.ROLE_COLOPHON",
1442 "role_context": "section",
1443 },
1444 {
1445 "id": "dpub_credit",
1446 "dpub_method": "is_dpub_credit",
1447 "expected_result": "object_properties.ROLE_CREDIT",
1448 "role_context": "section",
1449 },
1450 {
1451 "id": "dpub_dedication",
1452 "dpub_method": "is_dpub_dedication",
1453 "expected_result": "object_properties.ROLE_DEDICATION",
1454 "role_context": "section",
1455 },
1456 {
1457 "id": "dpub_epigraph",
1458 "dpub_method": "is_dpub_epigraph",
1459 "expected_result": "object_properties.ROLE_EPIGRAPH",
1460 "role_context": "section",
1461 },
1462 {
1463 "id": "dpub_example",
1464 "dpub_method": "is_dpub_example",
1465 "expected_result": "object_properties.ROLE_EXAMPLE",
1466 "role_context": "section",
1467 },
1468 {
1469 "id": "dpub_pullquote",
1470 "dpub_method": "is_dpub_pullquote",
1471 "expected_result": "object_properties.ROLE_PULLQUOTE",
1472 "role_context": "section",
1473 },
1474 {
1475 "id": "dpub_qna",
1476 "dpub_method": "is_dpub_qna",
1477 "expected_result": "object_properties.ROLE_QNA",
1478 "role_context": "section",
1479 },
1480 {
1481 "id": "dpub_biblioref",
1482 "dpub_method": "is_dpub_biblioref",
1483 "expected_result": "object_properties.ROLE_BIBLIOENTRY",
1484 "role_context": "list_item",
1485 },
1486 {
1487 "id": "dpub_endnote",
1488 "dpub_method": "is_dpub_endnote",
1489 "expected_result": "object_properties.ROLE_ENDNOTE",
1490 "role_context": "list_item",
1491 },
1492 {
1493 "id": "dpub_cover",
1494 "dpub_method": "is_dpub_cover",
1495 "expected_result": "object_properties.ROLE_COVER",
1496 "role_context": "other",
1497 },
1498 {
1499 "id": "dpub_pagebreak",
1500 "dpub_method": "is_dpub_pagebreak",
1501 "expected_result": "object_properties.ROLE_PAGEBREAK",
1502 "role_context": "other",
1503 },
1504 {
1505 "id": "dpub_subtitle",
1506 "dpub_method": "is_dpub_subtitle",
1507 "expected_result": "object_properties.ROLE_SUBTITLE",
1508 "role_context": "other",
1509 },
1510 ],
1511 ids=lambda case: case["id"],
1512 )
1513 def test_get_localized_role_name_dpub_roles_comprehensive(
1514 self,
1515 test_context: OrcaTestContext,
1516 case: dict,
1517 ) -> None:
1518 """Test AXUtilitiesRole.get_localized_role_name for all DPUB role types."""
1519
1520 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1521 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1522 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1523 mock_ax_object_class.supports_value = test_context.Mock(return_value=False)
1524 from orca import object_properties
1525 from orca.ax_utilities_role import AXUtilitiesRole
1526
1527 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1528 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=True)
1529 if case["role_context"] == "landmark":
1530 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=True)
1531 test_context.patch_object(AXUtilitiesRole, "is_list_item", return_value=False)
1532 role_param = Atspi.Role.LANDMARK
1533 elif case["role_context"] == "section":
1534 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
1535 test_context.patch_object(AXUtilitiesRole, "is_list_item", return_value=False)
1536 role_param = "ROLE_DPUB_SECTION"
1537 elif case["role_context"] == "list_item":
1538 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
1539 test_context.patch_object(AXUtilitiesRole, "is_list_item", return_value=True)
1540 role_param = Atspi.Role.LIST_ITEM
1541 else:
1542 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
1543 test_context.patch_object(AXUtilitiesRole, "is_list_item", return_value=False)
1544 role_param = Atspi.Role.UNKNOWN
1545
1546 dpub_methods = [
1547 "is_dpub_acknowledgments",
1548 "is_dpub_afterword",
1549 "is_dpub_appendix",
1550 "is_dpub_bibliography",
1551 "is_dpub_chapter",
1552 "is_dpub_conclusion",
1553 "is_dpub_credits",
1554 "is_dpub_endnotes",
1555 "is_dpub_epilogue",
1556 "is_dpub_errata",
1557 "is_dpub_foreword",
1558 "is_dpub_glossary",
1559 "is_dpub_index",
1560 "is_dpub_introduction",
1561 "is_dpub_pagelist",
1562 "is_dpub_part",
1563 "is_dpub_preface",
1564 "is_dpub_prologue",
1565 "is_dpub_toc",
1566 "is_dpub_abstract",
1567 "is_dpub_colophon",
1568 "is_dpub_credit",
1569 "is_dpub_dedication",
1570 "is_dpub_epigraph",
1571 "is_dpub_example",
1572 "is_dpub_pullquote",
1573 "is_dpub_qna",
1574 "is_dpub_biblioref",
1575 "is_dpub_endnote",
1576 "is_dpub_cover",
1577 "is_dpub_pagebreak",
1578 "is_dpub_subtitle",
1579 ]
1580 for method in dpub_methods:
1581 test_context.patch_object(
1582 AXUtilitiesRole,
1583 method,
1584 side_effect=lambda obj, role=None, m=method: m == case["dpub_method"],
1585 )
1586
1587 test_context.patch_object(AXUtilitiesRole, "is_suggestion", return_value=False)
1588 test_context.patch_object(AXUtilitiesRole, "is_feed", return_value=False)
1589 test_context.patch_object(AXUtilitiesRole, "is_figure", return_value=False)
1590 test_context.patch_object(AXUtilitiesRole, "is_switch", return_value=False)
1591 test_context.patch_object(AXUtilitiesRole, "is_comment", return_value=False)
1592
1593 result = AXUtilitiesRole.get_localized_role_name(mock_obj, role_param)
1594 expected = getattr(object_properties, case["expected_result"].split(".")[1])
1595 assert result == expected
1596
1597 def test_get_localized_role_name_no_role_provided_uses_ax_object_get_role(
1598 self,
1599 test_context: OrcaTestContext,
1600 ) -> None:
1601 """Test AXUtilitiesRole.get_localized_role_name without role parameter."""
1602
1603 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1604 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1605 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1606 mock_ax_object_class.supports_value = test_context.Mock(return_value=False)
1607 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.BUTTON)
1608 from orca.ax_utilities_role import AXUtilitiesRole
1609
1610 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1611 test_context.patch_object(AXUtilitiesRole, "is_suggestion", return_value=False)
1612 test_context.patch_object(AXUtilitiesRole, "is_feed", return_value=False)
1613 test_context.patch_object(AXUtilitiesRole, "is_figure", return_value=False)
1614 test_context.patch_object(AXUtilitiesRole, "is_switch", return_value=False)
1615 test_context.patch_object(AXUtilitiesRole, "is_dpub", return_value=False)
1616 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
1617 test_context.patch_object(AXUtilitiesRole, "is_comment", return_value=False)
1618 test_context.patch_object(Atspi, "role_get_localized_name", return_value="button_localized")
1619
1620 result = AXUtilitiesRole.get_localized_role_name(mock_obj)
1621 assert result == "button_localized"
1622 mock_ax_object_class.get_role.assert_called_once_with(mock_obj)
1623
1624 def test_is_grid(self, test_context: OrcaTestContext) -> None:
1625 """Test AXUtilitiesRole.is_grid."""
1626
1627 self._setup_dependencies(test_context)
1628 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1629
1630 from orca.ax_utilities_role import AXUtilitiesRole
1631
1632 test_context.patch_object(AXUtilitiesRole, "is_table", return_value=False)
1633 assert not AXUtilitiesRole.is_grid(mock_obj)
1634
1635 test_context.patch_object(AXUtilitiesRole, "is_table", return_value=True)
1636 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=[])
1637 assert not AXUtilitiesRole.is_grid(mock_obj)
1638
1639 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=["grid"])
1640 assert AXUtilitiesRole.is_grid(mock_obj)
1641
1642 def test_is_grid_cell(self, test_context: OrcaTestContext) -> None:
1643 """Test AXUtilitiesRole.is_grid_cell."""
1644
1645 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1646 mock_ax_utilities_object_class = essential_modules[
1647 "orca.ax_utilities_object"
1648 ].AXUtilitiesObject
1649 mock_ax_utilities_object_class.find_ancestor = test_context.Mock(return_value=None)
1650 from orca.ax_utilities_role import AXUtilitiesRole
1651
1652 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1653 test_context.patch_object(AXUtilitiesRole, "is_table_cell", return_value=False)
1654 assert not AXUtilitiesRole.is_grid_cell(mock_obj)
1655
1656 test_context.patch_object(AXUtilitiesRole, "is_table_cell", return_value=True)
1657 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=["gridcell"])
1658 assert AXUtilitiesRole.is_grid_cell(mock_obj)
1659
1660 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=["cell"])
1661 mock_ax_utilities_object_class.find_ancestor = test_context.Mock(
1662 return_value=test_context.Mock()
1663 )
1664 assert AXUtilitiesRole.is_grid_cell(mock_obj)
1665
1666 mock_ax_utilities_object_class.find_ancestor = test_context.Mock(return_value=None)
1667 assert not AXUtilitiesRole.is_grid_cell(mock_obj)
1668
1669 def test_is_editable_combo_box(self, test_context: OrcaTestContext) -> None:
1670 """Test AXUtilitiesRole.is_editable_combo_box."""
1671
1672 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1673 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1674 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.LABEL)
1675 mock_ax_object_class.supports_collection = test_context.Mock(return_value=False)
1676 mock_ax_utilities_object_class = essential_modules[
1677 "orca.ax_utilities_object"
1678 ].AXUtilitiesObject
1679 mock_ax_utilities_object_class.find_descendant = test_context.Mock(return_value=None)
1680 mock_utilities_state_class = essential_modules["orca.ax_utilities_state"].AXUtilitiesState
1681 mock_utilities_state_class.is_editable = test_context.Mock(return_value=False)
1682 from orca.ax_utilities_role import AXUtilitiesRole
1683
1684 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1685 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.LABEL)
1686 assert not AXUtilitiesRole.is_editable_combo_box(mock_obj)
1687
1688 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.COMBO_BOX)
1689 mock_utilities_state_class.is_editable = test_context.Mock(return_value=True)
1690 assert AXUtilitiesRole.is_editable_combo_box(mock_obj)
1691
1692 mock_utilities_state_class.is_editable = test_context.Mock(return_value=False)
1693 mock_ax_utilities_object_class.find_descendant = test_context.Mock(
1694 return_value=test_context.Mock(),
1695 )
1696 assert AXUtilitiesRole.is_editable_combo_box(mock_obj)
1697
1698 mock_ax_utilities_object_class.find_descendant = test_context.Mock(return_value=None)
1699 assert not AXUtilitiesRole.is_editable_combo_box(mock_obj)
1700
1701 def test_is_feed_article(self, test_context: OrcaTestContext) -> None:
1702 """Test AXUtilitiesRole.is_feed_article."""
1703
1704 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1705 mock_ax_utilities_object_class = essential_modules[
1706 "orca.ax_utilities_object"
1707 ].AXUtilitiesObject
1708 mock_ax_utilities_object_class.find_ancestor = test_context.Mock(return_value=None)
1709 from orca.ax_utilities_role import AXUtilitiesRole
1710
1711 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1712 test_context.patch_object(AXUtilitiesRole, "is_article", return_value=False)
1713 assert not AXUtilitiesRole.is_feed_article(mock_obj)
1714
1715 test_context.patch_object(AXUtilitiesRole, "is_article", return_value=True)
1716 mock_ax_utilities_object_class.find_ancestor = test_context.Mock(return_value=None)
1717 assert not AXUtilitiesRole.is_feed_article(mock_obj)
1718
1719 mock_ax_utilities_object_class.find_ancestor = test_context.Mock(
1720 return_value=test_context.Mock()
1721 )
1722 assert AXUtilitiesRole.is_feed_article(mock_obj)
1723
1724 @pytest.mark.parametrize(
1725 "case",
1726 [
1727 {
1728 "id": "internal_frame",
1729 "method_name": "is_inline_internal_frame",
1730 "base_method_name": "is_internal_frame",
1731 },
1732 {
1733 "id": "list_item",
1734 "method_name": "is_inline_list_item",
1735 "base_method_name": "is_list_item",
1736 },
1737 {
1738 "id": "suggestion",
1739 "method_name": "is_inline_suggestion",
1740 "base_method_name": "is_suggestion",
1741 },
1742 ],
1743 ids=lambda case: case["id"],
1744 )
1745 def test_is_inline_methods(self, test_context: OrcaTestContext, case: dict) -> None:
1746 """Test is_inline_* methods for base role check and display style."""
1747
1748 self._setup_dependencies(test_context)
1749 from orca.ax_utilities_role import AXUtilitiesRole
1750
1751 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1752 method_to_test = getattr(AXUtilitiesRole, case["method_name"])
1753 test_context.patch_object(AXUtilitiesRole, case["base_method_name"], return_value=False)
1754 assert not method_to_test(mock_obj)
1755
1756 test_context.patch_object(AXUtilitiesRole, case["base_method_name"], return_value=True)
1757 test_context.patch_object(AXUtilitiesRole, "_get_display_style", return_value="block")
1758 assert not method_to_test(mock_obj)
1759
1760 test_context.patch_object(AXUtilitiesRole, "_get_display_style", return_value="inline")
1761 assert method_to_test(mock_obj)
1762
1763 def test_is_list_box_item(self, test_context: OrcaTestContext) -> None:
1764 """Test is_list_box_item for list item and list box ancestor."""
1765
1766 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1767 mock_ax_utilities_object_class = essential_modules[
1768 "orca.ax_utilities_object"
1769 ].AXUtilitiesObject
1770 mock_ax_utilities_object_class.find_ancestor = test_context.Mock(return_value=None)
1771 from orca.ax_utilities_role import AXUtilitiesRole
1772
1773 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1774 test_context.patch_object(AXUtilitiesRole, "is_list_item", return_value=False)
1775 assert not AXUtilitiesRole.is_list_box_item(mock_obj)
1776
1777 test_context.patch_object(AXUtilitiesRole, "is_list_item", return_value=True)
1778 mock_ax_utilities_object_class.find_ancestor = test_context.Mock(return_value=None)
1779 assert not AXUtilitiesRole.is_list_box_item(mock_obj)
1780
1781 mock_ax_utilities_object_class.find_ancestor = test_context.Mock(
1782 return_value=test_context.Mock()
1783 )
1784 assert AXUtilitiesRole.is_list_box_item(mock_obj)
1785
1786 def test_is_math_fraction_without_bar(self, test_context: OrcaTestContext) -> None:
1787 """Test is_math_fraction_without_bar for math fraction and linethickness."""
1788
1789 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1790 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1791 mock_ax_object_class.get_attribute = test_context.Mock(return_value=None)
1792 from orca.ax_utilities_role import AXUtilitiesRole
1793
1794 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1795 test_context.patch_object(AXUtilitiesRole, "is_math_fraction", return_value=False)
1796 assert not AXUtilitiesRole.is_math_fraction_without_bar(mock_obj)
1797
1798 test_context.patch_object(AXUtilitiesRole, "is_math_fraction", return_value=True)
1799 mock_ax_object_class.get_attribute = test_context.Mock(return_value=None)
1800 assert not AXUtilitiesRole.is_math_fraction_without_bar(mock_obj)
1801
1802 mock_ax_object_class.get_attribute = test_context.Mock(return_value="2")
1803 assert not AXUtilitiesRole.is_math_fraction_without_bar(mock_obj)
1804
1805 mock_ax_object_class.get_attribute = test_context.Mock(return_value="00")
1806 assert AXUtilitiesRole.is_math_fraction_without_bar(mock_obj)
1807
1808 def test_is_modal_dialog(self, test_context: OrcaTestContext) -> None:
1809 """Test is_modal_dialog for dialog/alert roles and modal state."""
1810
1811 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1812 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1813 mock_ax_object_class.has_state = test_context.Mock(return_value=False)
1814 from orca.ax_utilities_role import AXUtilitiesRole
1815
1816 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1817 test_context.patch_object(AXUtilitiesRole, "is_dialog_or_alert", return_value=False)
1818 assert not AXUtilitiesRole.is_modal_dialog(mock_obj)
1819
1820 test_context.patch_object(AXUtilitiesRole, "is_dialog_or_alert", return_value=True)
1821 mock_ax_object_class.has_state = test_context.Mock(return_value=False)
1822 assert not AXUtilitiesRole.is_modal_dialog(mock_obj)
1823
1824 mock_ax_object_class.has_state = test_context.Mock(return_value=True)
1825 assert AXUtilitiesRole.is_modal_dialog(mock_obj)
1826
1827 def test_is_multi_line_entry(self, test_context: OrcaTestContext) -> None:
1828 """Test is_multi_line_entry for entry role and multiline state."""
1829
1830 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1831 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1832 mock_ax_object_class.has_state = test_context.Mock(return_value=False)
1833 from orca.ax_utilities_role import AXUtilitiesRole
1834
1835 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1836 test_context.patch_object(AXUtilitiesRole, "is_entry", return_value=False)
1837 assert not AXUtilitiesRole.is_multi_line_entry(mock_obj)
1838
1839 test_context.patch_object(AXUtilitiesRole, "is_entry", return_value=True)
1840 mock_ax_object_class.has_state = test_context.Mock(return_value=False)
1841 assert not AXUtilitiesRole.is_multi_line_entry(mock_obj)
1842
1843 mock_ax_object_class.has_state = test_context.Mock(return_value=True)
1844 assert AXUtilitiesRole.is_multi_line_entry(mock_obj)
1845
1846 def test_is_docked_frame(self, test_context: OrcaTestContext) -> None:
1847 """Test is_docked_frame for frame role and docked attribute."""
1848
1849 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1850 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1851 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1852 from orca.ax_utilities_role import AXUtilitiesRole
1853
1854 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1855 test_context.patch_object(AXUtilitiesRole, "is_frame", return_value=False)
1856 assert not AXUtilitiesRole.is_docked_frame(mock_obj)
1857
1858 test_context.patch_object(AXUtilitiesRole, "is_frame", return_value=True)
1859 mock_ax_object_class.get_attributes_dict = test_context.Mock(
1860 return_value={"window-type": "normal"},
1861 )
1862 assert not AXUtilitiesRole.is_docked_frame(mock_obj)
1863
1864 mock_ax_object_class.get_attributes_dict = test_context.Mock(
1865 return_value={"window-type": "dock"},
1866 )
1867 assert AXUtilitiesRole.is_docked_frame(mock_obj)
1868
1869 def test_is_desktop_frame(self, test_context: OrcaTestContext) -> None:
1870 """Test is_desktop_frame for desktop frame and is-desktop attribute."""
1871
1872 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1873 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1874 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.LABEL)
1875 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1876 from orca.ax_utilities_role import AXUtilitiesRole
1877
1878 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1879 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.DESKTOP_FRAME)
1880 assert AXUtilitiesRole.is_desktop_frame(mock_obj)
1881
1882 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.FRAME)
1883 mock_ax_object_class.get_attributes_dict = test_context.Mock(
1884 return_value={"is-desktop": "true"},
1885 )
1886 assert AXUtilitiesRole.is_desktop_frame(mock_obj)
1887
1888 mock_ax_object_class.get_attributes_dict = test_context.Mock(
1889 return_value={"is-desktop": "false"},
1890 )
1891 assert not AXUtilitiesRole.is_desktop_frame(mock_obj)
1892
1893 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.LABEL)
1894 assert not AXUtilitiesRole.is_desktop_frame(mock_obj)
1895
1896 def test_is_live_region(self, test_context: OrcaTestContext) -> None:
1897 """Test is_live_region for container-live attribute."""
1898
1899 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1900 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
1901 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
1902 from orca.ax_utilities_role import AXUtilitiesRole
1903
1904 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1905 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={"foo": "bar"})
1906 assert not AXUtilitiesRole.is_live_region(mock_obj)
1907
1908 mock_ax_object_class.get_attributes_dict = test_context.Mock(
1909 return_value={"container-live": "polite"},
1910 )
1911 assert AXUtilitiesRole.is_live_region(mock_obj)
1912
1913 @pytest.mark.parametrize(
1914 "case",
1915 [
1916 {
1917 "id": "with_code_xml_role",
1918 "xml_roles": ["code"],
1919 "tag": None,
1920 "expected_result": True,
1921 },
1922 {"id": "with_code_tag", "xml_roles": [], "tag": "code", "expected_result": True},
1923 {"id": "with_pre_tag", "xml_roles": [], "tag": "pre", "expected_result": True},
1924 {
1925 "id": "with_no_code_indicators",
1926 "xml_roles": ["text"],
1927 "tag": "p",
1928 "expected_result": False,
1929 },
1930 ],
1931 ids=lambda case: case["id"],
1932 )
1933 def test_is_code(self, test_context: OrcaTestContext, case: dict) -> None:
1934 """Test AXUtilitiesRole.is_code in various scenarios."""
1935
1936 self._setup_dependencies(test_context)
1937 from orca.ax_utilities_role import AXUtilitiesRole
1938
1939 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1940 test_context.patch_object(
1941 AXUtilitiesRole,
1942 "_get_xml_roles",
1943 side_effect=lambda obj: case["xml_roles"],
1944 )
1945 if case["tag"] is not None:
1946 test_context.patch_object(
1947 AXUtilitiesRole,
1948 "_get_tag",
1949 side_effect=lambda obj: case["tag"],
1950 )
1951
1952 result = AXUtilitiesRole.is_code(mock_obj)
1953 assert result == case["expected_result"]
1954
1955 @pytest.mark.parametrize(
1956 "case",
1957 [
1958 {
1959 "id": "push_button_with_popup",
1960 "role": Atspi.Role.BUTTON,
1961 "has_popup": True,
1962 "expected": True,
1963 },
1964 {
1965 "id": "push_button_without_popup",
1966 "role": Atspi.Role.BUTTON,
1967 "has_popup": False,
1968 "expected": False,
1969 },
1970 {
1971 "id": "label_with_popup",
1972 "role": Atspi.Role.LABEL,
1973 "has_popup": True,
1974 "expected": False,
1975 },
1976 ],
1977 ids=lambda case: case["id"],
1978 )
1979 def test_is_button_with_popup(self, test_context: OrcaTestContext, case: dict) -> None:
1980 """Test AXUtilitiesRole.is_button_with_popup with various combinations."""
1981
1982 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
1983 ax_object_mock = essential_modules["orca.ax_object"].AXObject
1984 ax_utilities_state_mock = essential_modules["orca.ax_utilities_state"].AXUtilitiesState
1985 from orca.ax_utilities_role import AXUtilitiesRole
1986
1987 mock_obj = test_context.Mock(spec=Atspi.Accessible)
1988 ax_object_mock.get_role.return_value = case["role"]
1989 ax_utilities_state_mock.has_popup.return_value = case["has_popup"]
1990
1991 result = AXUtilitiesRole.is_button_with_popup(mock_obj)
1992 assert result is case["expected"]
1993
1994 def test_is_landmark_without_type(self, test_context: OrcaTestContext) -> None:
1995 """Test AXUtilitiesRole.is_landmark_without_type."""
1996
1997 self._setup_dependencies(test_context)
1998 from orca.ax_utilities_role import AXUtilitiesRole
1999
2000 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2001 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=False)
2002 assert not AXUtilitiesRole.is_landmark_without_type(mock_obj)
2003
2004 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=True)
2005 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=[])
2006 assert AXUtilitiesRole.is_landmark_without_type(mock_obj)
2007
2008 test_context.patch_object(AXUtilitiesRole, "is_landmark", return_value=True)
2009 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=["navigation"])
2010 assert not AXUtilitiesRole.is_landmark_without_type(mock_obj)
2011
2012 @pytest.mark.parametrize(
2013 "case",
2014 [
2015 {
2016 "id": "dialog_roles",
2017 "method_name": "get_dialog_roles",
2018 "expected_roles": [
2019 Atspi.Role.COLOR_CHOOSER,
2020 Atspi.Role.DIALOG,
2021 Atspi.Role.FILE_CHOOSER,
2022 Atspi.Role.ALERT,
2023 ],
2024 "test_params": [{}, {"include_alert_as_dialog": False}],
2025 },
2026 {
2027 "id": "document_roles",
2028 "method_name": "get_document_roles",
2029 "expected_roles": [
2030 Atspi.Role.DOCUMENT_EMAIL,
2031 Atspi.Role.DOCUMENT_FRAME,
2032 Atspi.Role.DOCUMENT_PRESENTATION,
2033 Atspi.Role.DOCUMENT_SPREADSHEET,
2034 Atspi.Role.DOCUMENT_TEXT,
2035 Atspi.Role.DOCUMENT_WEB,
2036 ],
2037 "test_params": [{}],
2038 },
2039 {
2040 "id": "form_field_roles",
2041 "method_name": "get_form_field_roles",
2042 "expected_roles": [
2043 Atspi.Role.BUTTON,
2044 Atspi.Role.CHECK_BOX,
2045 Atspi.Role.RADIO_BUTTON,
2046 Atspi.Role.COMBO_BOX,
2047 Atspi.Role.DOCUMENT_FRAME,
2048 Atspi.Role.TEXT,
2049 Atspi.Role.LIST_BOX,
2050 Atspi.Role.ENTRY,
2051 Atspi.Role.PASSWORD_TEXT,
2052 Atspi.Role.SPIN_BUTTON,
2053 Atspi.Role.TOGGLE_BUTTON,
2054 ],
2055 "test_params": [{}],
2056 },
2057 ],
2058 ids=lambda case: case["id"],
2059 )
2060 def test_get_role_collections(self, test_context: OrcaTestContext, case: dict) -> None:
2061 """Test AXUtilitiesRole get_*_roles methods."""
2062
2063 self._setup_dependencies(test_context)
2064 from orca.ax_utilities_role import AXUtilitiesRole
2065
2066 method_to_test = getattr(AXUtilitiesRole, case["method_name"])
2067
2068 for params in case["test_params"]:
2069 roles = method_to_test(**params)
2070 if case["method_name"] == "get_dialog_roles" and "include_alert_as_dialog" in params:
2071 expected = [r for r in case["expected_roles"] if r != Atspi.Role.ALERT]
2072 assert roles == expected
2073 else:
2074 assert roles == case["expected_roles"]
2075
2076 def test_get_menu_item_roles(self, test_context: OrcaTestContext) -> None:
2077 """Test AXUtilitiesRole.get_menu_item_roles."""
2078
2079 self._setup_dependencies(test_context)
2080 from orca.ax_utilities_role import AXUtilitiesRole
2081
2082 roles = AXUtilitiesRole.get_menu_item_roles()
2083 expected = [
2084 Atspi.Role.MENU_ITEM,
2085 Atspi.Role.CHECK_MENU_ITEM,
2086 Atspi.Role.RADIO_MENU_ITEM,
2087 Atspi.Role.TEAROFF_MENU_ITEM,
2088 ]
2089 assert roles == expected
2090
2091 def test_get_menu_related_roles(self, test_context: OrcaTestContext) -> None:
2092 """Test AXUtilitiesRole.get_menu_related_roles."""
2093
2094 self._setup_dependencies(test_context)
2095 from orca.ax_utilities_role import AXUtilitiesRole
2096
2097 roles = AXUtilitiesRole.get_menu_related_roles()
2098 expected = [
2099 Atspi.Role.MENU,
2100 Atspi.Role.MENU_BAR,
2101 Atspi.Role.POPUP_MENU,
2102 Atspi.Role.MENU_ITEM,
2103 Atspi.Role.CHECK_MENU_ITEM,
2104 Atspi.Role.RADIO_MENU_ITEM,
2105 Atspi.Role.TEAROFF_MENU_ITEM,
2106 ]
2107 assert roles == expected
2108
2109 @pytest.mark.parametrize(
2110 "case",
2111 [
2112 {
2113 "id": "table_cell_roles",
2114 "method_name": "get_table_cell_roles",
2115 "expected_roles": [
2116 Atspi.Role.TABLE_CELL,
2117 Atspi.Role.TABLE_COLUMN_HEADER,
2118 Atspi.Role.TABLE_ROW_HEADER,
2119 Atspi.Role.COLUMN_HEADER,
2120 Atspi.Role.ROW_HEADER,
2121 ],
2122 "test_params": [{}, {"include_headers": False}],
2123 },
2124 {
2125 "id": "table_header_roles",
2126 "method_name": "get_table_header_roles",
2127 "expected_roles": [
2128 Atspi.Role.TABLE_COLUMN_HEADER,
2129 Atspi.Role.TABLE_ROW_HEADER,
2130 Atspi.Role.COLUMN_HEADER,
2131 Atspi.Role.ROW_HEADER,
2132 ],
2133 "test_params": [{}],
2134 },
2135 ],
2136 ids=lambda case: case["id"],
2137 )
2138 def test_get_table_role_collections(self, test_context: OrcaTestContext, case: dict) -> None:
2139 """Test AXUtilitiesRole get_table_*_roles methods."""
2140
2141 self._setup_dependencies(test_context)
2142 from orca.ax_utilities_role import AXUtilitiesRole
2143
2144 method_to_test = getattr(AXUtilitiesRole, case["method_name"])
2145
2146 for params in case["test_params"]:
2147 roles = method_to_test(**params)
2148 if case["method_name"] == "get_table_cell_roles" and "include_headers" in params:
2149 expected = [Atspi.Role.TABLE_CELL]
2150 assert roles == expected
2151 else:
2152 assert roles == case["expected_roles"]
2153
2154 def test_get_table_related_roles(self, test_context: OrcaTestContext) -> None:
2155 """Test AXUtilitiesRole.get_table_related_roles."""
2156
2157 self._setup_dependencies(test_context)
2158 from orca.ax_utilities_role import AXUtilitiesRole
2159
2160 roles = AXUtilitiesRole.get_table_related_roles()
2161 expected = [
2162 Atspi.Role.TABLE,
2163 Atspi.Role.TABLE_CELL,
2164 Atspi.Role.TABLE_COLUMN_HEADER,
2165 Atspi.Role.TABLE_ROW_HEADER,
2166 Atspi.Role.COLUMN_HEADER,
2167 Atspi.Role.ROW_HEADER,
2168 ]
2169 assert roles == expected
2170
2171 roles = AXUtilitiesRole.get_table_related_roles(include_caption=True)
2172 expected = [
2173 Atspi.Role.TABLE,
2174 Atspi.Role.TABLE_CELL,
2175 Atspi.Role.TABLE_COLUMN_HEADER,
2176 Atspi.Role.TABLE_ROW_HEADER,
2177 Atspi.Role.COLUMN_HEADER,
2178 Atspi.Role.ROW_HEADER,
2179 Atspi.Role.CAPTION,
2180 ]
2181 assert roles == expected
2182
2183 def test_have_same_role(self, test_context: OrcaTestContext) -> None:
2184 """Test AXUtilitiesRole.have_same_role."""
2185
2186 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
2187 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
2188 from orca.ax_utilities_role import AXUtilitiesRole
2189
2190 mock_obj1 = test_context.Mock(spec=Atspi.Accessible)
2191 mock_obj2 = test_context.Mock(spec=Atspi.Accessible)
2192 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.BUTTON)
2193 assert AXUtilitiesRole.have_same_role(mock_obj1, mock_obj2)
2194
2195 def mock_get_role(obj):
2196 if obj == mock_obj1:
2197 return Atspi.Role.BUTTON
2198 return Atspi.Role.LABEL
2199
2200 mock_ax_object_class.get_role = mock_get_role
2201 assert not AXUtilitiesRole.have_same_role(mock_obj1, mock_obj2)
2202
2203 def test_has_role_from_aria(self, test_context: OrcaTestContext) -> None:
2204 """Test AXUtilitiesRole.has_role_from_aria."""
2205
2206 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
2207 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
2208 from orca.ax_utilities_role import AXUtilitiesRole
2209
2210 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2211 mock_ax_object_class.get_attributes_dict = test_context.Mock(
2212 return_value={"xml-roles": "button"},
2213 )
2214 assert AXUtilitiesRole.has_role_from_aria(mock_obj)
2215
2216 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={})
2217 assert not AXUtilitiesRole.has_role_from_aria(mock_obj)
2218
2219 mock_ax_object_class.get_attributes_dict = test_context.Mock(return_value={"xml-roles": ""})
2220 assert not AXUtilitiesRole.has_role_from_aria(mock_obj)
2221
2222 def test_is_aria_alert(self, test_context: OrcaTestContext) -> None:
2223 """Test AXUtilitiesRole.is_aria_alert."""
2224
2225 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
2226 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
2227 from orca.ax_utilities_role import AXUtilitiesRole
2228
2229 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2230 mock_ax_object_class.get_attributes_dict = test_context.Mock(
2231 return_value={"xml-roles": "button"},
2232 )
2233 assert not AXUtilitiesRole.is_aria_alert(mock_obj)
2234
2235 mock_ax_object_class.get_attributes_dict = test_context.Mock(
2236 return_value={"xml-roles": "alert"},
2237 )
2238 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.NOTIFICATION)
2239 assert AXUtilitiesRole.is_aria_alert(mock_obj)
2240
2241 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.ALERT)
2242 assert AXUtilitiesRole.is_aria_alert(mock_obj)
2243
2244 def test_is_autocomplete(self, test_context: OrcaTestContext) -> None:
2245 """Test AXUtilitiesRole.is_autocomplete."""
2246
2247 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
2248 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
2249 from orca.ax_utilities_role import AXUtilitiesRole
2250
2251 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2252 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.AUTOCOMPLETE)
2253 assert AXUtilitiesRole.is_autocomplete(mock_obj)
2254
2255 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.BUTTON)
2256 assert not AXUtilitiesRole.is_autocomplete(mock_obj)
2257 assert AXUtilitiesRole.is_autocomplete(mock_obj, Atspi.Role.AUTOCOMPLETE)
2258 assert not AXUtilitiesRole.is_autocomplete(mock_obj, Atspi.Role.BUTTON)
2259
2260 def test_is_default_button(self, test_context: OrcaTestContext) -> None:
2261 """Test AXUtilitiesRole.is_default_button."""
2262
2263 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
2264 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
2265 mock_ax_object_class.has_state = test_context.Mock(return_value=False)
2266 from orca.ax_utilities_role import AXUtilitiesRole
2267
2268 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2269 test_context.patch_object(AXUtilitiesRole, "is_push_button", return_value=False)
2270 assert not AXUtilitiesRole.is_default_button(mock_obj)
2271
2272 test_context.patch_object(AXUtilitiesRole, "is_push_button", return_value=True)
2273 mock_ax_object_class.has_state = test_context.Mock(return_value=False)
2274 assert not AXUtilitiesRole.is_default_button(mock_obj)
2275
2276 test_context.patch_object(AXUtilitiesRole, "is_push_button", return_value=True)
2277 mock_ax_object_class.has_state = test_context.Mock(return_value=True)
2278 assert AXUtilitiesRole.is_default_button(mock_obj)
2279
2280 def test_is_single_line_autocomplete_entry(self, test_context: OrcaTestContext) -> None:
2281 """Test AXUtilitiesRole.is_single_line_autocomplete_entry."""
2282
2283 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
2284 mock_ax_utilities_state_class = essential_modules[
2285 "orca.ax_utilities_state"
2286 ].AXUtilitiesState
2287 from orca.ax_utilities_role import AXUtilitiesRole
2288
2289 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2290 test_context.patch_object(AXUtilitiesRole, "is_single_line_entry", return_value=False)
2291 assert not AXUtilitiesRole.is_single_line_autocomplete_entry(mock_obj)
2292
2293 test_context.patch_object(AXUtilitiesRole, "is_single_line_entry", return_value=True)
2294 mock_ax_utilities_state_class.supports_autocompletion = test_context.Mock(
2295 return_value=False,
2296 )
2297 assert not AXUtilitiesRole.is_single_line_autocomplete_entry(mock_obj)
2298
2299 test_context.patch_object(AXUtilitiesRole, "is_single_line_entry", return_value=True)
2300 mock_ax_utilities_state_class.supports_autocompletion = test_context.Mock(return_value=True)
2301 assert AXUtilitiesRole.is_single_line_autocomplete_entry(mock_obj)
2302
2303 def test_is_single_line_entry(self, test_context: OrcaTestContext) -> None:
2304 """Test AXUtilitiesRole.is_single_line_entry."""
2305
2306 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
2307 mock_ax_utilities_state_class = essential_modules[
2308 "orca.ax_utilities_state"
2309 ].AXUtilitiesState
2310 from orca.ax_utilities_role import AXUtilitiesRole
2311
2312 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2313 mock_ax_utilities_state_class.is_single_line = test_context.Mock(return_value=False)
2314 assert not AXUtilitiesRole.is_single_line_entry(mock_obj)
2315
2316 mock_ax_utilities_state_class.is_single_line = test_context.Mock(return_value=True)
2317 test_context.patch_object(AXUtilitiesRole, "is_entry", return_value=True)
2318 assert AXUtilitiesRole.is_single_line_entry(mock_obj)
2319
2320 mock_ax_utilities_state_class.is_single_line = test_context.Mock(return_value=True)
2321 test_context.patch_object(AXUtilitiesRole, "is_entry", return_value=False)
2322 test_context.patch_object(AXUtilitiesRole, "is_text", return_value=True)
2323 mock_ax_utilities_state_class.is_editable = test_context.Mock(return_value=True)
2324 assert AXUtilitiesRole.is_single_line_entry(mock_obj)
2325
2326 mock_ax_utilities_state_class.is_editable = test_context.Mock(return_value=False)
2327 assert not AXUtilitiesRole.is_single_line_entry(mock_obj)
2328
2329 def test_is_dialog_or_alert(self, test_context: OrcaTestContext) -> None:
2330 """Test AXUtilitiesRole.is_dialog_or_alert."""
2331
2332 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
2333 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
2334 from orca.ax_utilities_role import AXUtilitiesRole
2335
2336 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2337 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.DIALOG)
2338 assert AXUtilitiesRole.is_dialog_or_alert(mock_obj)
2339
2340 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.ALERT)
2341 assert AXUtilitiesRole.is_dialog_or_alert(mock_obj)
2342
2343 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.COLOR_CHOOSER)
2344 assert AXUtilitiesRole.is_dialog_or_alert(mock_obj)
2345
2346 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.FILE_CHOOSER)
2347 assert AXUtilitiesRole.is_dialog_or_alert(mock_obj)
2348
2349 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.BUTTON)
2350 assert not AXUtilitiesRole.is_dialog_or_alert(mock_obj)
2351
2352 def test_is_dialog_or_window(self, test_context: OrcaTestContext) -> None:
2353 """Test AXUtilitiesRole.is_dialog_or_window."""
2354
2355 essential_modules: dict[str, MagicMock] = self._setup_dependencies(test_context)
2356 mock_ax_object_class = essential_modules["orca.ax_object"].AXObject
2357 from orca.ax_utilities_role import AXUtilitiesRole
2358
2359 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2360 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.DIALOG)
2361 assert AXUtilitiesRole.is_dialog_or_window(mock_obj)
2362
2363 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.FRAME)
2364 assert AXUtilitiesRole.is_dialog_or_window(mock_obj)
2365
2366 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.WINDOW)
2367 assert AXUtilitiesRole.is_dialog_or_window(mock_obj)
2368
2369 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.COLOR_CHOOSER)
2370 assert AXUtilitiesRole.is_dialog_or_window(mock_obj)
2371
2372 mock_ax_object_class.get_role = test_context.Mock(return_value=Atspi.Role.BUTTON)
2373 assert not AXUtilitiesRole.is_dialog_or_window(mock_obj)
2374
2375 def test_get_widget_roles(self, test_context: OrcaTestContext) -> None:
2376 """Test AXUtilitiesRole.get_widget_roles."""
2377
2378 self._setup_dependencies(test_context)
2379 from orca.ax_utilities_role import AXUtilitiesRole
2380
2381 roles = AXUtilitiesRole.get_widget_roles()
2382 assert len(roles) > 10
2383 assert Atspi.Role.BUTTON in roles
2384 assert Atspi.Role.CHECK_BOX in roles
2385 assert Atspi.Role.ENTRY in roles
2386 assert Atspi.Role.COMBO_BOX in roles
2387
2388 def test_get_text_ui_roles(self, test_context: OrcaTestContext) -> None:
2389 """Test AXUtilitiesRole.get_text_ui_roles."""
2390
2391 self._setup_dependencies(test_context)
2392 from orca.ax_utilities_role import AXUtilitiesRole
2393
2394 roles = AXUtilitiesRole.get_text_ui_roles()
2395 expected = [
2396 Atspi.Role.INFO_BAR,
2397 Atspi.Role.LABEL,
2398 Atspi.Role.PAGE_TAB,
2399 Atspi.Role.STATUS_BAR,
2400 ]
2401 assert roles == expected
2402
2403 def test_get_tree_related_roles(self, test_context: OrcaTestContext) -> None:
2404 """Test AXUtilitiesRole.get_tree_related_roles."""
2405
2406 self._setup_dependencies(test_context)
2407 from orca.ax_utilities_role import AXUtilitiesRole
2408
2409 roles = AXUtilitiesRole.get_tree_related_roles()
2410 expected = [Atspi.Role.TREE, Atspi.Role.TREE_ITEM, Atspi.Role.TREE_TABLE]
2411 assert roles == expected
2412
2413 def test_get_set_container_roles(self, test_context: OrcaTestContext) -> None:
2414 """Test AXUtilitiesRole.get_set_container_roles."""
2415
2416 self._setup_dependencies(test_context)
2417 from orca.ax_utilities_role import AXUtilitiesRole
2418
2419 roles = AXUtilitiesRole.get_set_container_roles()
2420 expected = [
2421 Atspi.Role.LIST,
2422 Atspi.Role.MENU,
2423 Atspi.Role.PAGE_TAB_LIST,
2424 Atspi.Role.TABLE,
2425 Atspi.Role.TREE,
2426 Atspi.Role.TREE_TABLE,
2427 ]
2428 assert roles == expected
2429
2430 def test_get_layout_only_roles(self, test_context: OrcaTestContext) -> None:
2431 """Test AXUtilitiesRole.get_layout_only_roles."""
2432
2433 self._setup_dependencies(test_context)
2434 from orca.ax_utilities_role import AXUtilitiesRole
2435
2436 roles = AXUtilitiesRole.get_layout_only_roles()
2437 expected = [
2438 Atspi.Role.AUTOCOMPLETE,
2439 Atspi.Role.FILLER,
2440 Atspi.Role.REDUNDANT_OBJECT,
2441 Atspi.Role.UNKNOWN,
2442 Atspi.Role.SCROLL_PANE,
2443 Atspi.Role.TEAROFF_MENU_ITEM,
2444 ]
2445 assert roles == expected
2446
2447 def test_get_large_container_roles(self, test_context: OrcaTestContext) -> None:
2448 """Test AXUtilitiesRole.get_large_container_roles."""
2449
2450 self._setup_dependencies(test_context)
2451 from orca.ax_utilities_role import AXUtilitiesRole
2452
2453 roles = AXUtilitiesRole.get_large_container_roles()
2454 expected = [
2455 Atspi.Role.ARTICLE,
2456 Atspi.Role.BLOCK_QUOTE,
2457 Atspi.Role.DESCRIPTION_LIST,
2458 Atspi.Role.FORM,
2459 Atspi.Role.FOOTER,
2460 Atspi.Role.GROUPING,
2461 Atspi.Role.HEADER,
2462 Atspi.Role.HTML_CONTAINER,
2463 Atspi.Role.LANDMARK,
2464 Atspi.Role.LOG,
2465 Atspi.Role.LIST,
2466 Atspi.Role.MARQUEE,
2467 Atspi.Role.PANEL,
2468 Atspi.Role.TABLE,
2469 Atspi.Role.TREE,
2470 Atspi.Role.TREE_TABLE,
2471 ]
2472 assert roles == expected
2473
2474 def test_get_roles_to_exclude_from_clickables_list(self, test_context: OrcaTestContext) -> None:
2475 """Test AXUtilitiesRole.get_roles_to_exclude_from_clickables_list."""
2476
2477 self._setup_dependencies(test_context)
2478 from orca.ax_utilities_role import AXUtilitiesRole
2479
2480 roles = AXUtilitiesRole.get_roles_to_exclude_from_clickables_list()
2481 expected = [
2482 Atspi.Role.COMBO_BOX,
2483 Atspi.Role.ENTRY,
2484 Atspi.Role.LIST_BOX,
2485 Atspi.Role.MENU,
2486 Atspi.Role.MENU_ITEM,
2487 Atspi.Role.CHECK_MENU_ITEM,
2488 Atspi.Role.RADIO_MENU_ITEM,
2489 Atspi.Role.PAGE_TAB,
2490 Atspi.Role.PAGE_TAB_LIST,
2491 Atspi.Role.PASSWORD_TEXT,
2492 Atspi.Role.PROGRESS_BAR,
2493 Atspi.Role.SLIDER,
2494 Atspi.Role.SPIN_BUTTON,
2495 Atspi.Role.TOOL_BAR,
2496 Atspi.Role.TREE_ITEM,
2497 Atspi.Role.TREE_TABLE,
2498 Atspi.Role.TREE,
2499 ]
2500 assert roles == expected
2501
2502 def test_is_dpub(self, test_context: OrcaTestContext) -> None:
2503 """Test AXUtilitiesRole.is_dpub."""
2504
2505 self._setup_dependencies(test_context)
2506 from orca.ax_utilities_role import AXUtilitiesRole
2507
2508 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2509 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=["doc-abstract"])
2510 assert AXUtilitiesRole.is_dpub(mock_obj)
2511
2512 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=["button"])
2513 assert not AXUtilitiesRole.is_dpub(mock_obj)
2514
2515 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=[])
2516 assert not AXUtilitiesRole.is_dpub(mock_obj)
2517
2518 @pytest.mark.parametrize(
2519 "case",
2520 [
2521 {
2522 "id": "dpub_abstract",
2523 "method_name": "is_dpub_abstract",
2524 "expected_xml_role": "doc-abstract",
2525 },
2526 {
2527 "id": "dpub_acknowledgments",
2528 "method_name": "is_dpub_acknowledgments",
2529 "expected_xml_role": "doc-acknowledgments",
2530 },
2531 {
2532 "id": "dpub_afterword",
2533 "method_name": "is_dpub_afterword",
2534 "expected_xml_role": "doc-afterword",
2535 },
2536 {
2537 "id": "dpub_appendix",
2538 "method_name": "is_dpub_appendix",
2539 "expected_xml_role": "doc-appendix",
2540 },
2541 {
2542 "id": "dpub_backlink",
2543 "method_name": "is_dpub_backlink",
2544 "expected_xml_role": "doc-backlink",
2545 },
2546 {
2547 "id": "dpub_biblioref",
2548 "method_name": "is_dpub_biblioref",
2549 "expected_xml_role": "doc-biblioref",
2550 },
2551 {
2552 "id": "dpub_bibliography",
2553 "method_name": "is_dpub_bibliography",
2554 "expected_xml_role": "doc-bibliography",
2555 },
2556 {
2557 "id": "dpub_chapter",
2558 "method_name": "is_dpub_chapter",
2559 "expected_xml_role": "doc-chapter",
2560 },
2561 {
2562 "id": "dpub_colophon",
2563 "method_name": "is_dpub_colophon",
2564 "expected_xml_role": "doc-colophon",
2565 },
2566 {
2567 "id": "dpub_conclusion",
2568 "method_name": "is_dpub_conclusion",
2569 "expected_xml_role": "doc-conclusion",
2570 },
2571 {"id": "dpub_cover", "method_name": "is_dpub_cover", "expected_xml_role": "doc-cover"},
2572 {
2573 "id": "dpub_credit",
2574 "method_name": "is_dpub_credit",
2575 "expected_xml_role": "doc-credit",
2576 },
2577 {
2578 "id": "dpub_credits",
2579 "method_name": "is_dpub_credits",
2580 "expected_xml_role": "doc-credits",
2581 },
2582 {
2583 "id": "dpub_dedication",
2584 "method_name": "is_dpub_dedication",
2585 "expected_xml_role": "doc-dedication",
2586 },
2587 {
2588 "id": "dpub_endnote",
2589 "method_name": "is_dpub_endnote",
2590 "expected_xml_role": "doc-endnote",
2591 },
2592 {
2593 "id": "dpub_endnotes",
2594 "method_name": "is_dpub_endnotes",
2595 "expected_xml_role": "doc-endnotes",
2596 },
2597 {
2598 "id": "dpub_epigraph",
2599 "method_name": "is_dpub_epigraph",
2600 "expected_xml_role": "doc-epigraph",
2601 },
2602 {
2603 "id": "dpub_epilogue",
2604 "method_name": "is_dpub_epilogue",
2605 "expected_xml_role": "doc-epilogue",
2606 },
2607 {
2608 "id": "dpub_errata",
2609 "method_name": "is_dpub_errata",
2610 "expected_xml_role": "doc-errata",
2611 },
2612 {
2613 "id": "dpub_example",
2614 "method_name": "is_dpub_example",
2615 "expected_xml_role": "doc-example",
2616 },
2617 {
2618 "id": "dpub_footnote",
2619 "method_name": "is_dpub_footnote",
2620 "expected_xml_role": "doc-footnote",
2621 },
2622 {
2623 "id": "dpub_foreword",
2624 "method_name": "is_dpub_foreword",
2625 "expected_xml_role": "doc-foreword",
2626 },
2627 {
2628 "id": "dpub_glossary",
2629 "method_name": "is_dpub_glossary",
2630 "expected_xml_role": "doc-glossary",
2631 },
2632 {
2633 "id": "dpub_glossref",
2634 "method_name": "is_dpub_glossref",
2635 "expected_xml_role": "doc-glossref",
2636 },
2637 {"id": "dpub_index", "method_name": "is_dpub_index", "expected_xml_role": "doc-index"},
2638 {
2639 "id": "dpub_introduction",
2640 "method_name": "is_dpub_introduction",
2641 "expected_xml_role": "doc-introduction",
2642 },
2643 {
2644 "id": "dpub_noteref",
2645 "method_name": "is_dpub_noteref",
2646 "expected_xml_role": "doc-noteref",
2647 },
2648 {
2649 "id": "dpub_pagelist",
2650 "method_name": "is_dpub_pagelist",
2651 "expected_xml_role": "doc-pagelist",
2652 },
2653 {
2654 "id": "dpub_pagebreak",
2655 "method_name": "is_dpub_pagebreak",
2656 "expected_xml_role": "doc-pagebreak",
2657 },
2658 {"id": "dpub_part", "method_name": "is_dpub_part", "expected_xml_role": "doc-part"},
2659 {
2660 "id": "dpub_preface",
2661 "method_name": "is_dpub_preface",
2662 "expected_xml_role": "doc-preface",
2663 },
2664 {
2665 "id": "dpub_prologue",
2666 "method_name": "is_dpub_prologue",
2667 "expected_xml_role": "doc-prologue",
2668 },
2669 {
2670 "id": "dpub_pullquote",
2671 "method_name": "is_dpub_pullquote",
2672 "expected_xml_role": "doc-pullquote",
2673 },
2674 {"id": "dpub_qna", "method_name": "is_dpub_qna", "expected_xml_role": "doc-qna"},
2675 {
2676 "id": "dpub_subtitle",
2677 "method_name": "is_dpub_subtitle",
2678 "expected_xml_role": "doc-subtitle",
2679 },
2680 {"id": "dpub_toc", "method_name": "is_dpub_toc", "expected_xml_role": "doc-toc"},
2681 ],
2682 ids=lambda case: case["id"],
2683 )
2684 def test_dpub_methods(self, test_context, case: dict) -> None:
2685 """Test AXUtilitiesRole DPUB methods."""
2686
2687 self._setup_dependencies(test_context)
2688 from orca.ax_utilities_role import AXUtilitiesRole
2689
2690 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2691 method = getattr(AXUtilitiesRole, case["method_name"])
2692 test_context.patch_object(
2693 AXUtilitiesRole,
2694 "_get_xml_roles",
2695 side_effect=lambda obj: [case["expected_xml_role"]],
2696 )
2697 assert method(mock_obj)
2698
2699 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=["doc-other"])
2700 assert not method(mock_obj)
2701
2702 test_context.patch_object(AXUtilitiesRole, "_get_xml_roles", return_value=[])
2703 assert not method(mock_obj)
2704
2705 def test_get_display_style(self, test_context: OrcaTestContext) -> None:
2706 """Test AXUtilitiesRole._get_display_style method."""
2707
2708 self._setup_dependencies(test_context)
2709 from orca import ax_utilities_role
2710 from orca.ax_utilities_role import AXUtilitiesRole
2711
2712 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2713 test_context.patch_object(
2714 ax_utilities_role.AXObject,
2715 "get_attributes_dict",
2716 return_value={"display": "inline"},
2717 )
2718 result = AXUtilitiesRole._get_display_style(mock_obj) # pylint: disable=protected-access
2719 assert result == "inline"
2720
2721 def test_get_display_style_missing(self, test_context: OrcaTestContext) -> None:
2722 """Test AXUtilitiesRole._get_display_style when display attribute is missing."""
2723
2724 self._setup_dependencies(test_context)
2725 from orca import ax_utilities_role
2726 from orca.ax_utilities_role import AXUtilitiesRole
2727
2728 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2729 test_context.patch_object(
2730 ax_utilities_role.AXObject,
2731 "get_attributes_dict",
2732 return_value={},
2733 )
2734 result = AXUtilitiesRole._get_display_style(mock_obj) # pylint: disable=protected-access
2735 assert result == ""
2736
2737 def test_get_tag(self, test_context: OrcaTestContext) -> None:
2738 """Test AXUtilitiesRole._get_tag method."""
2739
2740 self._setup_dependencies(test_context)
2741 from orca import ax_utilities_role
2742 from orca.ax_utilities_role import AXUtilitiesRole
2743
2744 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2745 test_context.patch_object(
2746 ax_utilities_role.AXObject,
2747 "get_attributes_dict",
2748 return_value={"tag": "button"},
2749 )
2750 result = AXUtilitiesRole._get_tag(mock_obj) # pylint: disable=protected-access
2751 assert result == "button"
2752
2753 def test_get_tag_missing(self, test_context: OrcaTestContext) -> None:
2754 """Test AXUtilitiesRole._get_tag when tag attribute is missing."""
2755
2756 self._setup_dependencies(test_context)
2757 from orca import ax_utilities_role
2758 from orca.ax_utilities_role import AXUtilitiesRole
2759
2760 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2761 test_context.patch_object(
2762 ax_utilities_role.AXObject,
2763 "get_attributes_dict",
2764 return_value={},
2765 )
2766 result = AXUtilitiesRole._get_tag(mock_obj) # pylint: disable=protected-access
2767 assert result is None
2768
2769 def test_get_xml_roles(self, test_context: OrcaTestContext) -> None:
2770 """Test AXUtilitiesRole._get_xml_roles method."""
2771
2772 self._setup_dependencies(test_context)
2773 from orca import ax_utilities_role
2774 from orca.ax_utilities_role import AXUtilitiesRole
2775
2776 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2777 test_context.patch_object(
2778 ax_utilities_role.AXObject,
2779 "get_attributes_dict",
2780 return_value={"xml-roles": "doc-part doc-chapter"},
2781 )
2782 result = AXUtilitiesRole._get_xml_roles(mock_obj) # pylint: disable=protected-access
2783 assert result == ["doc-part", "doc-chapter"]
2784
2785 def test_get_xml_roles_empty(self, test_context: OrcaTestContext) -> None:
2786 """Test AXUtilitiesRole._get_xml_roles when xml-roles is empty."""
2787
2788 self._setup_dependencies(test_context)
2789 from orca import ax_utilities_role
2790 from orca.ax_utilities_role import AXUtilitiesRole
2791
2792 mock_obj = test_context.Mock(spec=Atspi.Accessible)
2793 test_context.patch_object(
2794 ax_utilities_role.AXObject,
2795 "get_attributes_dict",
2796 return_value={"xml-roles": ""},
2797 )
2798 result = AXUtilitiesRole._get_xml_roles(mock_obj) # pylint: disable=protected-access
2799 assert result == []