rag_template / tests /test_units.py
Guilherme Favaron
Initial commit of local project
f5eb34f
import io
import os
import importlib
def test_chunk_text_basic():
app = importlib.import_module("app")
text = "a" * 2500
chunks = app.chunk_text(text, max_chars=1000)
assert len(chunks) == 3
assert "".join(chunks) == text
def test_build_prompt_includes_contexts():
app = importlib.import_module("app")
ctx = [{"id": 1, "title": "t", "content": "c1"}, {"id": 2, "title": "t2", "content": "c2"}]
p = app.build_prompt("q", ctx)
assert "c1" in p and "c2" in p and "q" in p
def test_extract_pdf_text_handles_bytes():
app = importlib.import_module("app")
# Minimal PDF content (may not contain extractable text, should not raise)
minimal_pdf = b"%PDF-1.4\n1 0 obj\n<<>>\nendobj\nxref\n0 1\n0000000000 65535 f \ntrailer\n<<>>\nstartxref\n0\n%%EOF\n"
text = app.extract_pdf_text(minimal_pdf)
assert isinstance(text, str)