"""Shared pytest fixtures and test setup for the tatami package. ``tatami.traveltimes`` raises at import time if ``GOOGLE_MAPS_API_KEY`` is unset, so we set a dummy value here (conftest is imported before any test module, and therefore before the package is imported) to make the modules importable without a real API key. Tests never hit the live API; the HTTP layer is mocked. """ import os os.environ.setdefault("GOOGLE_MAPS_API_KEY", "test-key") import numpy as np import pandas as pd import pytest from tatami.classes import Participant @pytest.fixture(autouse=True) def _seed_rng(): """Make the randomized steps (shuffles, annealing) deterministic per test.""" np.random.seed(1234) def make_participants( n: int, kitchen_sizes: list[float] | None = None ) -> list[Participant]: """Create ``n`` participants with distinct addresses and uuids.""" if kitchen_sizes is None: kitchen_sizes = [10.0] * n return [ Participant( name=f"P{i}", address=f"address {i}", phone=f"phone {i}", kitchen_size=kitchen_sizes[i], allergies="", ) for i in range(n) ] def make_timedelta_matrix( participants: list[Participant], seconds: np.ndarray ) -> pd.DataFrame: """Build a uuid-indexed square matrix of ``pd.Timedelta`` from a seconds array. Mirrors the shape produced by ``get_participant_distance_matrix``: object dtype cells holding ``pd.Timedelta`` values, indexed and columned by participant uuid. """ uuids = [p.uuid for p in participants] matrix = pd.DataFrame(index=pd.Index(uuids), columns=pd.Index(uuids), dtype=object) for i, u in enumerate(uuids): for j, v in enumerate(uuids): matrix.at[u, v] = pd.to_timedelta(f"{int(seconds[i][j])}s") return matrix @pytest.fixture def participants_factory(): return make_participants @pytest.fixture def matrix_factory(): return make_timedelta_matrix