Skip to content

Video editing with Python

Additional tests cleanup

Mark Beacome8bf1456c78a
diff --git a/tests/README.rst b/tests/README.rst
index 5ff50179..6a696a7c 100644
--- a/tests/README.rst
+++ b/tests/README.rst
@@ -1 +1,3 @@
-No official test suite for the moment. Coming soon.
\ No newline at end of file
+Install testing dependencies: `pip install moviepy[test]`
+
+Run tests: `python setup.py test`
diff --git a/tests/test_ImageSequenceClip.py b/tests/test_ImageSequenceClip.py
index caef3dbd..b81ee77f 100644
--- a/tests/test_ImageSequenceClip.py
+++ b/tests/test_ImageSequenceClip.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
"""Image sequencing clip tests meant to be run with pytest."""
import sys
diff --git a/tests/test_TextClip.py b/tests/test_TextClip.py
index 58858e28..cab3a97e 100644
--- a/tests/test_TextClip.py
+++ b/tests/test_TextClip.py
@@ -1,9 +1,10 @@
+import sys
+
import pytest
-from moviepy.editor import *
+from moviepy.video.fx.blink import blink
+from moviepy.video.VideoClip import TextClip
-import sys
sys.path.append("tests")
-import download_media
def test_duration():
return
@@ -15,9 +16,18 @@ def test_duration():
clip.set_duration(5)
assert clip.duration == 5
- clip2 = clip.fx(vfx.blink, d_on=1, d_off=1)
+ clip2 = clip.fx(blink, d_on=1, d_off=1)
clip2.set_duration(5)
assert clip2.duration == 5
+# Moved from tests.py. Maybe we can remove these?
+def test_if_textclip_crashes_in_caption_mode():
+ TextClip(txt='foo', color='white', size=(640, 480), method='caption',
+ align='center', fontsize=25)
+
+def test_if_textclip_crashes_in_label_mode():
+ TextClip(txt='foo', method='label')
+
+
if __name__ == '__main__':
pytest.main()
diff --git a/tests/test_VideoFileClip.py b/tests/test_VideoFileClip.py
index 23bb309e..a807bc80 100644
--- a/tests/test_VideoFileClip.py
+++ b/tests/test_VideoFileClip.py
@@ -1,13 +1,20 @@
-import pytest
-from moviepy.editor import *
+# -*- coding: utf-8 -*-
+"""Video file clip tests meant to be run with pytest."""
import os
+import pytest
+from moviepy.video.compositing.CompositeVideoClip import clips_array
+from moviepy.video.VideoClip import ColorClip
+from moviepy.video.VideoFileClip import VideoFileClip
+
+
def test_setup():
+ """Test VideoFileClip setup."""
red = ColorClip((1024,800), color=(255,0,0))
green = ColorClip((1024,800), color=(0,255,0))
blue = ColorClip((1024,800), color=(0,0,255))
- red.fps=green.fps=blue.fps=30
+ red.fps = green.fps = blue.fps = 30
video = clips_array([[red, green, blue]]).set_duration(5)
video.write_videofile("/tmp/test.mp4")
@@ -19,25 +26,26 @@ def test_setup():
assert clip.size == [1024*3, 800]
def test_ffmpeg_resizing():
- # Test downscaling
- target_resolution = (128,128)
- video = VideoFileClip("media/big_buck_bunny_432_433.webm", target_resolution=target_resolution)
+ """Test FFmpeg resizing, to include downscaling."""
+ video_file = 'media/big_buck_bunny_432_433.webm'
+ target_resolution = (128, 128)
+ video = VideoFileClip(video_file, target_resolution=target_resolution)
frame = video.get_frame(0)
assert frame.shape[0:2] == target_resolution
target_resolution = (128, None)
- video = VideoFileClip("media/big_buck_bunny_432_433.webm", target_resolution=target_resolution)
+ video = VideoFileClip(video_file, target_resolution=target_resolution)
frame = video.get_frame(0)
assert frame.shape[0] == target_resolution[0]
target_resolution = (None, 128)
- video = VideoFileClip("media/big_buck_bunny_432_433.webm", target_resolution=target_resolution)
+ video = VideoFileClip(video_file, target_resolution=target_resolution)
frame = video.get_frame(0)
assert frame.shape[1] == target_resolution[1]
# Test upscaling
target_resolution = (None, 2048)
- video = VideoFileClip("media/big_buck_bunny_432_433.webm", target_resolution=target_resolution)
+ video = VideoFileClip(video_file, target_resolution=target_resolution)
frame = video.get_frame(0)
assert frame.shape[1] == target_resolution[1]
diff --git a/tests/test_Videos.py b/tests/test_Videos.py
index 451a38e2..bd001a60 100644
--- a/tests/test_Videos.py
+++ b/tests/test_Videos.py
@@ -1,24 +1,30 @@
+# -*- coding: utf-8 -*-
+"""Video tests meant to be run with pytest."""
+import sys
+
import pytest
-from moviepy.editor import *
+from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
+from moviepy.video.fx.mask_color import mask_color
+from moviepy.video.VideoClip import ColorClip, ImageClip
-# must have to work on travis-ci
-import sys
-sys.path.append("tests")
import download_media
+sys.path.append("tests")
+
+
def test_download_media(capsys):
with capsys.disabled():
download_media.download()
def test_afterimage():
- ai=ImageClip("media/afterimage.png")
- masked_clip = vfx.mask_color(ai, color=[0,255,1]) # for green
+ ai = ImageClip("media/afterimage.png")
+ masked_clip = mask_color(ai, color=[0,255,1]) # for green
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
+ final_clip.duration = 5
final_clip.write_videofile("/tmp/afterimage.mp4", fps=30)
if __name__ == '__main__':
diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.py
index 9b8c6496..5f0d381e 100644
--- a/tests/test_ffmpeg_reader.py
+++ b/tests/test_ffmpeg_reader.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
"""FFmpeg reader tests meant to be run with pytest."""
import sys
diff --git a/tests/test_helper.py b/tests/test_helper.py
index 9b6f33c1..7913b44e 100644
--- a/tests/test_helper.py
+++ b/tests/test_helper.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+"""Define general test helper attributes and utilities."""
import os
import sys
diff --git a/tests/test_issues.py b/tests/test_issues.py
index b804e830..f226e78e 100644
--- a/tests/test_issues.py
+++ b/tests/test_issues.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
"""Issue tests meant to be run with pytest."""
import os
import sys
@@ -26,10 +27,10 @@ def test_issue_145():
concatenate_videoclips([video], method='composite')
def test_issue_285():
- clip_1 = ImageClip('media/python_logo.png', duration=10)
- clip_2 = ImageClip('media/python_logo.png', duration=10)
- clip_3 = ImageClip('media/python_logo.png', duration=10)
+ clip_1, clip_2, clip_3 = ImageClip('media/python_logo.png', duration=10), \
+ ImageClip('media/python_logo.png', duration=10), \
+ ImageClip('media/python_logo.png', duration=10)
merged_clip = concatenate_videoclips([clip_1, clip_2, clip_3])
assert merged_clip.duration == 30
diff --git a/tests/test_tools.py b/tests/test_tools.py
index 31cde521..b1510bb6 100644
--- a/tests/test_tools.py
+++ b/tests/test_tools.py
@@ -1,13 +1,14 @@
-import pytest
-import moviepy.tools as tools
+# -*- coding: utf-8 -*-
+"""Tool tests meant to be run with pytest. Taken from PR #121 (grimley517)."""
import sys
import time
-## taken from PR #121 (grimley517)
+import moviepy.tools as tools
+import pytest
def test_ext():
- '''Test for find_extension function'''
+ """Test for find_extension function."""
lefts = ['libx264', 'libmpeg4', 'libtheora', 'libvpx']
rights = ['mp4', 'mp4', 'ogv', 'webm']
for i in range(len(lefts)):
@@ -17,14 +18,13 @@ def test_ext():
assert left == right, message
def test_2():
- '''Tests for raising erre if codec not in dictionaries'''
+ """Test for raising erre if codec not in dictionaries."""
message = "asking for a silly video format did not Raise a Value Error"
with pytest.raises(ValueError, message=message):
tools.find_extension('flashvideo')
def test_3():
- '''tests the cvsecs funtion outputs the correct times
- as per the docstring'''
+ """Test the cvsecs funtion outputs correct times as per the docstring."""
lefts = [15.4, (1,21.5), (1,1,2), '01:01:33.5', '01:01:33.045' ]
rights = [15.4, 81.5, 3662, 3693.5, 3693.045]
for i in range(len(lefts)):
@@ -35,7 +35,7 @@ def test_3():
assert left == right, message
def test_4():
- '''tests the is_string function in tools'''
+ """Test the is_string function in tools."""
lefts = ["hello straight string", r'hello raw string',42, True ]
rights = [True, True, False, False]
for i in range(len(lefts)):
@@ -46,8 +46,7 @@ def test_4():
assert left == right, message
def test_4a():
- '''as for test 4 - but tests for the different behaviour of byte strings
- between python 2 and 3'''
+ """Test for the different behaviour of byte strings between python 2/3."""
version = sys.version_info[0]
answer = version < 3 #True for py2, else False
left = tools.is_string(b'hello bytes')
@@ -57,10 +56,12 @@ def test_4a():
assert left == right, message
def test_5():
- '''Tests for sys_write-flush function
- 1) checks that this works quickly,
- 2) checks that stdout has no content after flushing
- '''
+ """Test for sys_write-flush function.
+
+ 1) Check that this works quickly.
+ 2) Check that stdout has no content after flushing.
+
+ """
start = time.time()
tools.sys_write_flush("hello world")
myTime = time.time() - start
@@ -69,11 +70,13 @@ def test_5():
assert file == b""
def test_6():
- '''
- Tests subprocess_call for operation. the process sleep should run for
- a given time in seconds. This checks that the process has
- deallocated from the stack on completion of the called process
- '''
+ """Test subprocess_call for operation.
+
+ The process sleep should run for a given time in seconds.
+ This checks that the process has deallocated from the stack on
+ completion of the called process.
+
+ """
process = tools.subprocess_call(["sleep" , '1'])
time.sleep(1)
assert process is None
diff --git a/tests/tests.py b/tests/tests.py
deleted file mode 100644
index 3cd55af8..00000000
--- a/tests/tests.py
+++ /dev/null
@@ -1,18 +0,0 @@
-"""
-To run the tests:
- py.test tests.py
-"""
-
-from moviepy.editor import *
-
-#@pytest.fixture
-def test_if_TextClip_crashes_in_caption_mode():
- overlay = TextClip(txt='foo',
- color='white',
- size=(640, 480),
- method='caption',
- align='center',
- fontsize=25)
-
-def test_if_TextClip_crashes_in_label_mode():
- overlay = TextClip(txt='foo', method='label')