feat: complete translator stack
This commit is contained in:
commit
6fe7c5121b
9946 files changed
+1747495
No files matched your search
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from backend.app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_health_check():
|
||||
resp = client.get("/health")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json().get("status") == "ok"
|
||||
@@ -0,0 +1,69 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
import fitz
|
||||
from ebooklib import epub
|
||||
from docx import Document
|
||||
|
||||
from backend.app.processors.registry import select_processor
|
||||
from backend.app.services.chunking import chunk_document
|
||||
|
||||
|
||||
def _create_docx(path: Path) -> Path:
|
||||
doc = Document()
|
||||
doc.add_heading("Titolo principale", level=1)
|
||||
doc.add_paragraph("Primo paragrafo del documento.")
|
||||
doc.add_paragraph("Secondo paragrafo con alcune frasi.")
|
||||
doc.save(path)
|
||||
return path
|
||||
|
||||
|
||||
def _create_pdf(path: Path) -> Path:
|
||||
doc = fitz.open()
|
||||
page = doc.new_page()
|
||||
page.insert_text((72, 72), "Titolo PDF\n\nParagrafo PDF di prova.")
|
||||
doc.save(path)
|
||||
doc.close()
|
||||
return path
|
||||
|
||||
|
||||
def _create_epub(path: Path) -> Path:
|
||||
book = epub.EpubBook()
|
||||
book.set_identifier("test-123")
|
||||
book.set_title("EPUB di prova")
|
||||
book.set_language("it")
|
||||
|
||||
chapter = epub.EpubHtml(title="Capitolo", file_name="chap.xhtml")
|
||||
chapter.content = "<h1>Capitolo</h1><p>Paragrafo EPUB.</p>"
|
||||
book.add_item(chapter)
|
||||
book.toc = (epub.Link("chap.xhtml", "Capitolo", "chap"),)
|
||||
book.add_item(epub.EpubNcx())
|
||||
book.add_item(epub.EpubNav())
|
||||
epub.write_epub(str(path), book)
|
||||
return path
|
||||
|
||||
|
||||
def _create_txt(path: Path) -> Path:
|
||||
path.write_text("Titolo TXT\n\nParagrafo 1\n\nParagrafo 2", encoding="utf-8")
|
||||
return path
|
||||
|
||||
|
||||
generator_map: dict[str, Callable[[Path], Path]] = {
|
||||
".docx": _create_docx,
|
||||
".pdf": _create_pdf,
|
||||
".epub": _create_epub,
|
||||
".txt": _create_txt,
|
||||
}
|
||||
|
||||
|
||||
def test_processor_chain(tmp_path: Path):
|
||||
for suffix, generator in generator_map.items():
|
||||
target = tmp_path / f"sample{suffix}"
|
||||
path = generator(target)
|
||||
processor = select_processor(path)
|
||||
assert processor is not None, f"Processor missing for {suffix}"
|
||||
extraction = processor(path)
|
||||
chunks = chunk_document(f"session-{suffix}", extraction)
|
||||
assert chunks, f"Nessun chunk per {suffix}"
|
||||
assert all(chunk.text.strip() for chunk in chunks)
|
||||
Reference in new issue
Block a user