feat: 完成 SRT 转双目 ASS 节点
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import runpy
|
||||
from pathlib import Path
|
||||
|
||||
from wov_node_ass.__main__ import parse_srt, write_ass, invoke
|
||||
from wov_sdk.models import InvokeRequest
|
||||
|
||||
|
||||
SAMPLE_SRT = """
|
||||
1
|
||||
00:00:01,000 --> 00:00:03,000
|
||||
第一行
|
||||
第二行
|
||||
|
||||
2
|
||||
00:00:04,000 --> 00:00:06,000
|
||||
第三行
|
||||
"""
|
||||
|
||||
|
||||
def test_parse_and_write(tmp_path) -> None:
|
||||
entries = parse_srt(SAMPLE_SRT)
|
||||
assert len(entries) == 2
|
||||
assert entries[0][2] == r"第一行\N第二行"
|
||||
|
||||
output = tmp_path / "out.ass"
|
||||
write_ass(entries, output, "3840x1920")
|
||||
content = output.read_text(encoding="utf-8")
|
||||
assert "PlayResX: 3840" in content
|
||||
assert "PlayResY: 1920" in content
|
||||
assert "LeftEye" in content
|
||||
assert "RightEye" in content
|
||||
assert r"第一行\N第二行" in content
|
||||
|
||||
|
||||
def test_parse_malformed(tmp_path) -> None:
|
||||
source = tmp_path / "bad.srt"
|
||||
source.write_text("1\nnot a time line\n", encoding="utf-8")
|
||||
assert parse_srt(source.read_text(encoding="utf-8")) == []
|
||||
|
||||
source.write_text("1", encoding="utf-8")
|
||||
assert parse_srt(source.read_text(encoding="utf-8")) == []
|
||||
|
||||
|
||||
def test_invoke_success(tmp_path) -> None:
|
||||
source = tmp_path / "in.srt"
|
||||
source.write_text(SAMPLE_SRT, encoding="utf-8")
|
||||
response = invoke(
|
||||
InvokeRequest(
|
||||
run_id="run_1",
|
||||
node_instance_id="ni_1",
|
||||
inputs={"cn_srt_uri": str(source)},
|
||||
params={"resolution": "1920x1080"},
|
||||
output_dir=str(tmp_path / "out"),
|
||||
)
|
||||
)
|
||||
assert response.status == "completed"
|
||||
assert "PlayResX: 1920" in Path(response.outputs["ass_uri"]).read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_invoke_missing_input(tmp_path) -> None:
|
||||
response = invoke(
|
||||
InvokeRequest(
|
||||
run_id="run_2",
|
||||
node_instance_id="ni_2",
|
||||
inputs={},
|
||||
output_dir=str(tmp_path),
|
||||
)
|
||||
)
|
||||
assert response.status == "failed"
|
||||
|
||||
|
||||
def test_invoke_missing_file(tmp_path) -> None:
|
||||
response = invoke(
|
||||
InvokeRequest(
|
||||
run_id="run_3",
|
||||
node_instance_id="ni_3",
|
||||
inputs={"cn_srt_uri": str(tmp_path / "missing.srt")},
|
||||
output_dir=str(tmp_path),
|
||||
)
|
||||
)
|
||||
assert response.status == "failed"
|
||||
|
||||
|
||||
def test_entrypoint(monkeypatch) -> None:
|
||||
module_path = Path(__file__).resolve().parent.parent / "wov_node_ass" / "__main__.py"
|
||||
captured = {}
|
||||
|
||||
def fake_run_node(manifest, handler) -> None:
|
||||
captured["id"] = manifest.id
|
||||
|
||||
monkeypatch.setattr("wov_sdk.server.run_node", fake_run_node)
|
||||
runpy.run_path(str(module_path), run_name="__main__")
|
||||
assert captured["id"] == "srt-to-dual-eye-ass"
|
||||
Reference in New Issue
Block a user