songsplit als Git-Submodul (tools/songsplit) mit Aufrufskript, Make-Zielen und Aufnahme ins Paket (#1080)
Submodul auf Commit 7bbc6b7 (https, öffentlich). tools/songsplit.sh richtet die Python-Umgebung nur auf Befehl ein (fragt vorher) und reicht alles andere an songsplit weiter. Das Paket enthält Quelltext, Spezifikation, Skript und Lizenz, nicht die Python-Umgebung. Release-Workflow checkt Submodule aus und prüft den Paketinhalt. Worktree-Skripte holen und lösen Submodule. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
107
tools/test_songsplit_wrapper.py
Normal file
107
tools/test_songsplit_wrapper.py
Normal file
@ -0,0 +1,107 @@
|
||||
"""Tests für tools/songsplit.sh ohne echte Python-Umgebung: Attrappen für `uv` und `songsplit`, eigene Ordner."""
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
SCRIPT = Path(__file__).with_name("songsplit.sh")
|
||||
|
||||
|
||||
def make_exec(path: Path, body: str) -> Path:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text("#!/bin/sh\n" + body, encoding="utf-8")
|
||||
path.chmod(path.stat().st_mode | stat.S_IXUSR)
|
||||
return path
|
||||
|
||||
|
||||
class WrapperTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = Path(tempfile.mkdtemp(prefix="songsplit-wrapper-"))
|
||||
self.src = self.tmp / "src"
|
||||
self.src.mkdir()
|
||||
(self.src / "pyproject.toml").write_text("[project]\nname='songsplit'\n", encoding="utf-8")
|
||||
self.venv = self.tmp / "venv"
|
||||
self.bin = self.tmp / "bin"
|
||||
self.bin.mkdir()
|
||||
# Nur die Werkzeuge, die das Skript braucht, damit „uv fehlt“ wirklich fehlt.
|
||||
for tool in ("dirname", "mkdir"):
|
||||
os.symlink(shutil.which(tool), self.bin / tool)
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.tmp, ignore_errors=True)
|
||||
|
||||
def run_script(self, *args, stdin="", env_extra=None):
|
||||
env = {"PATH": str(self.bin), "HOME": str(self.tmp), "SONGSPLIT_SRC": str(self.src), "SONGSPLIT_VENV": str(self.venv)}
|
||||
env.update(env_extra or {})
|
||||
return subprocess.run(["/bin/sh", str(SCRIPT), *args], input=stdin, text=True, capture_output=True, env=env)
|
||||
|
||||
def test_missing_source_points_to_the_submodule(self):
|
||||
empty = self.tmp / "leer"
|
||||
empty.mkdir()
|
||||
r = self.run_script("doctor", env_extra={"SONGSPLIT_SRC": str(empty)})
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("git submodule update --init", r.stderr)
|
||||
|
||||
def test_not_set_up_says_how_to_set_it_up(self):
|
||||
r = self.run_script("doctor")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("noch nicht eingerichtet", r.stderr)
|
||||
self.assertIn("setup", r.stderr)
|
||||
|
||||
def test_default_environment_is_under_xdg_data_home(self):
|
||||
# Ohne SONGSPLIT_VENV (Variable nicht gesetzt) gilt der Standardort unter XDG_DATA_HOME.
|
||||
env = {"PATH": str(self.bin), "HOME": str(self.tmp), "SONGSPLIT_SRC": str(self.src), "XDG_DATA_HOME": str(self.tmp / "xdg")}
|
||||
r = subprocess.run(["/bin/sh", str(SCRIPT), "doctor"], text=True, capture_output=True, env=env)
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn(str(self.tmp / "xdg" / "singtrainer" / "songsplit-venv"), r.stderr)
|
||||
|
||||
def test_default_environment_falls_back_to_home_without_xdg(self):
|
||||
env = {"PATH": str(self.bin), "HOME": str(self.tmp), "SONGSPLIT_SRC": str(self.src)}
|
||||
r = subprocess.run(["/bin/sh", str(SCRIPT), "doctor"], text=True, capture_output=True, env=env)
|
||||
self.assertIn(str(self.tmp / ".local" / "share" / "singtrainer" / "songsplit-venv"), r.stderr)
|
||||
|
||||
def test_arguments_are_passed_on_to_songsplit(self):
|
||||
make_exec(self.venv / "bin" / "songsplit", 'echo "ARGS: $*"\n')
|
||||
r = self.run_script("analyze", "lied.mp3", "-o", "ordner", "--lang", "de")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(r.stdout.strip(), "ARGS: analyze lied.mp3 -o ordner --lang de")
|
||||
|
||||
def test_exit_code_of_songsplit_is_kept(self):
|
||||
make_exec(self.venv / "bin" / "songsplit", "exit 7\n")
|
||||
self.assertEqual(self.run_script("doctor").returncode, 7)
|
||||
|
||||
def test_setup_without_uv_fails_clearly(self):
|
||||
r = self.run_script("setup", "--yes")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("uv fehlt", r.stderr)
|
||||
self.assertFalse(self.venv.exists())
|
||||
|
||||
def test_setup_asks_first_and_aborts_on_no(self):
|
||||
make_exec(self.bin / "uv", f'echo called > "{self.tmp}/uv-called"\n')
|
||||
r = self.run_script("setup", stdin="n\n")
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("Abgebrochen", r.stdout)
|
||||
self.assertIn("mehrere GB", r.stdout, "der Umfang des Downloads wird vorher genannt")
|
||||
self.assertFalse((self.tmp / "uv-called").exists(), "bei Nein wird uv nicht gestartet")
|
||||
r = self.run_script("setup", stdin="")
|
||||
self.assertEqual(r.returncode, 1, "ohne Eingabe gilt Nein")
|
||||
|
||||
def test_setup_runs_uv_sync_with_the_frozen_lock_and_the_chosen_environment(self):
|
||||
make_exec(self.bin / "uv", f'echo "$*" > "{self.tmp}/uv-args"; echo "$UV_PROJECT_ENVIRONMENT" > "{self.tmp}/uv-env"\n')
|
||||
r = self.run_script("setup", "--yes")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
args = (self.tmp / "uv-args").read_text(encoding="utf-8").strip()
|
||||
self.assertEqual(args, f"sync --project {self.src} --frozen --no-dev --no-editable --python 3.12")
|
||||
self.assertEqual((self.tmp / "uv-env").read_text(encoding="utf-8").strip(), str(self.venv))
|
||||
|
||||
def test_setup_accepts_j_as_yes(self):
|
||||
make_exec(self.bin / "uv", f'echo ok > "{self.tmp}/uv-called"\n')
|
||||
self.assertEqual(self.run_script("setup", stdin="j\n").returncode, 0)
|
||||
self.assertTrue((self.tmp / "uv-called").exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user