63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import sqlite3
|
|
|
|
import pytest
|
|
|
|
from scripts.common import CHUNKS_FILE, DB_FILE, DOCUMENTS_FILE
|
|
from scripts.search_utils import search_database
|
|
|
|
|
|
pytestmark = pytest.mark.skipif(
|
|
os.getenv("RUN_LIVE_TESTS") != "1",
|
|
reason="Spusti s RUN_LIVE_TESTS=1 po vytvorení reálneho indexu.",
|
|
)
|
|
|
|
|
|
def test_real_generated_files_are_consistent() -> None:
|
|
assert DOCUMENTS_FILE.exists()
|
|
assert CHUNKS_FILE.exists()
|
|
assert DB_FILE.exists()
|
|
|
|
documents = json.loads(DOCUMENTS_FILE.read_text(encoding="utf-8"))
|
|
chunks = json.loads(CHUNKS_FILE.read_text(encoding="utf-8"))
|
|
|
|
assert documents
|
|
assert chunks
|
|
assert all(document.get("title") for document in documents)
|
|
assert all(chunk.get("chunk_id") for chunk in chunks)
|
|
assert all(chunk.get("title") for chunk in chunks)
|
|
assert all(chunk.get("text") for chunk in chunks)
|
|
assert all(chunk.get("token_count", 0) <= 450 for chunk in chunks)
|
|
|
|
with sqlite3.connect(DB_FILE) as conn:
|
|
db_documents = conn.execute("SELECT COUNT(*) FROM documents").fetchone()[0]
|
|
db_chunks = conn.execute("SELECT COUNT(*) FROM chunks").fetchone()[0]
|
|
fts_chunks = conn.execute("SELECT COUNT(*) FROM chunks_fts").fetchone()[0]
|
|
integrity = conn.execute("PRAGMA integrity_check").fetchone()[0]
|
|
foreign_keys = conn.execute("PRAGMA foreign_key_check").fetchall()
|
|
|
|
assert db_documents == len(documents)
|
|
assert db_chunks == len(chunks)
|
|
assert fts_chunks == len(chunks)
|
|
assert integrity == "ok"
|
|
assert foreign_keys == []
|
|
|
|
|
|
def test_real_search_finds_expected_baseline_results() -> None:
|
|
person = search_database(DB_FILE, "jan ptak", limit=5)
|
|
topic = search_database(DB_FILE, "strojovy preklad", limit=5)
|
|
inflection = search_database(DB_FILE, "hlboke ucenie", limit=5)
|
|
|
|
assert person["strategies"] == ["all_terms"]
|
|
assert person["results"]
|
|
assert person["results"][0]["title"] == "Ján Pták"
|
|
|
|
assert topic["results"]
|
|
assert topic["results"][0]["title"] == "Strojový preklad"
|
|
|
|
assert inflection["results"]
|
|
assert inflection["strategies"] in (["all_terms"], ["prefix_terms"])
|