ValorSentimental / backend /tests /conftest.py
iagofp's picture
Version previa a ultima reunion e ultima revision
cafba23
Raw
History Blame Contribute Delete
1.44 kB
"""Configuracion compartida dos tests.
Os modulos do backend importanse en plano (``from services.calculos import ...``),
asi que engadimos ``backend/`` ao sys.path para poder lanzar pytest dende a raiz
do repo ou dende backend/.
"""
import sys
from pathlib import Path
import pytest
BACKEND_DIR = Path(__file__).resolve().parent.parent
if str(BACKEND_DIR) not in sys.path:
sys.path.insert(0, str(BACKEND_DIR))
@pytest.fixture
def muestreo_determinista(monkeypatch):
"""Quita o azar de sample_from_ranked para poder comprobar a orde do ranking.
Substituindo random.sample/shuffle por operacions deterministas, a estratexia
devolve os primeiros ``limit`` elementos respectando a orde calculada.
"""
import services.calculos as calculos
monkeypatch.setattr(calculos.random, "sample", lambda poboacion, k: list(poboacion)[:k])
monkeypatch.setattr(calculos.random, "shuffle", lambda secuencia: None)
return None
@pytest.fixture
def peli():
# Construtor de dicts candidatos. Como fixture e non import para evitar
# chocar cun paquete `tests` de terceiros que hai en site-packages.
def _build(movie_id="m", genres="Drama", rating_count=100, rating_mean=4.0):
return {
"movie_id": movie_id,
"movieId": movie_id,
"genres": genres,
"rating_count": rating_count,
"rating_mean": rating_mean,
}
return _build