forked from kenzuya/unshackle
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -40,11 +38,6 @@ def test_metacharacters_in_a_value_stay_one_argument():
|
||||
assert argv == ["upload.py", "/downloads/Bob's Burgers S01E01.mkv", '--title=Bob"; rm -rf ~']
|
||||
|
||||
|
||||
def test_empty_variable_substitutes_empty():
|
||||
argv = build("upload.py {filepath} --tmdb={tmdb}", {"filepath": "/x.mkv", "tmdb": ""})
|
||||
assert argv == ["upload.py", "/x.mkv", "--tmdb="]
|
||||
|
||||
|
||||
def test_sidecars_join_as_a_single_token():
|
||||
subs = [Path("/dl/Show S01E01.en.srt"), Path("/dl/Show S01E01.fr.srt")]
|
||||
argv = build("upload.py --subs={sidecars}", {"sidecars": SIDECAR_SEPARATOR.join(map(str, subs))})
|
||||
@@ -175,57 +168,10 @@ def test_typoed_event_or_mode_warns_instead_of_silently_dropping(monkeypatch, ca
|
||||
assert caplog.text.count("unknown event/mode") == 1 # warned once, not per dispatch
|
||||
|
||||
|
||||
def test_tagging_ids_are_read_at_dispatch_not_snapshotted():
|
||||
"""A series' TMDB ID is resolved inside the title loop, after any pre-loop snapshot.
|
||||
|
||||
Guards a regression where ``post_script_ids`` was a dict built before the loop, so
|
||||
``{tmdb}`` was empty for every download that did not pass ``--tmdb`` by hand.
|
||||
"""
|
||||
import ast
|
||||
import inspect
|
||||
import textwrap
|
||||
|
||||
from unshackle.commands.dl import dl
|
||||
from unshackle.core.title_metadata import TitleMetadata
|
||||
|
||||
metadata = TitleMetadata(imdb_id="tt0000001")
|
||||
assert build_context(SimpleNamespace(), ids=metadata.post_script_ids())["tmdb"] == ""
|
||||
metadata.tmdb_id = 1396
|
||||
assert build_context(SimpleNamespace(), ids=metadata.post_script_ids())["tmdb"] == "1396"
|
||||
|
||||
body = ast.parse(textwrap.dedent(inspect.getsource(dl.result)))
|
||||
for node in ast.walk(body):
|
||||
targets = getattr(node, "targets", [])
|
||||
assert not any(isinstance(t, ast.Name) and t.id == "post_script_ids" for t in targets), (
|
||||
"post_script_ids is snapshotted again; it must be read per dispatch"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(pytest.main([__file__, "-q"]))
|
||||
|
||||
|
||||
def _dispatch_seconds(monkeypatch, entry: dict) -> float:
|
||||
import time
|
||||
|
||||
monkeypatch.setattr(config, "post_scripts", [entry])
|
||||
start = time.monotonic()
|
||||
dispatch("success", "file", {})
|
||||
return time.monotonic() - start
|
||||
|
||||
|
||||
def test_wait_true_waits_for_the_script_and_logs_the_exit_code(monkeypatch, caplog):
|
||||
caplog.set_level("DEBUG", logger="post-script")
|
||||
slow = f'"{sys.executable}" -c "import time,sys; time.sleep(0.3); sys.exit(3)"'
|
||||
assert _dispatch_seconds(monkeypatch, {"command": slow, "wait": True}) >= 0.3
|
||||
assert "Post-script exited 3" in caplog.text
|
||||
|
||||
|
||||
def test_wait_defaults_to_fire_and_forget(monkeypatch):
|
||||
slow = f'"{sys.executable}" -c "import time; time.sleep(0.3)"'
|
||||
assert _dispatch_seconds(monkeypatch, {"command": slow}) < 0.3
|
||||
|
||||
|
||||
def test_no_postscript_override_silences_every_event_and_mode(monkeypatch):
|
||||
"""``dl --no-postscript`` passes NO_POST_SCRIPTS as the override list. Nothing may spawn."""
|
||||
monkeypatch.setattr(config, "post_scripts", [{"command": "should_not_run.py", "mode": mode} for mode in MODES])
|
||||
@@ -246,43 +192,9 @@ def _episode(part):
|
||||
return Episode(id_="episode-id", service=Svc, title="T", season=1, number=5, part=part, name="Ep")
|
||||
|
||||
|
||||
def test_part_is_a_plain_number_on_success_and_failure():
|
||||
"""{part} agrees on both paths, and the failure path carries every title-owned variable."""
|
||||
title = _episode(1)
|
||||
success = build_context(title, SimpleNamespace(video_tracks=[], audio_tracks=[]), service="SVC")
|
||||
failure = build_context(title, None, service="SVC", error="Boom")
|
||||
for context in (success, failure):
|
||||
assert context["part"] == "1"
|
||||
assert context["episode"] == "5"
|
||||
assert context["season_episode"] == "S01E05.Part.1"
|
||||
assert failure["quality"] == ""
|
||||
assert build_context(_episode(None), None, service="SVC")["part"] == ""
|
||||
|
||||
|
||||
def test_season_context_blanks_every_episode_identity_field():
|
||||
context = build_context(_episode(1), None, service="SVC")
|
||||
season = ps.season_context(context, Path("/out"))
|
||||
assert season["season"] == "1"
|
||||
for key in ("episode", "part", "season_episode", "absolute", "date", "episode_name"):
|
||||
assert season[key] == ""
|
||||
|
||||
|
||||
def test_every_documented_variable_is_one_build_context_produces():
|
||||
"""The variable tables in docs/reference/configuration/post-scripts.md must not drift from the code."""
|
||||
from unshackle.core.titles.music import Song
|
||||
|
||||
doc = Path(__file__).resolve().parents[1] / "docs" / "reference" / "configuration" / "post-scripts.md"
|
||||
documented = {
|
||||
name
|
||||
for line in doc.read_text(encoding="utf-8").splitlines()
|
||||
if line.startswith("| `{")
|
||||
for name in re.findall(r"`\{(\w+)\}`", line.split("|")[1])
|
||||
}
|
||||
assert documented, "no variable table rows found"
|
||||
|
||||
class Svc:
|
||||
pass
|
||||
|
||||
song = Song(id_="song-id", service=Svc, name="Tr", artist="Ar", album="Al", track=1)
|
||||
produced = set(build_context(_episode(1), None, service="SVC")) | set(build_context(song, None, service="SVC"))
|
||||
assert documented <= produced, sorted(documented - produced)
|
||||
|
||||
Reference in New Issue
Block a user