Skip to content

Commit

Permalink
added more tests, fixed potential problem in converters
Browse files Browse the repository at this point in the history
  • Loading branch information
balintlaczko committed Sep 29, 2021
1 parent c81a863 commit bded061
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
6 changes: 3 additions & 3 deletions musicalgestures/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def convert_to_avi(filename, target_name=None, overwrite=False):

import os
of, fex = os.path.splitext(filename)
if fex == '.avi':
if fex.lower() == '.avi':
print(f'{filename} is already in avi container.')
return filename
if not target_name:
Expand Down Expand Up @@ -400,7 +400,7 @@ def convert_to_mp4(filename, target_name=None, overwrite=False):

import os
of, fex = os.path.splitext(filename)
if fex == '.mp4':
if fex.lower() == '.mp4':
print(f'{filename} is already in mp4 container.')
return filename
if not target_name:
Expand All @@ -427,7 +427,7 @@ def convert_to_webm(filename, target_name=None, overwrite=False):

import os
of, fex = os.path.splitext(filename)
if fex == '.webm':
if fex.lower() == '.webm':
print(f'{filename} is already in webm container.')
return filename
if not target_name:
Expand Down
41 changes: 36 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# %%
# import sys
# sys.path.append('../')
import musicalgestures
from musicalgestures._utils import *
import numpy as np
import os
import pytest

# %%


class Test_MgProgressbar:
def test_init(self):
Expand Down Expand Up @@ -138,8 +133,44 @@ def testvideo_mp4(tmp_path_factory):
return testvideo_mp4

class Test_convert_to_avi:
@pytest.mark.xfail(raises=AssertionError)
def test_output(self, tmp_path, testvideo_mp4):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_converted.avi"
testvideo_avi = convert_to_avi(testvideo_mp4, target_name=target_name)
length_in = get_length(testvideo_mp4)
length_out = get_length(testvideo_avi)
assert os.path.isfile(testvideo_avi) == True
assert os.path.splitext(testvideo_avi)[1] == ".avi"
assert target_name == testvideo_avi
assert length_in == length_out # this will fail due to ffmpeg bug: https://trac.ffmpeg.org/ticket/9443#ticket


@pytest.fixture(scope="class")
def testvideo_avi(tmp_path_factory):
target_name = str(tmp_path_factory.mktemp("data")).replace("\\", "/") + "/testvideo.avi"
testvideo_avi = extract_subclip(musicalgestures.examples.dance, 5, 6, target_name=target_name)
return testvideo_avi

class Test_convert_to_mp4:
def test_output(self, tmp_path, testvideo_avi):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_converted.mp4"
testvideo_mp4 = convert_to_mp4(testvideo_avi, target_name=target_name)
length_in = get_length(testvideo_avi)
length_out = get_length(testvideo_mp4)
assert os.path.isfile(testvideo_mp4) == True
assert os.path.splitext(testvideo_mp4)[1] == ".mp4"
assert target_name == testvideo_mp4
assert length_in == length_out


class Test_convert_to_webm:
@pytest.mark.xfail(raises=AssertionError)
def test_output(self, tmp_path, testvideo_avi):
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_converted.webm"
testvideo_webm = convert_to_webm(testvideo_avi, target_name=target_name)
length_in = get_length(testvideo_avi)
length_out = get_length(testvideo_webm)
assert os.path.isfile(testvideo_webm) == True
assert os.path.splitext(testvideo_webm)[1] == ".webm"
assert target_name == testvideo_webm
assert length_in == length_out # this will fail, need to find out why

0 comments on commit bded061

Please sign in to comment.