Files
wordarr/tests/test_naming.py
T

47 lines
1.5 KiB
Python

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_removes_forbidden_chars():
assert sanitize('A<b>:c/d\\e|f?g*h"') == "Abcdefgh"
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)"