test: delete slow, timing-based and redundant tests

This commit is contained in:
imSp4rky
2026-12-05 15:20:05 -07:00
parent 783a2fc185
commit 3a0a74e694
292 changed files with 153 additions and 15174 deletions
+1 -121
View File
@@ -14,7 +14,7 @@ from types import SimpleNamespace
import pytest
from unshackle.core.utils.post_scripts import build_context, dispatch, season_context, substitute, tokenize
from unshackle.core.utils.post_scripts import build_context, season_context
class FakeSong(SimpleNamespace):
@@ -75,14 +75,6 @@ def test_song_context_has_music_fields_and_blank_episode_fields():
assert context["episode"] == ""
def test_song_context_survives_without_media_info():
"""The failure path and any pre-mux dispatch pass no MediaInfo."""
context = build_context(song(), None, service="EXAMPLE", error="HTTPError: 403")
assert context["title"] == "Example Track"
assert context["error"] == "HTTPError: 403"
assert context["filepath"] == ""
def test_album_grouping_matches_the_season_grouping_rule():
"""post_script_group's music branch: albums group by (album artist, album)."""
from unshackle.commands.dl import post_script_group
@@ -107,90 +99,6 @@ def test_album_grouping_matches_the_season_grouping_rule():
assert post_script_group(a)[0] == "album"
@pytest.mark.parametrize("mode", ["season", "run"])
def test_album_and_run_contexts_blank_the_file_variables(mode):
"""Mirrors the blanking dl.py applies before dispatching an album or run post-script."""
base = build_context(
song(),
media_info=object(),
filepath=Path("/dl/Example Artist/04. Example Track.flac"),
service="EXAMPLE",
)
folder = Path("/dl/Example Artist")
if mode == "season":
context = season_context(base, folder)
else:
context = dict.fromkeys(base, "")
context["folder"] = str(folder)
assert context["filepath"] == ""
assert context["sidecars"] == ""
assert context["folder"] == str(folder)
if mode == "run":
assert context["title"] == ""
assert set(context) == set(base)
else:
assert context["album"] == "Example Album, Live & Remastered"
def test_a_music_post_script_command_builds_the_argv_a_script_would_get(monkeypatch, tmp_path):
"""End to end through the real dispatcher: config entry in, argv out."""
from unshackle.core.config import config
marker = tmp_path / "argv.txt"
script = tmp_path / "hook.py"
script.write_text("import sys, pathlib\npathlib.Path(sys.argv[1]).write_text(chr(10).join(sys.argv[2:]))\n")
import sys
command = (
f'"{sys.executable}" "{script}" "{marker}" '
"--album={album} --artist={artist} --track={track_number} --file={filepath}"
)
monkeypatch.setattr(config, "post_scripts", [{"command": command, "mode": "file", "event": "success"}])
context = build_context(
song(),
media_info=object(),
filepath=Path("/dl/Example Artist/04. Example Track.flac"),
service="EXAMPLE",
)
dispatch("success", "file", context)
for _ in range(100):
if marker.exists() and marker.stat().st_size:
break
import time
time.sleep(0.05)
assert marker.exists(), "the post-script process never ran"
argv = marker.read_text().splitlines()
assert "--album=Example Album, Live & Remastered" in argv
assert "--artist=Example Artist" in argv
assert "--track=04" in argv
assert f"--file={Path('/dl/Example Artist/04. Example Track.flac')}" in argv
def test_season_context_blanks_the_file_variables_and_sets_the_folder():
"""An album post-script describes the release folder, so no track's file may leak into it."""
folder = Path("/dl/Example Artist - Example Album, Live & Remastered (1983)")
context = build_context(
song(),
media_info=object(),
filepath=folder / "04. Example Track.flac",
sidecars=[folder / "04. Example Track.lrc"],
service="EXAMPLE",
)
album = season_context(context, folder)
for key in ("filepath", "filename", "ext", "sidecars", "episode", "episode_name"):
assert album[key] == "", f"{key} still describes a file"
assert album["folder"] == str(folder)
assert album["service"] == "EXAMPLE"
assert context["filepath"] != "", "the file context handed in must not be mutated"
def test_season_context_identifies_the_album_not_the_last_track():
"""A Song's ``{title}`` is the song, so blanking only the file fields is not enough.
@@ -218,28 +126,6 @@ def test_season_context_identifies_the_album_not_the_last_track():
assert album["year"] == "1983" # album-level, kept
def test_season_context_leaves_a_non_music_context_untouched():
"""The music branch is gated on ``{album}``; a season post-script must not lose its own keys."""
folder = Path("/dl/Some Show/Season 1")
context = build_context(
episode(),
media_info=object(),
filepath=folder / "Some Show S01E05 Pilot.mkv",
service="EXAMPLE",
)
context["disc"] = "sentinel" # only the music branch clears this
season = season_context(context, folder)
assert season["title"] == "Some Show"
assert season["title_raw"] == "Some Show"
assert season["season"] == "1"
assert season["disc"] == "sentinel"
assert season["episode"] == ""
assert season["episode_name"] == ""
assert season["folder"] == str(folder)
def test_a_failed_track_gets_a_track_scoped_failure_context():
"""Failure is per-track, like every other title type, and does not describe the album.
@@ -255,11 +141,5 @@ def test_a_failed_track_gets_a_track_scoped_failure_context():
assert context["season"] == ""
def test_an_album_name_with_a_comma_stays_one_argument():
"""'Example Album, Live & Remastered' must not split, which is the whole tokenize-first point."""
argv = substitute(tokenize("upload.py --album={album}"), {"album": "Example Album, Live & Remastered"})
assert argv == ["upload.py", "--album=Example Album, Live & Remastered"]
if __name__ == "__main__":
raise SystemExit(pytest.main([__file__, "-q"]))