add program files

This commit is contained in:
2025-11-16 10:00:56 +01:00
parent 4a019c37c2
commit 4519d722bc
23 changed files with 1205 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
from __future__ import annotations
import json
from pathlib import Path
import pytest
from audiobooksorter.ingest import IngestError, load_library
def test_load_library_from_json(samples_dir: Path) -> None:
records = load_library(samples_dir / "library.json")
assert len(records) == 5
assert records[0].title == "The Final Empire"
assert records[0].source_path is None
def test_load_library_from_directory(tmp_path: Path) -> None:
library = tmp_path / "library"
book_one = library / "Mistborn1"
book_two = library / "Wayfarers"
book_one.mkdir(parents=True)
book_two.mkdir(parents=True)
(book_one / "metadata.json").write_text(
json.dumps(
{"title": "The Final Empire", "series": "Mistborn", "seriesIndex": 1, "author": "Brandon"}
),
encoding="utf-8",
)
(book_two / "metadata.json").write_text(
json.dumps({"title": "Wayfarers", "author": "Becky Chambers"}),
encoding="utf-8",
)
records = load_library(library)
sources = {record.title: record.source_path for record in records}
assert sources["The Final Empire"] == book_one
assert sources["Wayfarers"] == book_two
def test_missing_library_raises(tmp_path: Path) -> None:
with pytest.raises(IngestError):
load_library(tmp_path / "missing")