Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
python -m pip check

- name: Test runtime, installation, and CLI help
run: python -m pytest -q tests/test_gradio_runtime_compat.py tests/test_installation_docs.py tests/test_cli_stage_help.py
run: python -m pytest -q tests/test_gradio_runtime_compat.py tests/test_installation_docs.py tests/test_cli_stage_help.py tests/test_demo_import.py
31 changes: 17 additions & 14 deletions funclip/test/imagemagick_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from moviepy.editor import *
from moviepy.video.tools.subtitles import SubtitlesClip, TextClip
from moviepy.editor import VideoFileClip, concatenate_videoclips
from moviepy.video.compositing import CompositeVideoClip
"""Optional media demo; importing this module must not render a video."""

generator = lambda txt: TextClip(txt, font='./font/STHeitiMedium.ttc', fontsize=48, color='white')
subs = [((0, 2), 'sub1中文字幕'),
((2, 4), 'subs2'),
((4, 6), 'subs3'),
((6, 8), 'subs4')]
if __name__ == "__main__":
from moviepy.editor import *
from moviepy.video.tools.subtitles import SubtitlesClip, TextClip
from moviepy.editor import VideoFileClip, concatenate_videoclips
from moviepy.video.compositing import CompositeVideoClip

subtitles = SubtitlesClip(subs, generator)
generator = lambda txt: TextClip(txt, font='./font/STHeitiMedium.ttc', fontsize=48, color='white')
subs = [((0, 2), 'sub1中文字幕'),
((2, 4), 'subs2'),
((4, 6), 'subs3'),
((6, 8), 'subs4')]

video = VideoFileClip("examples/2022云栖大会_片段.mp4.mp4")
video = video.subclip(0, 8)
video = CompositeVideoClip([video, subtitles.set_pos(('center','bottom'))])
subtitles = SubtitlesClip(subs, generator)

video.write_videofile("test_output.mp4")
video = VideoFileClip("examples/2022云栖大会_片段.mp4.mp4")
video = video.subclip(0, 8)
video = CompositeVideoClip([video, subtitles.set_pos(('center','bottom'))])

video.write_videofile("test_output.mp4")
29 changes: 29 additions & 0 deletions tests/test_demo_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Optional media demos must not run while tools import or collect them."""

from pathlib import Path
import subprocess
import sys


def test_imagemagick_demo_import_is_side_effect_free(tmp_path):
demo = Path(__file__).resolve().parents[1] / "funclip/test/imagemagick_test.py"
code = """
import importlib.util
import sys

spec = importlib.util.spec_from_file_location("funclip_imagemagick_demo", sys.argv[1])
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
"""
result = subprocess.run(
[sys.executable, "-I", "-S", "-c", code, str(demo)],
cwd=tmp_path,
capture_output=True,
text=True,
timeout=20,
)

assert result.returncode == 0, result.stderr
assert result.stdout == ""
assert result.stderr == ""
assert list(tmp_path.iterdir()) == []
Loading