Files
dotfiles/tests/test_eval_warnings_extended.py
Claude b3199dfc31 Add comprehensive test suite achieving 99% code coverage
Added 35 test files with 502 tests covering all Python modules including
API routes, ORM models, splendor game logic/TUI, heater controller,
weather service, NixOS installer, ZFS dataset management, and utilities.
Coverage improved from 11% to 99% (2540/2564 statements covered).

https://claude.ai/code/session_01SVzgLDUS1Cdc4eh1ijETTh
2026-03-09 03:55:38 +00:00

78 lines
2.1 KiB
Python

"""Extended tests for python/eval_warnings/main.py."""
from __future__ import annotations
import os
from pathlib import Path
from unittest.mock import MagicMock, patch
from python.eval_warnings.main import (
EvalWarning,
extract_referenced_files,
)
def test_extract_referenced_files_nix_store_paths(tmp_path: Path) -> None:
"""Test extracting files from nix store paths."""
# Create matching directory structure
systems_dir = tmp_path / "systems"
systems_dir.mkdir()
nix_file = systems_dir / "test.nix"
nix_file.write_text("{ pkgs }: pkgs")
warnings = {
EvalWarning(
system="s1",
message="warning: in /nix/store/abc-source/systems/test.nix:5: deprecated",
)
}
# Change to tmp_path so relative paths work
old_cwd = os.getcwd()
try:
os.chdir(tmp_path)
files = extract_referenced_files(warnings)
finally:
os.chdir(old_cwd)
assert "systems/test.nix" in files
assert files["systems/test.nix"] == "{ pkgs }: pkgs"
def test_extract_referenced_files_no_files_found() -> None:
"""Test extract_referenced_files when no files are found."""
warnings = {
EvalWarning(
system="s1",
message="warning: something generic without file paths",
)
}
files = extract_referenced_files(warnings)
# Either empty or has flake.nix fallback
assert isinstance(files, dict)
def test_extract_referenced_files_repo_relative_paths(tmp_path: Path) -> None:
"""Test extracting repo-relative file paths."""
# Create the referenced file
systems_dir = tmp_path / "systems" / "foo"
systems_dir.mkdir(parents=True)
nix_file = systems_dir / "bar.nix"
nix_file.write_text("{ config }: {}")
warnings = {
EvalWarning(
system="s1",
message="warning: in systems/foo/bar.nix:10: test",
)
}
old_cwd = os.getcwd()
try:
os.chdir(tmp_path)
files = extract_referenced_files(warnings)
finally:
os.chdir(old_cwd)
assert "systems/foo/bar.nix" in files