Files
dl-organizer/tests/test_cli_json_errors.py
T

75 lines
1.9 KiB
Python
Raw Normal View History

2026-02-13 13:36:39 +08:00
"""Regression tests for CLI JSON error handling."""
from pathlib import Path
from click.testing import CliRunner
from vlm.cli import main
def _write_config(path: Path, library_root: Path) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(
f"""
library_root: {library_root}
video_extensions:
- .mp4
- .mkv
templates:
movie_dir: "movie/{{title}} ({{year}})/"
series_dir: "series/{{title}}/Season {{season:02d}}/"
movie_filename: "{{title}} ({{year}}){{ext}}"
series_filename: "S{{season:02d}}E{{episode:02d}}{{ext}}"
""".strip()
)
def test_analyze_invalid_json_returns_user_friendly_error(tmp_path):
config_path = tmp_path / ".vlm" / "config.yaml"
_write_config(config_path, tmp_path / "library")
invalid_json = tmp_path / "identities.json"
invalid_json.write_text("{ this is invalid json")
result = CliRunner().invoke(
main,
[
"--config",
str(config_path),
"analyze",
"--input",
str(invalid_json),
"--output",
str(tmp_path / "analysis.json"),
],
)
assert result.exit_code != 0
assert "Failed to parse JSON file" in result.output
assert "NameError" not in result.output
def test_plan_invalid_json_returns_user_friendly_error(tmp_path):
config_path = tmp_path / ".vlm" / "config.yaml"
_write_config(config_path, tmp_path / "library")
invalid_json = tmp_path / "identities.json"
invalid_json.write_text("{ this is invalid json")
result = CliRunner().invoke(
main,
[
"--config",
str(config_path),
"plan",
"--input",
str(invalid_json),
"--output",
str(tmp_path / "plan.json"),
],
)
assert result.exit_code != 0
assert "Failed to parse JSON file" in result.output
assert "NameError" not in result.output