Video editing with Python
General tests cleanup
Mark Beacoma3efe9f83cf0
diff --git a/tests/test_ImageSequenceClip.py b/tests/test_ImageSequenceClip.pyindex 79473f33..b74a63be 100644--- a/tests/test_ImageSequenceClip.py+++ b/tests/test_ImageSequenceClip.py@@ -1,11 +1,14 @@+"""Image sequencing clip tests meant to be run with pytest."""+import sys+import pytest-from moviepy.editor import *+from moviepy.video.io import ImageSequenceClip-# 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()@@ -19,7 +22,7 @@ def test_1():durations.append(i)images.append("media/matplotlib_demo1.png")- clip=ImageSequenceClip(images, durations=durations)+ clip = ImageSequenceClip(images, durations=durations)assert clip.duration == sum(durations)clip.write_videofile("/tmp/ImageSequenceClip1.mp4", fps=30)diff --git a/tests/test_examples.py b/tests/test_examples.pyindex 3b81101b..b9bc5235 100644--- a/tests/test_examples.py+++ b/tests/test_examples.py@@ -1,24 +1,22 @@-import pytest-from moviepy.editor import *-import moviepy.video.tools.cuts as cuts-import osimport sys-sys.path.append("tests")++import pytest+import download_mediafrom test_helper import PYTHON_VERSION, TMP_DIR, TRAVIS+sys.path.append("tests")++def test_download_media(capsys):with capsys.disabled():download_media.download()def test_matplotlib():- if PYTHON_VERSION in ('2.7', '3.3'):- return-#for now, python 3.5 installs a version of matplotlib that complains#about $DISPLAY variable, so lets just ignore for now.- if PYTHON_VERSION == '3.5' and TRAVIS:+ if PYTHON_VERSION in ('2.7', '3.3') or (PYTHON_VERSION == '3.5' and TRAVIS):returnimport matplotlib.pyplot as pltdiff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.pyindex d7ac41d5..9b8c6496 100644--- a/tests/test_ffmpeg_reader.py+++ b/tests/test_ffmpeg_reader.py@@ -1,12 +1,14 @@-import pytest-from moviepy.editor import *+"""FFmpeg reader tests meant to be run with pytest."""+import sys+import pytestfrom moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos-import sys-sys.path.append("tests")import download_media+sys.path.append("tests")++def test_download_media(capsys):with capsys.disabled():download_media.download()diff --git a/tests/test_fx.py b/tests/test_fx.pyindex 6e29d057..4a82d19c 100644--- a/tests/test_fx.py+++ b/tests/test_fx.py@@ -1,18 +1,19 @@-import pytest-from moviepy.editor import *+import os+import sys-from moviepy.video.fx.crop import crop+import pytestfrom moviepy.video.fx.blackwhite import blackwhite-from moviepy.video.fx.blink import blink+# from moviepy.video.fx.blink import blinkfrom moviepy.video.fx.colorx import colorx+from moviepy.video.fx.crop import cropfrom moviepy.video.fx.fadein import fadeinfrom moviepy.video.fx.fadeout import fadeout+from moviepy.video.VideoClip import VideoFileClip-import os-import sys-sys.path.append("tests")import download_media-from test_helper import TRAVIS, TMP_DIR+from test_helper import TMP_DIR++sys.path.append("tests")def test_download_media(capsys):@@ -24,19 +25,17 @@ def test_blackwhite():clip1 = blackwhite(clip)clip1.write_videofile(os.path.join(TMP_DIR,"blackwhite1.webm"))-def test_blink():- #this currently fails with a with_mask error!- return- clip = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0,10)- clip1 = blink(clip, 1, 1)- clip1.write_videofile(os.path.join(TMP_DIR,"blink1.webm"))+# This currently fails with a with_mask error!+# def test_blink():+# clip = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0,10)+# clip1 = blink(clip, 1, 1)+# clip1.write_videofile(os.path.join(TMP_DIR,"blink1.webm"))def test_colorx():clip = VideoFileClip("media/big_buck_bunny_432_433.webm")clip1 = colorx(clip, 2)clip1.write_videofile(os.path.join(TMP_DIR,"colorx1.webm"))-def test_crop():clip = VideoFileClip("media/big_buck_bunny_432_433.webm")diff --git a/tests/test_helper.py b/tests/test_helper.pyindex de076593..9b6f33c1 100644--- a/tests/test_helper.py+++ b/tests/test_helper.py@@ -4,4 +4,3 @@ import sysTRAVIS=os.getenv("TRAVIS_PYTHON_VERSION") is not NonePYTHON_VERSION = "%s.%s" % (sys.version_info.major, sys.version_info.minor)TMP_DIR="/tmp"-diff --git a/tests/test_issues.py b/tests/test_issues.pyindex a854d9c4..b804e830 100644--- a/tests/test_issues.py+++ b/tests/test_issues.py@@ -1,25 +1,29 @@-"""-Tests meant to be run with pytest-"""-+"""Issue tests meant to be run with pytest."""import os-import pytest+import sys-from moviepy.editor import *+import pytest+from moviepy.audio.io.AudioFileClip import AudioFileClip+from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip+from moviepy.video.compositing.concatenate import concatenate_videoclips+from moviepy.video.fx import blink, resize+from moviepy.video.io.VideoFileClip import VideoFileClip+from moviepy.video.VideoClip import ColorClip, ImageClip, VideoClip-import sys-sys.path.append("tests")import download_mediafrom test_helper import PYTHON_VERSION, TMP_DIR, TRAVIS+sys.path.append("tests")++def test_download_media(capsys):with capsys.disabled():download_media.download()def test_issue_145():video = ColorClip((800, 600), color=(255,0,0)).set_duration(5)- with pytest.raises(Exception, message="Expecting Exception"):- final = concatenate_videoclips([video], method = 'composite')+ with pytest.raises(Exception, message='Expecting Exception'):+ concatenate_videoclips([video], method='composite')def test_issue_285():clip_1 = ImageClip('media/python_logo.png', duration=10)@@ -29,15 +33,55 @@ def test_issue_285():merged_clip = concatenate_videoclips([clip_1, clip_2, clip_3])assert merged_clip.duration == 30-def test_issue_334():last_move = Nonelast_move1 = None- lis = [(0.0, 113, 167, 47), (0.32, 138, 159, 47), (0.44, 152, 144, 47), (0.48, 193, 148, 47), (0.6, 193, 148, 47), (0.76, 205, 138, 55), (0.88, 204, 121, 63), (0.92, 190, 31, 127), (1.2, 183, 59, 127), (1.4, 137, 22, 127), (1.52, 137, 22, 127), (1.72, 129, 67, 127), (1.88, 123, 69, 127), (2.04, 131, 123, 63), (2.24, 130, 148, 63), (2.48, 130, 148, 63), (2.8, 138, 180, 63), (3.0, 138, 180, 63), (3.2, 146, 192, 63), (3.28, 105, 91, 151), (3.44, 105, 91, 151), (3.72, 11, 48, 151), (3.96, 5, 78, 151), (4.32, 4, 134, 1), (4.6, 149, 184, 48), (4.8, 145, 188, 48), (5.0, 154, 217, 48), (5.08, 163, 199, 48), (5.2, 163, 199, 48), (5.32, 164, 187, 48), (5.48, 163, 200, 48), (5.76, 163, 200, 48), (5.96, 173, 199, 48), (6.0, 133, 172, 48), (6.04, 128, 165, 48), (6.28, 128, 165, 48), (6.4, 129, 180, 48), (6.52, 133, 166, 48), (6.64, 133, 166, 48), (6.88, 144, 183, 48), (7.0, 153, 174, 48), (7.16, 153, 174, 48), (7.24, 153, 174, 48), (7.28, 253, 65, 104), (7.64, 253, 65, 104), (7.8, 279, 116, 80), (8.0, 290, 105, 80), (8.24, 288, 124, 80), (8.44, 243, 102, 80), (8.56, 243, 102, 80), (8.8, 202, 107, 80), (8.84, 164, 27, 104), (9.0, 164, 27, 104), (9.12, 121, 9, 104), (9.28, 77, 33, 104), (9.32, 52, 23, 104), (9.48, 52, 23, 104), (9.64, 33, 46, 104), (9.8, 93, 49, 104), (9.92, 93, 49, 104), (10.16, 173, 19, 104), (10.2, 226, 173, 48), (10.36, 226, 173, 48), (10.48, 211, 172, 48), (10.64, 208, 162, 48), (10.92, 220, 171, 48)]-- lis1 = [(0.0, 113, 167, 47), (0.32, 138, 159, 47), (0.44, 152, 144, 47), (0.48, 193, 148, 47), (0.6, 193, 148, 47), (0.76, 205, 138, 55), (0.88, 204, 121, 63), (0.92, 190, 31, 127), (1.2, 183, 59, 127), (1.4, 137, 22, 127), (1.52, 137, 22, 127), (1.72, 129, 67, 127), (1.88, 123, 69, 127), (2.04, 131, 123, 63), (2.24, 130, 148, 63), (2.48, 130, 148, 63), (2.8, 138, 180, 63), (3.0, 138, 180, 63), (3.2, 146, 192, 63), (3.28, 105, 91, 151), (3.44, 105, 91, 151), (3.72, 11, 48, 151), (3.96, 5, 78, 151), (4.32, 4, 134, 1), (4.6, 149, 184, 48), (4.8, 145, 188, 48), (5.0, 154, 217, 48), (5.08, 163, 199, 48), (5.2, 163, 199, 48), (5.32, 164, 187, 48), (5.48, 163, 200, 48), (5.76, 163, 200, 48), (5.96, 173, 199, 48), (6.0, 133, 172, 48), (6.04, 128, 165, 48), (6.28, 128, 165, 48), (6.4, 129, 180, 48), (6.52, 133, 166, 48), (6.64, 133, 166, 48), (6.88, 144, 183, 48), (7.0, 153, 174, 48), (7.16, 153, 174, 48), (7.24, 153, 174, 48), (7.28, 253, 65, 104), (7.64, 253, 65, 104), (7.8, 279, 116, 80), (8.0, 290, 105, 80), (8.24, 288, 124, 80), (8.44, 243, 102, 80), (8.56, 243, 102, 80), (8.8, 202, 107, 80), (8.84, 164, 27, 104), (9.0, 164, 27, 104), (9.12, 121, 9, 104), (9.28, 77, 33, 104), (9.32, 52, 23, 104), (9.48, 52, 23, 104), (9.64, 33, 46, 104), (9.8, 93, 49, 104), (9.92, 93, 49, 104), (10.16, 173, 19, 104), (10.2, 226, 173, 48), (10.36, 226, 173, 48), (10.48, 211, 172, 48), (10.64, 208, 162, 48), (10.92, 220, 171, 48)]-+ lis = [(0.0, 113, 167, 47), (0.32, 138, 159, 47), (0.44, 152, 144, 47),+ (0.48, 193, 148, 47), (0.6, 193, 148, 47), (0.76, 205, 138, 55),+ (0.88, 204, 121, 63), (0.92, 190, 31, 127), (1.2, 183, 59, 127),+ (1.4, 137, 22, 127), (1.52, 137, 22, 127), (1.72, 129, 67, 127),+ (1.88, 123, 69, 127), (2.04, 131, 123, 63), (2.24, 130, 148, 63),+ (2.48, 130, 148, 63), (2.8, 138, 180, 63), (3.0, 138, 180, 63),+ (3.2, 146, 192, 63), (3.28, 105, 91, 151), (3.44, 105, 91, 151),+ (3.72, 11, 48, 151), (3.96, 5, 78, 151), (4.32, 4, 134, 1),+ (4.6, 149, 184, 48), (4.8, 145, 188, 48), (5.0, 154, 217, 48),+ (5.08, 163, 199, 48), (5.2, 163, 199, 48), (5.32, 164, 187, 48),+ (5.48, 163, 200, 48), (5.76, 163, 200, 48), (5.96, 173, 199, 48),+ (6.0, 133, 172, 48), (6.04, 128, 165, 48), (6.28, 128, 165, 48),+ (6.4, 129, 180, 48), (6.52, 133, 166, 48), (6.64, 133, 166, 48),+ (6.88, 144, 183, 48), (7.0, 153, 174, 48), (7.16, 153, 174, 48),+ (7.24, 153, 174, 48), (7.28, 253, 65, 104), (7.64, 253, 65, 104),+ (7.8, 279, 116, 80), (8.0, 290, 105, 80), (8.24, 288, 124, 80),+ (8.44, 243, 102, 80), (8.56, 243, 102, 80), (8.8, 202, 107, 80),+ (8.84, 164, 27, 104), (9.0, 164, 27, 104), (9.12, 121, 9, 104),+ (9.28, 77, 33, 104), (9.32, 52, 23, 104), (9.48, 52, 23, 104),+ (9.64, 33, 46, 104), (9.8, 93, 49, 104), (9.92, 93, 49, 104),+ (10.16, 173, 19, 104), (10.2, 226, 173, 48), (10.36, 226, 173, 48),+ (10.48, 211, 172, 48), (10.64, 208, 162, 48), (10.92, 220, 171, 48)]++ lis1 = [(0.0, 113, 167, 47), (0.32, 138, 159, 47), (0.44, 152, 144, 47),+ (0.48, 193, 148, 47), (0.6, 193, 148, 47), (0.76, 205, 138, 55),+ (0.88, 204, 121, 63), (0.92, 190, 31, 127), (1.2, 183, 59, 127),+ (1.4, 137, 22, 127), (1.52, 137, 22, 127), (1.72, 129, 67, 127),+ (1.88, 123, 69, 127), (2.04, 131, 123, 63), (2.24, 130, 148, 63),+ (2.48, 130, 148, 63), (2.8, 138, 180, 63), (3.0, 138, 180, 63),+ (3.2, 146, 192, 63), (3.28, 105, 91, 151), (3.44, 105, 91, 151),+ (3.72, 11, 48, 151), (3.96, 5, 78, 151), (4.32, 4, 134, 1),+ (4.6, 149, 184, 48), (4.8, 145, 188, 48), (5.0, 154, 217, 48),+ (5.08, 163, 199, 48), (5.2, 163, 199, 48), (5.32, 164, 187, 48),+ (5.48, 163, 200, 48), (5.76, 163, 200, 48), (5.96, 173, 199, 48),+ (6.0, 133, 172, 48), (6.04, 128, 165, 48), (6.28, 128, 165, 48),+ (6.4, 129, 180, 48), (6.52, 133, 166, 48), (6.64, 133, 166, 48),+ (6.88, 144, 183, 48), (7.0, 153, 174, 48), (7.16, 153, 174, 48),+ (7.24, 153, 174, 48), (7.28, 253, 65, 104), (7.64, 253, 65, 104),+ (7.8, 279, 116, 80), (8.0, 290, 105, 80), (8.24, 288, 124, 80),+ (8.44, 243, 102, 80), (8.56, 243, 102, 80), (8.8, 202, 107, 80),+ (8.84, 164, 27, 104), (9.0, 164, 27, 104), (9.12, 121, 9, 104),+ (9.28, 77, 33, 104), (9.32, 52, 23, 104), (9.48, 52, 23, 104),+ (9.64, 33, 46, 104), (9.8, 93, 49, 104), (9.92, 93, 49, 104),+ (10.16, 173, 19, 104), (10.2, 226, 173, 48), (10.36, 226, 173, 48),+ (10.48, 211, 172, 48), (10.64, 208, 162, 48), (10.92, 220, 171, 48)]def posi(t):global last_move@@ -74,17 +118,15 @@ def test_issue_334():return (nsw, nsh)return (last_move1[3], last_move1[3] * 1.33)-avatar = VideoFileClip("media/big_buck_bunny_432_433.webm", has_mask=True)avatar.audio=Nonemaskclip = ImageClip("media/afterimage.png", ismask=True, transparent=True)avatar.set_mask(maskclip) #must set maskclip here..- avatar = concatenate([avatar]*11)+ avatar = concatenate_videoclips([avatar]*11)tt = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0,11)- #setting mask here does not work.- #final = CompositeVideoClip([tt, avatar.set_position(posi).set_mask(maskclip).resize(size)])+ # TODO: Setting mask here does not work: .set_mask(maskclip).resize(size)])final = CompositeVideoClip([tt, avatar.set_position(posi).resize(size)])final.duration = tt.durationfinal.write_videofile(os.path.join(TMP_DIR, 'issue_334.mp4'), fps=24)@@ -95,10 +137,16 @@ def test_issue_354():clip.duration = 10crosstime = 1- #caption = editor.TextClip("test text", font="Liberation-Sans-Bold", color='white', stroke_color='gray', stroke_width=2, method='caption', size=(1280, 720), fontsize=60, align='South-East')+ # TODO: Should this be removed?+ # caption = editor.TextClip("test text", font="Liberation-Sans-Bold",+ # color='white', stroke_color='gray',+ # stroke_width=2, method='caption',+ # size=(1280, 720), fontsize=60,+ # align='South-East')#caption.duration = clip.duration+fadecaption = clip.crossfadein(crosstime).crossfadeout(crosstime)- ret = CompositeVideoClip([clip, fadecaption])+ CompositeVideoClip([clip, fadecaption])def test_issue_359():video = ColorClip((800, 600), color=(255,0,0)).set_duration(5)@@ -107,12 +155,8 @@ def test_issue_359():tempfiles=True)def test_issue_368():- import sys- if PYTHON_VERSION in ('2.7', '3.3'): #matplotlib only supported in python >= 3.4- return-- #travis, python 3.5 matplotlib version has problems..- if PYTHON_VERSION == '3.5' and TRAVIS:+ # Matplotlib only supported in python >= 3.4 and Travis/3.5 fails.+ if PYTHON_VERSION in ('2.7', '3.3') or (PYTHON_VERSION == '3.5' and TRAVIS):returnimport numpy as np@@ -120,7 +164,6 @@ def test_issue_368():from sklearn import svmfrom sklearn.datasets import make_moonsfrom moviepy.video.io.bindings import mplfig_to_npimage- import imageioX, Y = make_moons(50, noise=0.1, random_state=2) # semi-random data@@ -145,20 +188,21 @@ def test_issue_368():return mplfig_to_npimage(fig)- animation = VideoClip(make_frame,duration=2)- animation.write_gif(os.path.join(TMP_DIR, "svm.gif"),fps=20)+ animation = VideoClip(make_frame, duration=2)+ animation.write_gif(os.path.join(TMP_DIR, "svm.gif"), fps=20)def test_issue_407():red = ColorClip((800, 600), color=(255,0,0)).set_duration(5)- red.fps=30+ red.fps = 30+assert red.fps == 30assert red.w == 800assert red.h == 600assert red.size == (800, 600)- #ColorClip has no fps attribute- green=ColorClip((640, 480), color=(0,255,0)).set_duration(2)- blue=ColorClip((640, 480), color=(0,0,255)).set_duration(2)+ # ColorClip has no fps attribute.+ green = ColorClip((640, 480), color=(0,255,0)).set_duration(2)+ blue = ColorClip((640, 480), color=(0,0,255)).set_duration(2)assert green.w == blue.w == 640assert green.h == blue.h == 480@@ -174,16 +218,16 @@ def test_issue_407():assert video.fps == red.fpsdef test_issue_416():- green=ColorClip((640, 480), color=(0,255,0)).set_duration(2) #ColorClip has no fps attribute- video1=concatenate_videoclips([green])+ # ColorClip has no fps attribute.+ green = ColorClip((640, 480), color=(0,255,0)).set_duration(2)+ video1 = concatenate_videoclips([green])assert video1.fps == Nonedef test_issue_417():# failed in python2-cad = u'media/python_logo.png'- myclip = ImageClip(cad).fx(vfx.resize, newsize=[1280, 660])- final = CompositeVideoClip([myclip], size=(1280, 720))+ myclip = ImageClip(cad).fx(resize, newsize=[1280, 660])+ CompositeVideoClip([myclip], size=(1280, 720))#final.set_duration(7).write_videofile("test.mp4", fps=30)def test_issue_467():@@ -191,7 +235,7 @@ def test_issue_467():clip = ImageClip(cad)#caused an error, NameError: global name 'copy' is not defined- clip = clip.fx(vfx.blink, d_on=1, d_off=1)+ clip = clip.fx(blink, d_on=1, d_off=1)def test_issue_470():audio_clip = AudioFileClip('media/crunching.mp3')diff --git a/tests/test_misc.py b/tests/test_misc.pyindex dfeee7cb..b52e4fe6 100644--- a/tests/test_misc.py+++ b/tests/test_misc.py@@ -1,12 +1,17 @@-import pytest-from moviepy.editor import *-import moviepy.video.tools.cuts as cuts-import osimport sys-sys.path.append("tests")++import moviepy.video.tools.cuts as cuts+import pytest+from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip+from moviepy.video.compositing.concatenate import concatenate_videoclips+from moviepy.video.tools.subtitles import SubtitlesClip, file_to_subtitles+from moviepy.video.VideoClip import ColorClip, TextClip, VideoFileClip+import download_media-from test_helper import TRAVIS, TMP_DIR+from test_helper import TMP_DIR, TRAVIS++sys.path.append("tests")def test_download_media(capsys):@@ -18,8 +23,6 @@ def test_cuts1():cuts.find_video_period(clip) == pytest.approx(0.966666666667, 0.0001)def test_subtitles():- from moviepy.video.tools.subtitles import SubtitlesClip-red = ColorClip((800, 600), color=(255,0,0)).set_duration(10)green = ColorClip((800, 600), color=(0,255,0)).set_duration(10)blue = ColorClip((800, 600), color=(0,0,255)).set_duration(10)@@ -50,8 +53,6 @@ def test_subtitles():assert subtitles.subtitles == datadef test_file_to_subtitles():- from moviepy.video.tools.subtitles import file_to_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!')]