feat(example): upgrade demo song package and test suite to songpack v1.0
This commit is contained in:
@ -1,16 +1,20 @@
|
||||
"""Test the demo song package in examples/demo_song."""
|
||||
"""Test the demo song package in examples/demo_song according to Songpack spec v1.0."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import soundfile as sf
|
||||
|
||||
from songsplit.container import pack_songpack, unpack_songpack
|
||||
from songsplit.export.ultrastar import parse_ultrastar
|
||||
from songsplit.schema.chords import ChordsDocument
|
||||
from songsplit.schema.manifest import ManifestDocument
|
||||
from songsplit.schema.meta import MetaDocument
|
||||
from songsplit.schema.strumming import StrummingDocument
|
||||
from songsplit.schema.tempo import TempoDocument
|
||||
from songsplit.schema.tracks import TrackDocument
|
||||
from songsplit.schema.vocals import VocalsDocument
|
||||
from songsplit.schema.vocals_f0 import VocalsF0Document
|
||||
|
||||
|
||||
def test_demo_package_structure():
|
||||
@ -18,10 +22,14 @@ def test_demo_package_structure():
|
||||
assert demo_dir.is_dir()
|
||||
|
||||
required_files = [
|
||||
"manifest.json",
|
||||
"meta.json",
|
||||
"tempo.json",
|
||||
"vocals.json",
|
||||
"vocals_f0.json",
|
||||
"chords.json",
|
||||
"tracks/guitar.json",
|
||||
"export/song.txt",
|
||||
"strumming.json",
|
||||
"song.txt",
|
||||
]
|
||||
@ -39,12 +47,23 @@ def test_demo_package_structure():
|
||||
def test_demo_package_schemas():
|
||||
demo_dir = Path("examples/demo_song")
|
||||
|
||||
# Manifest
|
||||
manifest_raw = json.loads((demo_dir / "manifest.json").read_text(encoding="utf-8"))
|
||||
manifest = ManifestDocument.model_validate(manifest_raw)
|
||||
assert manifest.format == "songpack"
|
||||
assert manifest.schema_version == "1.0"
|
||||
assert manifest.variant == "full"
|
||||
assert manifest.audio_included is True
|
||||
|
||||
# Meta
|
||||
meta_raw = json.loads((demo_dir / "meta.json").read_text(encoding="utf-8"))
|
||||
meta = MetaDocument.model_validate(meta_raw)
|
||||
assert meta.title == "Demo Song"
|
||||
assert meta.schema_version == "1.0"
|
||||
assert meta.duration_sec > 0
|
||||
assert meta.audio_ref is not None
|
||||
assert meta.key.tonic == "A"
|
||||
assert meta.key.mode == "minor"
|
||||
|
||||
# Tempo
|
||||
tempo_raw = json.loads((demo_dir / "tempo.json").read_text(encoding="utf-8"))
|
||||
@ -58,6 +77,14 @@ def test_demo_package_schemas():
|
||||
vocals = VocalsDocument.model_validate(vocals_raw)
|
||||
assert len(vocals.lines) >= 1
|
||||
assert len(vocals.lines[0].syllables) == 3
|
||||
assert vocals.lines[0].syllables[0].text == "Hel"
|
||||
assert vocals.lines[0].syllables[1].word_end is True
|
||||
|
||||
# Vocals F0
|
||||
f0_raw = json.loads((demo_dir / "vocals_f0.json").read_text(encoding="utf-8"))
|
||||
f0 = VocalsF0Document.model_validate(f0_raw)
|
||||
assert f0.hop_sec == 0.01
|
||||
assert len(f0.hz) > 0
|
||||
|
||||
# Chords
|
||||
chords_raw = json.loads((demo_dir / "chords.json").read_text(encoding="utf-8"))
|
||||
@ -65,7 +92,15 @@ def test_demo_package_schemas():
|
||||
assert len(chords.chords) == 2
|
||||
assert chords.chords[0].label == "Am"
|
||||
|
||||
# Strumming
|
||||
# Tracks (guitar.json)
|
||||
track_raw = json.loads((demo_dir / "tracks" / "guitar.json").read_text(encoding="utf-8"))
|
||||
track = TrackDocument.model_validate(track_raw)
|
||||
assert track.kind == "strumming"
|
||||
assert track.name == "guitar"
|
||||
assert len(track.events) == 4
|
||||
assert len(track.patterns) == 1
|
||||
|
||||
# Strumming (backward compat)
|
||||
strumming_raw = json.loads((demo_dir / "strumming.json").read_text(encoding="utf-8"))
|
||||
strumming = StrummingDocument.model_validate(strumming_raw)
|
||||
assert len(strumming.events) == 4
|
||||
@ -86,7 +121,7 @@ def test_demo_package_audio_properties():
|
||||
|
||||
def test_demo_package_ultrastar_roundtrip():
|
||||
demo_dir = Path("examples/demo_song")
|
||||
song_txt = demo_dir / "song.txt"
|
||||
song_txt = demo_dir / "export" / "song.txt"
|
||||
parsed = parse_ultrastar(song_txt)
|
||||
|
||||
assert parsed.title == "Demo Song"
|
||||
@ -96,3 +131,16 @@ def test_demo_package_ultrastar_roundtrip():
|
||||
|
||||
texts = [s.text for s in parsed.lines[0]]
|
||||
assert texts == ["Hel", "lo ", "world"]
|
||||
|
||||
|
||||
def test_demo_package_pack_unpack_roundtrip(tmp_path: Path):
|
||||
demo_dir = Path("examples/demo_song")
|
||||
archive_out = tmp_path / "demo.songpack"
|
||||
pack_songpack(demo_dir, archive_out)
|
||||
assert archive_out.is_file()
|
||||
|
||||
unpacked_dir = tmp_path / "demo_unpacked"
|
||||
unpack_songpack(archive_out, unpacked_dir)
|
||||
assert (unpacked_dir / "manifest.json").is_file()
|
||||
assert (unpacked_dir / "tracks" / "guitar.json").is_file()
|
||||
assert (unpacked_dir / "stems" / "vocals.wav").is_file()
|
||||
|
||||
@ -229,4 +229,3 @@ def test_vocals_f0_document():
|
||||
dumped = json.loads(f0.model_dump_json())
|
||||
assert dumped["hop_sec"] == 0.01
|
||||
assert dumped["hz"][2] == 220.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user