import fitz import numpy as np import pytest from cv_analysis.server.pipeline import make_analysis_pipeline from cv_analysis.utils.structures import Rectangle def analysis_fn_mock(image: np.ndarray): bbox = (0, 0, 42, 42) return [Rectangle.from_xyxy(bbox)] @pytest.fixture def empty_pdf(n_pages): doc = fitz.open() for n in range(n_pages): doc.new_page() return doc.write() @pytest.fixture def expected_formatted_analysis_result(n_pages): return [ { "pageNumber": page_number, "rotation": 0, "width": 595.0, "height": 842.0, "bboxes": [{"x1": 0.0, "y1": 0.0, "x2": 15.12, "y2": 15.12, "width": 15.12, "height": 15.12}], } for page_number in range(n_pages) ] @pytest.mark.parametrize("n_pages", [1, 2]) def test_analysis_pipeline(empty_pdf, expected_formatted_analysis_result): analysis_pipeline = make_analysis_pipeline(analysis_fn_mock) results = analysis_pipeline(empty_pdf) assert list(results) == expected_formatted_analysis_result