# SPDX-FileCopyrightText: 2026 Team Centurions # SPDX-License-Identifier: AGPL-3.0-or-later import numpy as np import pytest from pageparse.ocr.printed import PrintedOCR def test_tesseract_not_found(monkeypatch: pytest.MonkeyPatch): monkeypatch.setattr("pageparse.ocr.printed.shutil.which", lambda _: None) monkeypatch.setattr("pageparse.ocr.printed.TESSERACT_CANDIDATES", []) with pytest.raises(RuntimeError, match="Tesseract not found"): PrintedOCR() def test_printed_ocr_recognize_failure(monkeypatch: pytest.MonkeyPatch): monkeypatch.setattr("pageparse.ocr.printed.shutil.which", lambda _: "/usr/bin/tesseract") import subprocess def fake_run(*args, **kwargs): class FakeResult: returncode = 1 stdout = "" stderr = "error message" return FakeResult() monkeypatch.setattr(subprocess, "run", fake_run) ocr = PrintedOCR(tesseract_cmd="tesseract") img = np.zeros((50, 50), dtype=np.uint8) with pytest.raises(RuntimeError, match="Tesseract failed"): ocr.recognize(img)