From cc9144214872b83d25810f84f464721f86dfeff0 Mon Sep 17 00:00:00 2001 From: Billy Earney Date: Tue, 28 Feb 2017 07:31:36 -0600 Subject: [PATCH 1/3] add test for tools (#450) * add coveralls to travis.yml * add coveralls python module * add pytest-cov python module * add pytest-cov python module * add pytest-cov python module * add coverage * modify .coverage * travis * remove coverage * remove coverage * remove coverage * remove coverage * remove coverage * remove coverage * remove coverage * remove coverage * remove coverage * remove coverage * remove coverage * remove coverage * __init__.py needed for pytest-cov and coverage to play nicely * change concatenation to concatenate_videoclips * test tools --- .travis.yml | 8 ++++- tests/__init__.py | 0 tests/test_issues.py | 2 +- tests/test_tools.py | 82 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_tools.py diff --git a/.travis.yml b/.travis.yml index 445e9f41c..f0fb6b1b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,12 @@ before_install: - sudo apt-get install -y ffmpeg - mkdir media install: + - pip install coveralls + - pip install pytest-cov - python setup.py install # command to run tests -script: py.test +before_script: + - py.test tests/ --cov +script: py.test tests/ --doctest-modules -v --cov moviepy --cov-report term-missing +after_success: + - coveralls diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_issues.py b/tests/test_issues.py index 9b932fb69..7bd3cae42 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -30,7 +30,7 @@ def test_download_media(capsys): def test_issue_145(): _video = ColorClip((800, 600), col=(255,0,0)).set_duration(5) with pytest.raises(Exception, message="Expecting Exception"): - _final = concatenation([_video], method = 'composite') + _final = concatenate_videoclips([_video], method = 'composite') def test_issue_407(): _red = ColorClip((800, 600), col=(255,0,0)).set_duration(5) diff --git a/tests/test_tools.py b/tests/test_tools.py new file mode 100644 index 000000000..21efeb34f --- /dev/null +++ b/tests/test_tools.py @@ -0,0 +1,82 @@ +import pytest +import moviepy.tools as tools +import sys +import time + +## taken from PR #121 (grimley517) + + +def test_ext(): + '''Test for find_extension function''' + lefts = ['libx264', 'libmpeg4', 'libtheora', 'libvpx'] + rights = ['mp4', 'mp4', 'ogv', 'webm'] + for i in range(len(lefts)): + left = tools.find_extension(lefts[i]) + right = rights[i] + message = "{0} did not get associated with {1}".format(left, right) + assert left == right, message + +def test_2(): + '''Tests 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''' + 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)): + left = tools.cvsecs(lefts[i]) + right = rights[i] + message = "{0} resulted in {1}, but {2} was expected"\ + .format(lefts[i],left, right) + assert left == right, message + +def test_4(): + '''tests 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)): + left = tools.is_string(lefts[i]) + right = rights[i] + message = "{0} resulted in {1}, but {2} was expected"\ + .format(lefts[i],left, right) + 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''' + version = sys.version_info[0] + answer = version < 3 #True for py2, else False + left = tools.is_string(b'hello bytes') + right = answer + message = "{0} resulted in {1}, but {2} was expected"\ + .format(b'hello bytes',left, right) + 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 + ''' + start = time.time() + tools.sys_write_flush("hello world") + myTime = time.time() - start + assert myTime < 0.0001 + file = sys.stdout.read() + 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 + ''' + process = tools.subprocess_call(["sleep" , '1']) + time.sleep(1) + assert process is None + +if __name__ == '__main__': + pytest.main() From 3ef911b06a9a0b155bff793cc1c52af06c007591 Mon Sep 17 00:00:00 2001 From: Billy Earney Date: Tue, 28 Feb 2017 07:36:22 -0600 Subject: [PATCH 2/3] fix issue 448; AudioFileClip 90k tbr error (#449) --- moviepy/video/io/ffmpeg_reader.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.py index 836fb6a8f..6ac83c32e 100644 --- a/moviepy/video/io/ffmpeg_reader.py +++ b/moviepy/video/io/ffmpeg_reader.py @@ -273,8 +273,6 @@ def ffmpeg_parse_infos(filename, print_infos=False, check_duration=True): result['video_found'] = ( lines_video != [] ) if result['video_found']: - - try: line = lines_video[0] @@ -295,9 +293,14 @@ def ffmpeg_parse_infos(filename, print_infos=False, check_duration=True): try: match = re.search("( [0-9]*.| )[0-9]* tbr", line) - tbr = float(line[match.start():match.end()].split(' ')[1]) - result['video_fps'] = tbr + s_tbr = line[match.start():match.end()].split(' ')[1] + if "k" in s_tbr: + tbr = float(s_tbr.replace("k", "")) * 1000 + else: + tbr = float(s_tbr) + + result['video_fps'] = tbr except: match = re.search("( [0-9]*.| )[0-9]* fps", line) result['video_fps'] = float(line[match.start():match.end()].split(' ')[1]) From cadfd833bf085e081458c2649ae0c15492f5d688 Mon Sep 17 00:00:00 2001 From: Billy Earney Date: Thu, 2 Mar 2017 10:16:22 -0600 Subject: [PATCH 3/3] change ColorClips col argument to color in tests --- tests/test_VideoFileClip.py | 8 ++++---- tests/test_compositing.py | 12 ++++++------ tests/test_issues.py | 13 +++++++------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/test_VideoFileClip.py b/tests/test_VideoFileClip.py index d8f272be2..992677f66 100644 --- a/tests/test_VideoFileClip.py +++ b/tests/test_VideoFileClip.py @@ -3,9 +3,9 @@ import os def test_setup(): - red = ColorClip((1024,800), col=(255,0,0)) - green = ColorClip((1024,800), col=(0,255,0)) - blue = ColorClip((1024,800), col=(0,0,255)) + 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 video = clips_array([[red, green, blue]]).set_duration(5) @@ -19,4 +19,4 @@ def test_setup(): assert clip.size == [1024*3, 800] if __name__ == '__main__': - pytest.main() \ No newline at end of file + pytest.main() diff --git a/tests/test_compositing.py b/tests/test_compositing.py index e3cf73f3e..a1f4bd527 100644 --- a/tests/test_compositing.py +++ b/tests/test_compositing.py @@ -2,9 +2,9 @@ from moviepy.editor import * def test_clips_array(): - red = ColorClip((1024,800), col=(255,0,0)) - green = ColorClip((1024,800), col=(0,255,0)) - blue = ColorClip((1024,800), col=(0,0,255)) + red = ColorClip((1024,800), color=(255,0,0)) + green = ColorClip((1024,800), color=(0,255,0)) + blue = ColorClip((1024,800), color=(0,0,255)) video = clips_array([[red, green, blue]]) @@ -14,9 +14,9 @@ def test_clips_array(): def test_clips_array(): - red = ColorClip((1024,800), col=(255,0,0)) - green = ColorClip((1024,800), col=(0,255,0)) - blue = ColorClip((1024,800), col=(0,0,255)) + red = ColorClip((1024,800), color=(255,0,0)) + green = ColorClip((1024,800), color=(0,255,0)) + blue = ColorClip((1024,800), color=(0,0,255)) video = clips_array([[red, green, blue]]).set_duration(5) diff --git a/tests/test_issues.py b/tests/test_issues.py index 38bf7562a..1e7679880 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -17,23 +17,24 @@ def test_download_media(capsys): download_media.download() def test_issue_145(): - video = ColorClip((800, 600), col=(255,0,0)).set_duration(5) + video = ColorClip((800, 600), color=(255,0,0)).set_duration(5) with pytest.raises(Exception, message="Expecting Exception"): - final = concatenate_videoclips([_video], method = 'composite') + final = concatenate_videoclips([video], method = 'composite') def test_issue_407(): - red = ColorClip((800, 600), col=(255,0,0)).set_duration(5) + red = ColorClip((800, 600), color=(255,0,0)).set_duration(5) red.fps=30 assert round(red.fps) == 30 - green=ColorClip((640, 480), col=(0,255,0)).set_duration(2) #ColorClip has no fps attribute - blue=ColorClip((640, 480), col=(0,0,255)).set_duration(2) #ColorClip has no fps attribute + #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) video=concatenate_videoclips([red, green, blue]) assert video.fps == red.fps def test_issue_416(): - green=ColorClip((640, 480), col=(0,255,0)).set_duration(2) #ColorClip has no fps attribute + green=ColorClip((640, 480), color=(0,255,0)).set_duration(2) #ColorClip has no fps attribute video1=concatenate_videoclips([green]) assert video1.fps == None