"""Shared test fixtures for FieldWitness tests.""" from __future__ import annotations from pathlib import Path import pytest from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey @pytest.fixture() def tmp_fieldwitness_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: """Set FIELDWITNESS_DATA_DIR to a temporary directory. This must be used before importing any module that reads fieldwitness.paths at import time. For modules that read paths lazily (most of them), monkeypatching the paths module directly is more reliable. """ data_dir = tmp_path / ".fieldwitness" data_dir.mkdir() monkeypatch.setenv("FIELDWITNESS_DATA_DIR", str(data_dir)) return data_dir @pytest.fixture() def chain_dir(tmp_path: Path) -> Path: """A temporary chain directory.""" d = tmp_path / "chain" d.mkdir() return d @pytest.fixture() def private_key() -> Ed25519PrivateKey: """A fresh Ed25519 private key for testing.""" return Ed25519PrivateKey.generate()