52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
"""Fixtures partagées.
|
|||
|
|
|
||
|
|
Le corpus de `data/input/` est lu tel quel : c'est la seule façon de garantir
|
||
|
|
que les parseurs suivent le format réel, et non une idée qu'on s'en fait. Les
|
||
|
|
tests ne l'écrivent jamais.
|
||
|
|
"""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import sqlite3
|
||
|
|
from collections.abc import Iterator
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from pipeline import chemins, db
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture(scope="session")
|
||
|
|
def annexe() -> str:
|
||
|
|
"""Contenu de `sec10.md`, l'annexe récapitulative."""
|
||
|
|
return chemins.chapitre(10).read_text(encoding="utf-8")
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture(scope="session")
|
||
|
|
def textes_annexe():
|
||
|
|
"""Textes extraits de l'annexe, analysés une seule fois pour la session."""
|
||
|
|
from pipeline.parseurs.tableaux_sec10 import parser
|
||
|
|
|
||
|
|
return parser(chemins.chapitre(10).read_text(encoding="utf-8"))
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture(scope="session")
|
||
|
|
def par_identifiant(textes_annexe) -> dict:
|
||
|
|
return {texte.id: texte for texte in textes_annexe.textes}
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def base(tmp_path) -> Iterator[sqlite3.Connection]:
|
||
|
|
"""Base SQLite éphémère, migrée, propre à chaque test."""
|
||
|
|
cx = db.initialiser(tmp_path / "test.db")
|
||
|
|
try:
|
||
|
|
yield cx
|
||
|
|
finally:
|
||
|
|
cx.close()
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def base_ensemencee(base, textes_annexe) -> sqlite3.Connection:
|
||
|
|
"""Base contenant les textes de l'annexe."""
|
||
|
|
db.enregistrer_textes(base, textes_annexe.textes)
|
||
|
|
return base
|