73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
"""Shared fixtures: temporary git repositories and tracker configuration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
def _git(*args: str, cwd: Path) -> None:
|
|
subprocess.run(
|
|
["git", *args],
|
|
cwd=str(cwd),
|
|
check=True,
|
|
capture_output=True,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def git_repo(tmp_path: Path) -> Path:
|
|
"""A fresh git repository with one initial commit on 'main'."""
|
|
repo = tmp_path / "project"
|
|
repo.mkdir()
|
|
_git("init", "-b", "main", cwd=repo)
|
|
_git("config", "user.name", "Test User", cwd=repo)
|
|
_git("config", "user.email", "test@example.com", cwd=repo)
|
|
(repo / "README.md").write_text("initial\n", encoding="utf-8")
|
|
_git("add", "README.md", cwd=repo)
|
|
_git("commit", "-m", "initial", cwd=repo)
|
|
return repo
|
|
|
|
|
|
@pytest.fixture
|
|
def tracker_config(git_repo: Path, tmp_path: Path) -> dict:
|
|
"""Tracker configuration dict pointing at the fixture repository."""
|
|
return {
|
|
"application": {"timezone": "Europe/Stockholm"},
|
|
"repository": {"path": str(git_repo), "branch": "main"},
|
|
"git": {
|
|
"user_name": "SCADA Change Tracker",
|
|
"user_email": "git-auto-tracker@localhost",
|
|
},
|
|
"files": {
|
|
"include": ["**/*"],
|
|
"exclude": ["**/*.tmp", "**/*.log", ".git/**"],
|
|
},
|
|
"security": {
|
|
"forbidden_patterns": ["**/*.key", "**/*.pem", "**/secrets.*", "**/credentials.*"],
|
|
},
|
|
"author_resolution": {
|
|
"resolvers": ["sidecar_metadata"],
|
|
"minimum_confidence": "probable",
|
|
"fallback": "unknown",
|
|
},
|
|
"logging": {"level": "INFO", "console": False, "file": None},
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def write_config(tmp_path: Path) -> object:
|
|
"""Factory: write a config dict to YAML and return its path."""
|
|
|
|
import yaml
|
|
|
|
class _Writer:
|
|
def __call__(self, config: dict, name: str = "git-auto-tracker.yaml") -> Path:
|
|
path = tmp_path / name
|
|
path.write_text(yaml.safe_dump(config), encoding="utf-8")
|
|
return path
|
|
|
|
return _Writer()
|