File size: 1,694 Bytes
16e3e7d | 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 OCR guard must actually skip when there is no engine.
This is a regression test for a real bug: the guard in `test_cli.py` asked
`detector_available()`, whose default `auto` is `True` even with nothing
installed - because the grid fallback always exists. So on a machine with no OCR
engine the test *failed* instead of skipping, and the failure looked like a
harness defect. The guard now asks for `ocr` specifically, and here is the proof.
"""
import pytest
from conftest import require_ocr
import tiny_computer_agent.perception as perception
def test_the_guard_skips_when_no_engine_is_installed(monkeypatch):
monkeypatch.setattr(perception, "detector_available",
lambda name="auto": (False, "simulated: no engine"))
with pytest.raises(pytest.skip.Exception):
require_ocr()
def test_the_guard_passes_when_an_engine_is_installed(monkeypatch):
monkeypatch.setattr(perception, "detector_available",
lambda name="auto": (True, "simulated: engine present"))
require_ocr() # must not raise
def test_the_guard_asks_for_ocr_and_not_auto(monkeypatch):
"""`auto` is available with nothing installed, so it would never skip."""
asked = []
def record(name="auto"):
asked.append(name)
return True, "recorded"
monkeypatch.setattr(perception, "detector_available", record)
require_ocr()
assert asked == ["ocr"]
def test_auto_is_available_without_any_engine():
"""The reason the old guard never fired, pinned down as a test."""
available, detail = perception.detector_available("auto")
assert available is True, "auto must stay usable with no OCR engine"
|