Files
wordarr/tests/test_naming.py
T

49 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from types import SimpleNamespace
from wordarr.naming import render_template, sanitize
def req(**kw):
base = dict(title="", authors="", year=None, series="", volume=None)
base.update(kw)
return SimpleNamespace(**base)
def test_sanitize_replaces_forbidden_chars():
assert sanitize("Die drei ???") == "Die drei ???"
assert sanitize("a/b") == "ab"
assert "\x01" not in sanitize("a\x01b")
def test_ebook_template():
r = req(title="The Hobbit", authors="J.R.R. Tolkien", year=1937)
assert render_template("{Author}/{Title} ({Year})", r) == "J.R.R. Tolkien/The Hobbit (1937)"
def test_missing_year_drops_parens():
r = req(title="The Hobbit", authors="Tolkien")
assert render_template("{Title} ({Year})", r) == "The Hobbit"
def test_comic_template():
r = req(title="One Piece", series="One Piece", volume=3)
assert render_template("{Series}/{Series} - Band {Volume}", r) == "One Piece/One Piece - Band 03"
def test_first_author_only():
r = req(title="X", authors="Alice A, Bob B")
assert render_template("{Author}", r) == "Alice A"
def test_empty_series_level_is_dropped():
r = req(title="Der Ickabog", authors="J.K. Rowling")
assert render_template("{Author}/{Series}/{Title} ({Narrator})", r) == "J.K. Rowling/Der Ickabog"
def test_series_level_kept_when_set():
r = req(title="Harry Potter und der Feuerkelch", authors="J.K. Rowling",
series="Harry Potter")
r.narrator = "Rufus Beck"
assert render_template("{Author}/{Series}/{Title} ({Narrator})", r) == \
"J.K. Rowling/Harry Potter/Harry Potter und der Feuerkelch (Rufus Beck)"