File size: 2,539 Bytes
f662601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Sprint A14-S52 — hiérarchie d'erreurs unifiée (fix audit #7 + #11).

Avant S52 :
- LLM/VLM levaient OCRAdapterError (mauvaise classe).
- JobStoreError héritait de Exception (pas de PicaronesError).
- Pas de racine commune AdapterStepError pour catcher OCR+LLM+VLM.

Après S52 :
- AdapterStepError(PicaronesError) est la racine commune.
- OCRAdapterError, LLMAdapterError, VLMAdapterError héritent.
- JobStoreError hérite de PicaronesError.
"""

from __future__ import annotations

import pytest

from picarones.adapters.llm.base import LLMAdapterError
from picarones.adapters.ocr.base import OCRAdapterError
from picarones.adapters.storage import JobStoreError
from picarones.adapters.vlm.base import VLMAdapterError
from picarones.domain.errors import AdapterStepError, PicaronesError


class TestErrorInheritance:
    def test_ocr_inherits_adapter_step_error(self) -> None:
        assert issubclass(OCRAdapterError, AdapterStepError)
        assert issubclass(OCRAdapterError, PicaronesError)

    def test_llm_inherits_adapter_step_error(self) -> None:
        assert issubclass(LLMAdapterError, AdapterStepError)
        assert issubclass(LLMAdapterError, PicaronesError)

    def test_vlm_inherits_adapter_step_error(self) -> None:
        assert issubclass(VLMAdapterError, AdapterStepError)
        assert issubclass(VLMAdapterError, PicaronesError)

    def test_jobstore_inherits_picarones_error(self) -> None:
        # Avant S52, héritait de Exception → un caller `except
        # PicaronesError` ratait JobStoreError.  Maintenant inclus.
        assert issubclass(JobStoreError, PicaronesError)


class TestPolymorphicCatch:
    """Un caller peut catcher AdapterStepError pour gérer toute
    erreur d'adapter sans connaître la sous-classe."""

    def test_catches_ocr(self) -> None:
        with pytest.raises(AdapterStepError):
            raise OCRAdapterError("ocr boom")

    def test_catches_llm(self) -> None:
        with pytest.raises(AdapterStepError):
            raise LLMAdapterError("llm boom")

    def test_catches_vlm(self) -> None:
        with pytest.raises(AdapterStepError):
            raise VLMAdapterError("vlm boom")

    def test_picarones_catches_all_adapter_errors(self) -> None:
        for cls in (OCRAdapterError, LLMAdapterError, VLMAdapterError):
            with pytest.raises(PicaronesError):
                raise cls("boom")

    def test_picarones_catches_jobstore(self) -> None:
        with pytest.raises(PicaronesError):
            raise JobStoreError("store boom")