Fix lint ans test errors
This commit is contained in:
parent
fe4e792885
commit
a63af61b73
5 changed files with 29 additions and 21 deletions
|
|
@ -6,9 +6,10 @@ Infrastructure adapters (local Docling, Docling Serve, etc.) implement these.
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Protocol
|
||||
from typing import TYPE_CHECKING, Protocol
|
||||
|
||||
from domain.value_objects import ConversionOptions, ConversionResult
|
||||
if TYPE_CHECKING:
|
||||
from domain.value_objects import ConversionOptions, ConversionResult
|
||||
|
||||
|
||||
class DocumentConverter(Protocol):
|
||||
|
|
|
|||
|
|
@ -214,16 +214,17 @@ def _extract_bbox(bbox_data: dict, page_height: float) -> list[float]:
|
|||
if not isinstance(bbox_data, dict):
|
||||
return [0.0, 0.0, 0.0, 0.0]
|
||||
|
||||
l = bbox_data.get("l", 0.0)
|
||||
t = bbox_data.get("t", 0.0)
|
||||
r = bbox_data.get("r", 0.0)
|
||||
b = bbox_data.get("b", 0.0)
|
||||
left = bbox_data.get("l", 0.0)
|
||||
top = bbox_data.get("t", 0.0)
|
||||
right = bbox_data.get("r", 0.0)
|
||||
bottom = bbox_data.get("b", 0.0)
|
||||
coord_origin = bbox_data.get("coord_origin", "TOPLEFT")
|
||||
|
||||
if coord_origin == "BOTTOMLEFT":
|
||||
# Convert: top = page_height - old_top, bottom = page_height - old_bottom
|
||||
new_t = page_height - b
|
||||
new_b = page_height - t
|
||||
t, b = new_t, new_b
|
||||
# In BOTTOMLEFT: top has higher y, bottom has lower y
|
||||
# In TOPLEFT: flip both — new_top = page_height - old_top
|
||||
new_top = page_height - top
|
||||
new_bottom = page_height - bottom
|
||||
top, bottom = new_top, new_bottom
|
||||
|
||||
return [l, t, r, b]
|
||||
return [left, top, right, bottom]
|
||||
|
|
|
|||
|
|
@ -10,10 +10,13 @@ import asyncio
|
|||
import json
|
||||
import logging
|
||||
from dataclasses import asdict
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from domain.models import AnalysisJob
|
||||
from domain.ports import DocumentConverter
|
||||
from domain.value_objects import ConversionOptions, ConversionResult
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from domain.ports import DocumentConverter
|
||||
from persistence import analysis_repo, document_repo
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ from docling.datamodel.pipeline_options import (
|
|||
from domain.value_objects import ConversionOptions
|
||||
from infra.local_converter import (
|
||||
_build_docling_converter as build_converter,
|
||||
)
|
||||
from infra.local_converter import (
|
||||
_convert_sync as convert_document,
|
||||
)
|
||||
|
||||
|
|
@ -457,13 +459,15 @@ class TestAnalysisEndpointPipelineOptions:
|
|||
@pytest.fixture
|
||||
def client(self):
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from main import app
|
||||
return TestClient(app, raise_server_exceptions=False)
|
||||
|
||||
@pytest.fixture
|
||||
def mock_svc(self, client):
|
||||
from main import app
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from main import app
|
||||
mock = MagicMock()
|
||||
original = getattr(app.state, "analysis_service", None)
|
||||
app.state.analysis_service = mock
|
||||
|
|
|
|||
|
|
@ -8,16 +8,14 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||
import httpx
|
||||
import pytest
|
||||
|
||||
from domain.value_objects import ConversionOptions, ConversionResult, PageDetail, PageElement
|
||||
from domain.value_objects import ConversionOptions, ConversionResult
|
||||
from infra.serve_converter import (
|
||||
ServeConverter,
|
||||
_build_form_data,
|
||||
_extract_bbox,
|
||||
_extract_pages_from_docling_document,
|
||||
_parse_response,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Unit tests — form data building
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
@ -182,8 +180,9 @@ class TestExtractBbox:
|
|||
assert bbox == [10, 20, 100, 50]
|
||||
|
||||
def test_bottomleft_conversion(self):
|
||||
bbox = _extract_bbox({"l": 10, "t": 742, "r": 100, "b": 772, "coord_origin": "BOTTOMLEFT"}, 792.0)
|
||||
# new_t = 792 - 772 = 20, new_b = 792 - 742 = 50
|
||||
# In BOTTOMLEFT: t (top of box) has higher y than b (bottom of box)
|
||||
bbox = _extract_bbox({"l": 10, "t": 772, "r": 100, "b": 742, "coord_origin": "BOTTOMLEFT"}, 792.0)
|
||||
# new_top = 792 - 772 = 20, new_bottom = 792 - 742 = 50
|
||||
assert bbox == [10, 20, 100, 50]
|
||||
|
||||
def test_missing_coord_origin_defaults_topleft(self):
|
||||
|
|
@ -308,9 +307,9 @@ class TestServeConverterConvert:
|
|||
|
||||
conv = ServeConverter(base_url="http://localhost:5001")
|
||||
|
||||
with patch("infra.serve_converter.httpx.AsyncClient", return_value=mock_client):
|
||||
with pytest.raises(httpx.HTTPStatusError):
|
||||
await conv.convert(str(test_file), ConversionOptions())
|
||||
with patch("infra.serve_converter.httpx.AsyncClient", return_value=mock_client), \
|
||||
pytest.raises(httpx.HTTPStatusError):
|
||||
await conv.convert(str(test_file), ConversionOptions())
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_health_check_success(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue