Video editing with Python
Additional tests cleanup
Mark Beacome8bf1456c78a
diff --git a/tests/README.rst b/tests/README.rstindex 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.pyindex 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 sysdiff --git a/tests/test_TextClip.py b/tests/test_TextClip.pyindex 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 syssys.path.append("tests")-import download_mediadef 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.pyindex 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 = 30video = 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_resolutiontarget_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 upscalingtarget_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.pyindex 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 greensome_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 = 5final_clip.write_videofile("/tmp/afterimage.mp4", fps=30)if __name__ == '__main__':diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.pyindex 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 sysdiff --git a/tests/test_helper.py b/tests/test_helper.pyindex 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 osimport sysdiff --git a/tests/test_issues.py b/tests/test_issues.pyindex 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 osimport 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 == 30diff --git a/tests/test_tools.py b/tests/test_tools.pyindex 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 sysimport time-## taken from PR #121 (grimley517)+import moviepy.tools as tools+import pytestdef 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, messagedef 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, messagedef 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, messagedef 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 Falseleft = tools.is_string(b'hello bytes')@@ -57,10 +56,12 @@ def test_4a():assert left == right, messagedef 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 Nonediff --git a/tests/tests.py b/tests/tests.pydeleted file mode 100644index 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')