import os import sys import unittest from pathlib import Path from unittest import mock import gi os.environ.setdefault("GSETTINGS_BACKEND", "memory") gi.require_version("Atspi", "2.0") sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) from cthulhu import messages from cthulhu import structural_navigation class StructuralNavigationTableRegressionTests(unittest.TestCase): def test_table_cell_coordinates_do_not_interrupt_cell_contents(self): navigator = structural_navigation.StructuralNavigation.__new__( structural_navigation.StructuralNavigation ) navigator._script = mock.Mock() navigator._script.utilities.rowAndColumnSpan.return_value = (1, 1) navigator._getCaretPosition = mock.Mock(return_value=("cell", 0)) navigator._setCaretPosition = mock.Mock(return_value=("cell", 0)) navigator._isBlankCell = mock.Mock(return_value=False) navigator._presentObject = mock.Mock() navigator.getCellCoordinates = mock.Mock(return_value=(1, 2)) with ( mock.patch.object(structural_navigation.settings, "speakCellHeaders", False), mock.patch.object(structural_navigation.settings, "speakCellCoordinates", True), mock.patch.object(structural_navigation.settings, "speakCellSpan", False), ): navigator._tableCellPresentation("cell", None) navigator._presentObject.assert_called_once_with("cell", 0) navigator._script.presentMessage.assert_called_once_with( messages.TABLE_CELL_COORDINATES % {"row": 2, "column": 3}, interrupt=False, ) def test_wrapping_announcement_does_not_interrupt_wrapped_object(self): navigator = structural_navigation.StructuralNavigation.__new__( structural_navigation.StructuralNavigation ) script = mock.Mock() script.utilities.isZombie.return_value = False script.utilities.isHidden.return_value = False script.utilities.isEmpty.return_value = False script.utilities.pathComparison.return_value = 0 navigator._script = script first = object() current = object() structuralNavigationObject = mock.Mock() structuralNavigationObject.predicate = None events = [] structuralNavigationObject.present.side_effect = lambda obj, arg=None: events.append( ("present", obj, arg) ) script.presentMessage.side_effect = lambda message, **kwargs: events.append( ("message", message, kwargs) ) navigator._getAll = mock.Mock(return_value=[first, current]) with ( mock.patch.object(structural_navigation.settings, "wrappedStructuralNavigation", True), mock.patch.object(structural_navigation.AXObject, "is_dead", return_value=False), mock.patch.object(structural_navigation.AXObject, "get_parent", return_value=None), mock.patch.object(structural_navigation.AXObject, "get_path", side_effect=lambda obj: [id(obj)]), ): navigator.goObject(structuralNavigationObject, True, current, "arg") self.assertEqual( events, [ ("present", first, "arg"), ("message", messages.WRAPPING_TO_TOP, {"interrupt": False}), ], ) if __name__ == "__main__": unittest.main()