70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
import json
|
|
import xml.etree.ElementTree as ET
|
|
|
|
import cadence
|
|
|
|
|
|
def _write_and_parse(make_track, tmp_path, **kwargs):
|
|
td = make_track(**kwargs)
|
|
out = tmp_path / "project"
|
|
cadence._generate_multi_kdenlive_project([td], out)
|
|
kdenlive = out.with_suffix(".kdenlive")
|
|
assert kdenlive.exists()
|
|
return ET.parse(kdenlive).getroot()
|
|
|
|
|
|
def _sequence_tractor(root):
|
|
for tractor in root.findall("tractor"):
|
|
if tractor.find("property[@name='kdenlive:uuid']") is not None:
|
|
return tractor
|
|
raise AssertionError("sequence tractor not found")
|
|
|
|
|
|
def _track_producers(tractor):
|
|
return [t.get("producer") for t in tractor.findall("track")]
|
|
|
|
|
|
def _group_track_indices(tractor):
|
|
prop = tractor.find("property[@name='kdenlive:sequenceproperties.groups']")
|
|
groups = json.loads(prop.text)
|
|
return [child["data"].split(":")[0] for group in groups for child in group["children"]]
|
|
|
|
|
|
def test_project_with_system_audio(make_track, tmp_path):
|
|
root = _write_and_parse(
|
|
make_track, tmp_path, audio_stream_count=2, audio_track_idx=0
|
|
)
|
|
|
|
assert root.find("chain[@id='chain_a2_0']") is not None
|
|
|
|
seq = _sequence_tractor(root)
|
|
assert _track_producers(seq) == ["producer0", "tractor0", "tractor_a2", "tractor1"]
|
|
assert _group_track_indices(seq) == ["0", "1", "2"]
|
|
|
|
|
|
def test_project_without_system_audio(make_track, tmp_path):
|
|
root = _write_and_parse(
|
|
make_track, tmp_path, audio_stream_count=1, audio_track_idx=0
|
|
)
|
|
|
|
assert root.find("chain[@id='chain_a2_0']") is None
|
|
|
|
seq = _sequence_tractor(root)
|
|
assert _track_producers(seq) == ["producer0", "tractor0", "tractor1"]
|
|
assert _group_track_indices(seq) == ["0", "1"]
|
|
|
|
|
|
def test_system_stream_wiring_audio_track_0(make_track, tmp_path):
|
|
root = _write_and_parse(
|
|
make_track, tmp_path, audio_stream_count=2, audio_track_idx=0
|
|
)
|
|
chain = root.find("chain[@id='chain_a2_0']")
|
|
assert chain.find("property[@name='astream']").text == "1"
|
|
|
|
|
|
def test_system_stream_wiring_audio_track_1(make_track, tmp_path):
|
|
root = _write_and_parse(
|
|
make_track, tmp_path, audio_stream_count=2, audio_track_idx=1
|
|
)
|
|
chain = root.find("chain[@id='chain_a2_0']")
|
|
assert chain.find("property[@name='astream']").text == "0"
|