Files
unmix/tests/test_cli.py

87 lines
2.5 KiB
Python

"""Unit tests for unmix CLI."""
from pathlib import Path
from typer.testing import CliRunner
from unmix.cli import app
from unmix.config import Config
from unmix.schema.vocals import VocalLine, VocalsDocument, VocalSyllable
from unmix.sources import is_url
runner = CliRunner()
def test_cli_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "Audio analysis pipeline decomposing songs into song packages" in result.stdout
assert "doctor" in result.stdout
assert "analyze" in result.stdout
def test_cli_doctor():
result = runner.invoke(app, ["doctor"])
assert result.exit_code == 0
output = result.stdout + result.stderr
assert "Python" in output
assert "ffmpeg" in output
assert "Model Cache" in output
def test_cli_is_url():
assert is_url("https://www.youtube.com/watch?v=n8NIHnkZkeE") is True
assert is_url("http://youtu.be/n8NIHnkZkeE") is True
assert is_url("/home/user/song.mp3") is False
assert is_url("relative/path/audio.wav") is False
def test_cli_export_ultrastar_with_options(tmp_path: Path):
song_dir = tmp_path / "song_pkg"
song_dir.mkdir(parents=True, exist_ok=True)
vocals = VocalsDocument(
lines=[
VocalLine(
start=1.0,
end=2.0,
syllables=[VocalSyllable(text="Test", start=1.0, end=2.0, midi=60.0)],
)
]
)
(song_dir / "vocals.json").write_text(vocals.model_dump_json(indent=2))
result = runner.invoke(
app,
[
"export-ultrastar",
str(song_dir),
"--title",
"Custom Title",
"--artist",
"Custom Artist",
"--lang",
"en",
],
)
assert result.exit_code == 0
song_txt = song_dir / "export" / "song.txt"
assert song_txt.exists()
content = song_txt.read_text(encoding="utf-8")
assert "#TITLE:Custom Title" in content
assert "#ARTIST:Custom Artist" in content
assert "#LANGUAGE:English" in content
def test_config_device_detection(monkeypatch):
# Test UNMIX_DEFAULT_DEVICE=cpu
monkeypatch.setenv("UNMIX_DEFAULT_DEVICE", "cpu")
monkeypatch.delenv("UNMIX_DEVICE_S2", raising=False)
cfg = Config()
assert cfg.get_device("s2_stems") == "cpu"
assert cfg.get_device("s3_lyrics") == "cpu"
# Test explicit CUDA requested on non-CUDA system falls back to cpu
monkeypatch.setenv("UNMIX_DEVICE_S2", "cuda:99")
assert cfg.get_device("s2_stems") == "cpu"