commit remaining modified project files
This commit is contained in:
@@ -8,6 +8,7 @@ import pytest
|
||||
|
||||
from vlm.io import (
|
||||
_video_file_from_record,
|
||||
load_analysis_json,
|
||||
load_identities_json,
|
||||
save_identities_json,
|
||||
)
|
||||
@@ -260,3 +261,72 @@ class TestIdentitiesJsonRoundTrip:
|
||||
assert series["video_metadata"]["size_bytes"] == 500000000
|
||||
assert series["video_metadata"]["resolution"] == "1920x1080"
|
||||
assert series["video_metadata"]["codec"] == "h264"
|
||||
|
||||
|
||||
class TestJsonSchemaValidation:
|
||||
"""Tests for runtime schema validation on JSON artifacts."""
|
||||
|
||||
def test_save_identities_rejects_invalid_movie_shape(self, tmp_path):
|
||||
identities_file = tmp_path / "identities.json"
|
||||
invalid_data = {
|
||||
"vlm_schema_version": "2.0",
|
||||
"metadata": {
|
||||
"generated": "2024-02-13T12:00:00",
|
||||
"source_inventory": "test_inventory.csv",
|
||||
"total_files": 1,
|
||||
},
|
||||
"movies": [
|
||||
{
|
||||
"path": "/library/movie/Movie1 (2024).mkv",
|
||||
"filename": "Movie1 (2024).mkv",
|
||||
"category": "movie",
|
||||
"title": "Movie1",
|
||||
"year": 2024,
|
||||
"confidence": "high",
|
||||
"needs_review": False,
|
||||
}
|
||||
],
|
||||
"series": [],
|
||||
"anime": [],
|
||||
"other": [],
|
||||
}
|
||||
|
||||
with pytest.raises(ValueError, match="confidence"):
|
||||
save_identities_json(invalid_data, identities_file)
|
||||
|
||||
def test_load_analysis_rejects_missing_required_fields(self, tmp_path):
|
||||
analysis_file = tmp_path / "analysis.json"
|
||||
analysis_file.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"vlm_schema_version": "1.0",
|
||||
"metadata": {"generated": "2024-01-01T00:00:00"},
|
||||
"completeness": [
|
||||
{
|
||||
"series_title": "Show",
|
||||
"season": 1,
|
||||
"episodes_found": [1],
|
||||
"episodes_missing": [2],
|
||||
}
|
||||
],
|
||||
"duplicates": [
|
||||
{
|
||||
"identity": {
|
||||
"type": "movie",
|
||||
"title": "Test",
|
||||
"year": 2024,
|
||||
"season": None,
|
||||
"episodes": [],
|
||||
},
|
||||
"files": ["/library/movie/Test (2024).mkv"],
|
||||
"quality_comparison": [],
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
loaded = load_analysis_json(analysis_file)
|
||||
assert loaded["metadata"]["generated"] == "2024-01-01T00:00:00"
|
||||
assert loaded["duplicates"][0]["identity"]["title"] == "Test"
|
||||
|
||||
Reference in New Issue
Block a user