Skip to content

Video editing with Python

Optimise test suite speed (#1463)

Tom Burrowsebd49250792e
diff --git a/media/subtitles.srt b/media/subtitles.srt
index fe57e433..6fd947cd 100644
--- a/media/subtitles.srt
+++ b/media/subtitles.srt
@@ -1,24 +1,20 @@
0
-00:00:00,000 --> 00:00:04,000
+00:00:00,000 --> 00:00:01,000
Red!
1
-00:00:05,000 --> 00:00:09,000
+00:00:02,000 --> 00:00:03,500
More Red!
2
-00:00:10,000 --> 00:00:14,000
+00:00:5,000 --> 00:00:6,000
Green!
3
-00:00:15,000 --> 00:00:19,000
-More Green!
-
-4
-00:00:20,000 --> 00:00:24,000
+00:00:7,000 --> 00:00:8,000
Blue
-5
-00:00:25,000 --> 00:00:29,000
+4
+00:00:9,000 --> 00:00:10,000
More Blue!
diff --git a/tests/test_PR.py b/tests/test_PR.py
index 37dc46c8..7e45763b 100644
--- a/tests/test_PR.py
+++ b/tests/test_PR.py
@@ -79,7 +79,7 @@ def test_PR_515():
def test_PR_528():
with ImageClip("media/vacation_2017.jpg") as clip:
new_clip = scroll(clip, w=1000, x_speed=50)
- new_clip = new_clip.with_duration(1)
+ new_clip = new_clip.with_duration(0.2)
new_clip.fps = 24
new_clip.write_videofile(os.path.join(TMP_DIR, "pano.mp4"))
@@ -105,7 +105,9 @@ def test_PR_1137_video():
"""
Test support for path-like objects as arguments for VideoFileClip.
"""
- with VideoFileClip(Path("media/big_buck_bunny_432_433.webm")) as video:
+ with VideoFileClip(Path("media/big_buck_bunny_432_433.webm")).subclip(
+ 0.2, 0.4
+ ) as video:
video.write_videofile(Path(TMP_DIR) / "pathlike.mp4")
assert isinstance(video.filename, str)
diff --git a/tests/test_Videos.py b/tests/test_Videos.py
index c6625c30..90b61e16 100644
--- a/tests/test_Videos.py
+++ b/tests/test_Videos.py
@@ -17,8 +17,7 @@ def test_afterimage():
some_background_clip = ColorClip((800, 600), color=(255, 255, 255))
final_clip = CompositeVideoClip(
[some_background_clip, masked_clip], use_bgclip=True
- )
- final_clip.duration = 5
+ ).with_duration(0.2)
final_clip.write_videofile(os.path.join(TMP_DIR, "afterimage.mp4"), fps=30)
diff --git a/tests/test_examples.py b/tests/test_examples.py
index dfe4da0e..0a837b64 100644
--- a/tests/test_examples.py
+++ b/tests/test_examples.py
@@ -21,7 +21,7 @@ def test_matplotlib_simple_example():
plt.switch_backend("agg")
x = np.linspace(-2, 2, 200)
- duration = 2
+ duration = 0.5
fig, ax = plt.subplots()
diff --git a/tests/test_fx.py b/tests/test_fx.py
index a8dfda3d..05dc9aca 100644
--- a/tests/test_fx.py
+++ b/tests/test_fx.py
@@ -279,16 +279,17 @@ def test_loop():
target3 = BitmapClip([["R"], ["G"], ["B"], ["R"], ["G"]], fps=1)
assert clip3 == target3
- clip = get_test_video()
- clip1 = loop(clip).with_duration(3) # infinite looping
+ clip = get_test_video().subclip(0.2, 0.3) # 0.1 seconds long
+ clip1 = loop(clip).with_duration(0.5) # infinite looping
clip1.write_videofile(os.path.join(TMP_DIR, "loop1.webm"))
- clip2 = loop(clip, duration=10) # loop for 10 seconds
+ clip2 = loop(clip, duration=0.5) # loop for 1 second
clip2.write_videofile(os.path.join(TMP_DIR, "loop2.webm"))
clip3 = loop(clip, n=3) # loop 3 times
clip3.write_videofile(os.path.join(TMP_DIR, "loop3.webm"))
+ # Test audio looping
clip = AudioClip(
lambda t: np.sin(440 * 2 * np.pi * t) * (t % 1) + 0.5, duration=2.5, fps=44100
)
@@ -373,7 +374,7 @@ def test_painting():
def test_resize():
# TODO update to use BitmapClip
- clip = get_test_video()
+ clip = get_test_video().subclip(0.2, 0.3)
clip1 = resize(clip, (460, 720)) # New resolution: (460,720)
assert clip1.size == (460, 720)
diff --git a/tests/test_issues.py b/tests/test_issues.py
index 52168229..90fa3137 100644
--- a/tests/test_issues.py
+++ b/tests/test_issues.py
@@ -256,7 +256,7 @@ def test_issue_354():
def test_issue_359():
- with ColorClip((800, 600), color=(255, 0, 0)).with_duration(5) as video:
+ with ColorClip((800, 600), color=(255, 0, 0)).with_duration(0.2) as video:
video.fps = 30
video.write_gif(filename=os.path.join(TMP_DIR, "issue_359.gif"), tempfiles=True)
@@ -301,7 +301,7 @@ def test_issue_368():
return mplfig_to_npimage(fig)
- animation = VideoClip(make_frame, duration=2)
+ animation = VideoClip(make_frame, duration=0.2)
animation.write_gif(os.path.join(TMP_DIR, "svm.gif"), fps=20)
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 958e5eb1..c45a1fff 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -15,12 +15,11 @@ from tests.test_helper import FONT, TMP_DIR
MEDIA_SUBTITLES_DATA = [
- ([0.0, 4.0], "Red!"),
- ([5.0, 9.0], "More Red!"),
- ([10.0, 14.0], "Green!"),
- ([15.0, 19.0], "More Green!"),
- ([20.0, 24.0], "Blue"),
- ([25.0, 29.0], "More Blue!"),
+ ([0.0, 1.0], "Red!"),
+ ([2.0, 3.5], "More Red!"),
+ ([5.0, 6.0], "Green!"),
+ ([7.0, 8.0], "Blue"),
+ ([9.0, 10.0], "More Blue!"),
]
MEDIA_SUBTITLES_UNICODE_DATA = [