darachhat
feat: build production-ready Khmer Document Corpus v0.2.0 with Typer CLI, PyMuPDF, Polars, and DI architecture
c4e128a | """Unit tests for Pydantic models and CorpusRecord.""" | |
| import pytest | |
| from pydantic import ValidationError | |
| from app.models.corpus import CorpusRecord | |
| from app.models.document import Category, DocumentMeta, Language | |
| def test_document_meta_valid(sample_meta: DocumentMeta) -> None: | |
| assert sample_meta.filename == "test.pdf" | |
| assert sample_meta.language == Language.mixed | |
| assert sample_meta.category == Category.research_paper | |
| assert sample_meta.pages == 2 | |
| assert sample_meta.file_size_bytes == 2048 | |
| def test_document_meta_invalid_filename() -> None: | |
| with pytest.raises(ValidationError): | |
| DocumentMeta( | |
| filename="test.docx", | |
| language=Language.en, | |
| category=Category.other, | |
| pages=1, | |
| file_size_bytes=100, | |
| ) | |
| def test_document_meta_invalid_sha256() -> None: | |
| with pytest.raises(ValidationError): | |
| DocumentMeta( | |
| filename="test.pdf", | |
| language=Language.en, | |
| category=Category.other, | |
| pages=1, | |
| file_size_bytes=100, | |
| sha256="invalid_short_hash", | |
| ) | |
| def test_corpus_record_polars_schema() -> None: | |
| schema = CorpusRecord.polars_schema() | |
| assert "id" in schema | |
| assert "sha256" in schema | |
| assert "file_size_bytes" in schema | |