add program files
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from audiobooksorter.cli import main
|
||||
|
||||
|
||||
def _make_book(folder: Path, title: str, author: str, series: str | None, index: int | None) -> None:
|
||||
folder.mkdir(parents=True)
|
||||
(folder / "metadata.json").write_text(
|
||||
json.dumps(
|
||||
{"title": title, "author": author, "series": series, "seriesIndex": index},
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
(folder / f"{title}.txt").write_text(title, encoding="utf-8")
|
||||
|
||||
|
||||
def test_cli_sorts_library(tmp_path: Path) -> None:
|
||||
library = tmp_path / "input"
|
||||
_make_book(library / "BookA", "Wayfarers", "Becky Chambers", None, None)
|
||||
_make_book(library / "BookB", "The Final Empire", "Brandon Sanderson", "Mistborn", 1)
|
||||
|
||||
output = tmp_path / "output"
|
||||
|
||||
exit_code = main(["--library", str(library), "--output", str(output)])
|
||||
|
||||
assert exit_code == 0
|
||||
assert (output / "Becky Chambers" / "Wayfarers" / "Wayfarers.txt").read_text(encoding="utf-8") == "Wayfarers"
|
||||
assert (
|
||||
output / "Brandon Sanderson" / "Mistborn" / "Book 1 - The Final Empire" / "The Final Empire.txt"
|
||||
).read_text(encoding="utf-8") == "The Final Empire"
|
||||
|
||||
|
||||
def test_cli_dry_run_shows_directory_structure(tmp_path: Path, capsys: object) -> None:
|
||||
library = tmp_path / "input"
|
||||
_make_book(library / "BookA", "All the Skills", "Honour Rae", "All the Skills", 1)
|
||||
_make_book(library / "BookB", "All the Skills", "Honour Rae", "All the Skills", 2)
|
||||
_make_book(library / "BookC", "The Wandering Inn", "PirateAba", "The Wandering Inn", 1)
|
||||
_make_book(library / "BookD", "Fae and Fare", "PirateAba", "The Wandering Inn", 2)
|
||||
_make_book(library / "BookE", "Domestication", "Seth Ring", "Battle Mage Farmer", 1)
|
||||
|
||||
exit_code = main(["--library", str(library), "--dry-run"])
|
||||
|
||||
assert exit_code == 0
|
||||
captured = capsys.readouterr()
|
||||
assert "Honour Rae / All the Skills" in captured.out
|
||||
assert "Honour Rae / All the Skills / Book 1 - All the Skills" in captured.out
|
||||
assert "Honour Rae / All the Skills / Book 2 - All the Skills" in captured.out
|
||||
assert "PirateAba / The Wandering Inn" in captured.out
|
||||
assert "PirateAba / The Wandering Inn / Book 1 - The Wandering Inn" in captured.out
|
||||
assert "PirateAba / The Wandering Inn / Book 2 - Fae and Fare" in captured.out
|
||||
assert "Seth Ring / Battle Mage Farmer" in captured.out
|
||||
assert "Seth Ring / Battle Mage Farmer / Book 1 - Domestication" in captured.out
|
||||
Reference in New Issue
Block a user