Skip to content

Commit bded061

Browse files
committed
added more tests, fixed potential problem in converters
#205
1 parent c81a863 commit bded061

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

musicalgestures/_utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def convert_to_avi(filename, target_name=None, overwrite=False):
372372

373373
import os
374374
of, fex = os.path.splitext(filename)
375-
if fex == '.avi':
375+
if fex.lower() == '.avi':
376376
print(f'{filename} is already in avi container.')
377377
return filename
378378
if not target_name:
@@ -400,7 +400,7 @@ def convert_to_mp4(filename, target_name=None, overwrite=False):
400400

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

428428
import os
429429
of, fex = os.path.splitext(filename)
430-
if fex == '.webm':
430+
if fex.lower() == '.webm':
431431
print(f'{filename} is already in webm container.')
432432
return filename
433433
if not target_name:

tests/test_utils.py

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
# %%
2-
# import sys
3-
# sys.path.append('../')
41
import musicalgestures
52
from musicalgestures._utils import *
63
import numpy as np
74
import os
85
import pytest
96

10-
# %%
11-
127

138
class Test_MgProgressbar:
149
def test_init(self):
@@ -138,8 +133,44 @@ def testvideo_mp4(tmp_path_factory):
138133
return testvideo_mp4
139134

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

148+
@pytest.fixture(scope="class")
149+
def testvideo_avi(tmp_path_factory):
150+
target_name = str(tmp_path_factory.mktemp("data")).replace("\\", "/") + "/testvideo.avi"
151+
testvideo_avi = extract_subclip(musicalgestures.examples.dance, 5, 6, target_name=target_name)
152+
return testvideo_avi
153+
154+
class Test_convert_to_mp4:
155+
def test_output(self, tmp_path, testvideo_avi):
156+
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_converted.mp4"
157+
testvideo_mp4 = convert_to_mp4(testvideo_avi, target_name=target_name)
158+
length_in = get_length(testvideo_avi)
159+
length_out = get_length(testvideo_mp4)
160+
assert os.path.isfile(testvideo_mp4) == True
161+
assert os.path.splitext(testvideo_mp4)[1] == ".mp4"
162+
assert target_name == testvideo_mp4
163+
assert length_in == length_out
164+
165+
166+
class Test_convert_to_webm:
167+
@pytest.mark.xfail(raises=AssertionError)
168+
def test_output(self, tmp_path, testvideo_avi):
169+
target_name = str(tmp_path).replace("\\", "/") + "/testvideo_converted.webm"
170+
testvideo_webm = convert_to_webm(testvideo_avi, target_name=target_name)
171+
length_in = get_length(testvideo_avi)
172+
length_out = get_length(testvideo_webm)
173+
assert os.path.isfile(testvideo_webm) == True
174+
assert os.path.splitext(testvideo_webm)[1] == ".webm"
175+
assert target_name == testvideo_webm
176+
assert length_in == length_out # this will fail, need to find out why

0 commit comments

Comments
 (0)