File size: 1,788 Bytes
03c1ae9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""The AT-SPI guard must actually skip when there is no typelib.

Same bug, one layer down from the OCR guard: `make_detector("atspi")` correctly
raises without PyGObject, so two tests failed on a machine that has no AT-SPI
reader - and a failing test reads like a harness defect rather than a missing
system package. The guard now asks the backend that needs the typelib, and here
is the proof that it skips, passes, and asks for the right thing.
"""

import pytest

from conftest import require_atspi

import tiny_computer_agent.accessibility as accessibility


def test_the_guard_skips_when_the_typelib_is_missing(monkeypatch):
    monkeypatch.setattr(accessibility, "accessibility_available",
                        lambda name="atspi": (False, "simulated: no PyGObject"))
    with pytest.raises(pytest.skip.Exception):
        require_atspi()


def test_the_guard_passes_when_the_reader_can_be_built(monkeypatch):
    monkeypatch.setattr(accessibility, "accessibility_available",
                        lambda name="atspi": (True, "simulated: AT-SPI reader ready"))
    require_atspi()          # must not raise


def test_the_guard_asks_for_atspi_and_not_a_name_that_always_resolves(monkeypatch):
    asked = []

    def record(name="atspi"):
        asked.append(name)
        return True, "recorded"

    monkeypatch.setattr(accessibility, "accessibility_available", record)
    require_atspi()
    assert asked == ["atspi"]


def test_uia_is_reported_unavailable_on_linux_and_that_is_not_a_failure():
    """Why the Windows test had to be split rather than guarded as a whole."""
    available, detail = accessibility.accessibility_available("uia")
    assert available is False, "UI Automation is Windows-only"
    assert detail, "an unavailable backend still has to say why"