All checks were successful
Publish Python Package to Gitea / publish (push) Successful in 17s
Co-authored-by: Cursor <cursoragent@cursor.com>
79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""screencast runner 媒体资源参数传递测试。"""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from screencast.runner import run_screencast
|
|
|
|
|
|
def test_run_screencast_passes_media_assets_root_to_compose_video(tmp_path: Path) -> None:
|
|
custom_root = tmp_path / "media-assets"
|
|
custom_root.mkdir()
|
|
captured: dict = {}
|
|
|
|
mock_recorder = MagicMock()
|
|
mock_recorder.frame_count = 1
|
|
|
|
def _fake_compose_video(**kwargs):
|
|
captured.update(kwargs)
|
|
Path(kwargs["output_path"]).write_bytes(b"mp4")
|
|
from screencast.composer import ComposeVideoResult
|
|
|
|
return ComposeVideoResult(kwargs["output_path"])
|
|
|
|
with patch("screencast.runner.activate_and_maximize_jiangchang_window", return_value=True), patch(
|
|
"screencast.runner.ScreenRecorder",
|
|
return_value=mock_recorder,
|
|
), patch("screencast.runner.SubtitleEngine") as subtitle_cls, patch(
|
|
"screencast.runner.subprocess.Popen",
|
|
) as popen_cls, patch(
|
|
"screencast.runner.compose_video",
|
|
side_effect=_fake_compose_video,
|
|
):
|
|
subtitle = subtitle_cls.return_value
|
|
proc = popen_cls.return_value
|
|
proc.stdout = iter([])
|
|
proc.wait.return_value = 0
|
|
|
|
out = run_screencast(
|
|
skill_slug="demo-skill",
|
|
subtitle_script=[("ok", "done")],
|
|
pytest_args=["-q", "tests/test_demo.py"],
|
|
output_dir=str(tmp_path / "out"),
|
|
media_assets_root=str(custom_root),
|
|
)
|
|
|
|
assert Path(out).is_file()
|
|
assert captured.get("media_assets_root") == str(custom_root)
|
|
|
|
|
|
def test_run_screencast_music_subdir_deprecated_warning() -> None:
|
|
with pytest.warns(DeprecationWarning, match="music_subdir is deprecated"):
|
|
with patch("screencast.runner.activate_and_maximize_jiangchang_window", return_value=False), patch(
|
|
"screencast.runner.ScreenRecorder",
|
|
) as rec_cls, patch("screencast.runner.SubtitleEngine"), patch(
|
|
"screencast.runner.subprocess.Popen",
|
|
) as popen_cls, patch(
|
|
"screencast.runner.compose_video",
|
|
) as compose_mock:
|
|
rec = rec_cls.return_value
|
|
rec.frame_count = 0
|
|
proc = popen_cls.return_value
|
|
proc.stdout = iter([])
|
|
proc.wait.return_value = 0
|
|
from screencast.composer import ComposeVideoResult
|
|
|
|
compose_mock.return_value = ComposeVideoResult("out.mp4")
|
|
|
|
run_screencast(
|
|
skill_slug="demo",
|
|
subtitle_script=[],
|
|
pytest_args=["-q"],
|
|
output_dir=".",
|
|
music_subdir="calm",
|
|
)
|