"""Shared test fixtures for rp.""" from __future__ import annotations from collections.abc import Callable, Iterator import io import json from pathlib import Path import pytest from rich.console import Console from rp.render import RenderOptions @pytest.fixture def tmp_file(tmp_path: Path) -> Callable[..., Path]: """Factory fixture to create a temporary file with given content and suffix.""" def _make(content: str, suffix: str = ".txt", name: str | None = None) -> Path: filename = name or f"test{suffix}" p = tmp_path / filename p.write_text(content, encoding="utf-8") return p return _make @pytest.fixture def capture_console() -> Iterator[Console]: """A Rich Console that captures output instead of printing to stdout.""" console = Console(file=io.StringIO(), width=120, force_terminal=True) yield console @pytest.fixture def default_options() -> RenderOptions: """Default RenderOptions for testing.""" return RenderOptions() @pytest.fixture def sample_json() -> str: """Valid JSON string for testing.""" return json.dumps({"name": "test", "value": 42, "items": [1, 2, 3]}, indent=2) @pytest.fixture def sample_markdown() -> str: """Markdown content for testing.""" return "# Hello\n\nThis is **bold** and *italic*.\n\n- item 1\n- item 2\n" @pytest.fixture def sample_python() -> str: """Python code for testing.""" return 'def hello(name: str = "world") -> str:\n return f"Hello, {name}!"\n'