"""Shared test fixtures for tacoshop."""

from __future__ import annotations

import os
import textwrap
from pathlib import Path

import pytest


@pytest.fixture
def tmp_toml(tmp_path: Path):
    """Create a temporary TOML config file and return (path, write_helper)."""

    def _write(content: str, name: str = "tacoshop.toml") -> Path:
        p = tmp_path / name
        p.write_text(textwrap.dedent(content))
        return p

    return _write


@pytest.fixture
def clean_env(monkeypatch: pytest.MonkeyPatch):
    """Remove tacoshop-related env vars for a clean test environment."""
    for key in list(os.environ):
        if key.startswith(("TORCH", "TRITON", "TORCHINDUCTOR")):
            monkeypatch.delenv(key, raising=False)
