"""Shared pytest fixtures for openrun tests.

The `tmp_conn` fixture provides a fresh in-memory SQLite connection with the
full openrun schema applied — every test that touches the DB should request
this rather than `openrun.db.connect()` so the live `data/garmin.db` is never
read or written by the test suite.
"""

from __future__ import annotations

import sqlite3

import pytest

from openrun.db import SCHEMA


@pytest.fixture
def tmp_conn() -> sqlite3.Connection:
    """Fresh in-memory SQLite with the openrun schema applied."""
    conn = sqlite3.connect(":memory:")
    conn.execute("PRAGMA foreign_keys = ON")
    conn.row_factory = sqlite3.Row
    conn.executescript(SCHEMA)
    try:
        yield conn
    finally:
        conn.close()
