back to SWE-Agent summary
SWE-Agent: moviepy
Pytest Summary for test tests
status |
count |
failed |
20 |
passed |
1 |
total |
21 |
collected |
21 |
Failed pytests:
test_tools.py::test_find_extensions[libx264-mp4]
given = 'libx264', expected = 'mp4'
@pytest.mark.parametrize('given, expected', [
("libx264", "mp4"),
("libmpeg4", "mp4"),
("libtheora", "ogv"),
("libvpx", "webm")
])
def test_find_extensions(given, expected):
"""Test for find_extension function."""
> assert tools.find_extension(given) == expected
E AttributeError: module 'moviepy.tools' has no attribute 'find_extension'
tests/test_tools.py:18: AttributeError
test_tools.py::test_find_extensions[libmpeg4-mp4]
given = 'libmpeg4', expected = 'mp4'
@pytest.mark.parametrize('given, expected', [
("libx264", "mp4"),
("libmpeg4", "mp4"),
("libtheora", "ogv"),
("libvpx", "webm")
])
def test_find_extensions(given, expected):
"""Test for find_extension function."""
> assert tools.find_extension(given) == expected
E AttributeError: module 'moviepy.tools' has no attribute 'find_extension'
tests/test_tools.py:18: AttributeError
test_tools.py::test_find_extensions[libtheora-ogv]
given = 'libtheora', expected = 'ogv'
@pytest.mark.parametrize('given, expected', [
("libx264", "mp4"),
("libmpeg4", "mp4"),
("libtheora", "ogv"),
("libvpx", "webm")
])
def test_find_extensions(given, expected):
"""Test for find_extension function."""
> assert tools.find_extension(given) == expected
E AttributeError: module 'moviepy.tools' has no attribute 'find_extension'
tests/test_tools.py:18: AttributeError
test_tools.py::test_find_extensions[libvpx-webm]
given = 'libvpx', expected = 'webm'
@pytest.mark.parametrize('given, expected', [
("libx264", "mp4"),
("libmpeg4", "mp4"),
("libtheora", "ogv"),
("libvpx", "webm")
])
def test_find_extensions(given, expected):
"""Test for find_extension function."""
> assert tools.find_extension(given) == expected
E AttributeError: module 'moviepy.tools' has no attribute 'find_extension'
tests/test_tools.py:18: AttributeError
test_tools.py::test_find_extensions_not_found
def test_find_extensions_not_found():
"""Test for raising error if codec not in dictionaries."""
with pytest.raises(ValueError): # asking for a silly video format
> tools.find_extension('flashvideo')
E AttributeError: module 'moviepy.tools' has no attribute 'find_extension'
tests/test_tools.py:24: AttributeError
test_tools.py::test_cvsecs[15.4-15.4]
given = 15.4, expected = 15.4
@pytest.mark.parametrize('given, expected', [
(15.4, 15.4),
((1, 21.5), 81.5),
((1, 1, 2), 3662),
([1, 1, 2], 3662),
('01:01:33.5', 3693.5),
('01:01:33.045', 3693.045),
('01:01:33,5', 3693.5),
('1:33', 93.0),
('33.4', 33.4),
(None, None)
])
def test_cvsecs(given, expected):
"""Test the cvsecs funtion outputs correct times as per the docstring."""
> assert tools.cvsecs(given) == expected
E assert None == 15.4
E + where None = (15.4)
E + where = tools.cvsecs
tests/test_tools.py:42: AssertionError
test_tools.py::test_cvsecs[given1-81.5]
given = (1, 21.5), expected = 81.5
@pytest.mark.parametrize('given, expected', [
(15.4, 15.4),
((1, 21.5), 81.5),
((1, 1, 2), 3662),
([1, 1, 2], 3662),
('01:01:33.5', 3693.5),
('01:01:33.045', 3693.045),
('01:01:33,5', 3693.5),
('1:33', 93.0),
('33.4', 33.4),
(None, None)
])
def test_cvsecs(given, expected):
"""Test the cvsecs funtion outputs correct times as per the docstring."""
> assert tools.cvsecs(given) == expected
E assert None == 81.5
E + where None = ((1, 21.5))
E + where = tools.cvsecs
tests/test_tools.py:42: AssertionError
test_tools.py::test_cvsecs[given2-3662]
given = (1, 1, 2), expected = 3662
@pytest.mark.parametrize('given, expected', [
(15.4, 15.4),
((1, 21.5), 81.5),
((1, 1, 2), 3662),
([1, 1, 2], 3662),
('01:01:33.5', 3693.5),
('01:01:33.045', 3693.045),
('01:01:33,5', 3693.5),
('1:33', 93.0),
('33.4', 33.4),
(None, None)
])
def test_cvsecs(given, expected):
"""Test the cvsecs funtion outputs correct times as per the docstring."""
> assert tools.cvsecs(given) == expected
E assert None == 3662
E + where None = ((1, 1, 2))
E + where = tools.cvsecs
tests/test_tools.py:42: AssertionError
test_tools.py::test_cvsecs[given3-3662]
given = [1, 1, 2], expected = 3662
@pytest.mark.parametrize('given, expected', [
(15.4, 15.4),
((1, 21.5), 81.5),
((1, 1, 2), 3662),
([1, 1, 2], 3662),
('01:01:33.5', 3693.5),
('01:01:33.045', 3693.045),
('01:01:33,5', 3693.5),
('1:33', 93.0),
('33.4', 33.4),
(None, None)
])
def test_cvsecs(given, expected):
"""Test the cvsecs funtion outputs correct times as per the docstring."""
> assert tools.cvsecs(given) == expected
E assert None == 3662
E + where None = ([1, 1, 2])
E + where = tools.cvsecs
tests/test_tools.py:42: AssertionError
test_tools.py::test_cvsecs[01:01:33.5-3693.5]
given = '01:01:33.5', expected = 3693.5
@pytest.mark.parametrize('given, expected', [
(15.4, 15.4),
((1, 21.5), 81.5),
((1, 1, 2), 3662),
([1, 1, 2], 3662),
('01:01:33.5', 3693.5),
('01:01:33.045', 3693.045),
('01:01:33,5', 3693.5),
('1:33', 93.0),
('33.4', 33.4),
(None, None)
])
def test_cvsecs(given, expected):
"""Test the cvsecs funtion outputs correct times as per the docstring."""
> assert tools.cvsecs(given) == expected
E AssertionError: assert None == 3693.5
E + where None = ('01:01:33.5')
E + where = tools.cvsecs
tests/test_tools.py:42: AssertionError
test_tools.py::test_cvsecs[01:01:33.045-3693.045]
given = '01:01:33.045', expected = 3693.045
@pytest.mark.parametrize('given, expected', [
(15.4, 15.4),
((1, 21.5), 81.5),
((1, 1, 2), 3662),
([1, 1, 2], 3662),
('01:01:33.5', 3693.5),
('01:01:33.045', 3693.045),
('01:01:33,5', 3693.5),
('1:33', 93.0),
('33.4', 33.4),
(None, None)
])
def test_cvsecs(given, expected):
"""Test the cvsecs funtion outputs correct times as per the docstring."""
> assert tools.cvsecs(given) == expected
E AssertionError: assert None == 3693.045
E + where None = ('01:01:33.045')
E + where = tools.cvsecs
tests/test_tools.py:42: AssertionError
test_tools.py::test_cvsecs[01:01:33,5-3693.5]
given = '01:01:33,5', expected = 3693.5
@pytest.mark.parametrize('given, expected', [
(15.4, 15.4),
((1, 21.5), 81.5),
((1, 1, 2), 3662),
([1, 1, 2], 3662),
('01:01:33.5', 3693.5),
('01:01:33.045', 3693.045),
('01:01:33,5', 3693.5),
('1:33', 93.0),
('33.4', 33.4),
(None, None)
])
def test_cvsecs(given, expected):
"""Test the cvsecs funtion outputs correct times as per the docstring."""
> assert tools.cvsecs(given) == expected
E AssertionError: assert None == 3693.5
E + where None = ('01:01:33,5')
E + where = tools.cvsecs
tests/test_tools.py:42: AssertionError
test_tools.py::test_cvsecs[1:33-93.0]
given = '1:33', expected = 93.0
@pytest.mark.parametrize('given, expected', [
(15.4, 15.4),
((1, 21.5), 81.5),
((1, 1, 2), 3662),
([1, 1, 2], 3662),
('01:01:33.5', 3693.5),
('01:01:33.045', 3693.045),
('01:01:33,5', 3693.5),
('1:33', 93.0),
('33.4', 33.4),
(None, None)
])
def test_cvsecs(given, expected):
"""Test the cvsecs funtion outputs correct times as per the docstring."""
> assert tools.cvsecs(given) == expected
E AssertionError: assert None == 93.0
E + where None = ('1:33')
E + where = tools.cvsecs
tests/test_tools.py:42: AssertionError
test_tools.py::test_cvsecs[33.4-33.4]
given = '33.4', expected = 33.4
@pytest.mark.parametrize('given, expected', [
(15.4, 15.4),
((1, 21.5), 81.5),
((1, 1, 2), 3662),
([1, 1, 2], 3662),
('01:01:33.5', 3693.5),
('01:01:33.045', 3693.045),
('01:01:33,5', 3693.5),
('1:33', 93.0),
('33.4', 33.4),
(None, None)
])
def test_cvsecs(given, expected):
"""Test the cvsecs funtion outputs correct times as per the docstring."""
> assert tools.cvsecs(given) == expected
E AssertionError: assert None == 33.4
E + where None = ('33.4')
E + where = tools.cvsecs
tests/test_tools.py:42: AssertionError
test_tools.py::test_is_string[hello straight string-True]
given = 'hello straight string', expected = True
@pytest.mark.parametrize("given, expected", [
("hello straight string", True),
(r'hello raw string', True),
(42, False),
(True, False),
(b'hello bytes', sys.version_info[0] < 3),
])
def test_is_string(given, expected):
"""Test the is_string function in tools."""
> assert tools.is_string(given) == expected
E AssertionError: assert None == True
E + where None = ('hello straight string')
E + where = tools.is_string
tests/test_tools.py:54: AssertionError
test_tools.py::test_is_string[hello raw string-True]
given = 'hello raw string', expected = True
@pytest.mark.parametrize("given, expected", [
("hello straight string", True),
(r'hello raw string', True),
(42, False),
(True, False),
(b'hello bytes', sys.version_info[0] < 3),
])
def test_is_string(given, expected):
"""Test the is_string function in tools."""
> assert tools.is_string(given) == expected
E AssertionError: assert None == True
E + where None = ('hello raw string')
E + where = tools.is_string
tests/test_tools.py:54: AssertionError
test_tools.py::test_is_string[42-False]
given = 42, expected = False
@pytest.mark.parametrize("given, expected", [
("hello straight string", True),
(r'hello raw string', True),
(42, False),
(True, False),
(b'hello bytes', sys.version_info[0] < 3),
])
def test_is_string(given, expected):
"""Test the is_string function in tools."""
> assert tools.is_string(given) == expected
E assert None == False
E + where None = (42)
E + where = tools.is_string
tests/test_tools.py:54: AssertionError
test_tools.py::test_is_string[True-False]
given = True, expected = False
@pytest.mark.parametrize("given, expected", [
("hello straight string", True),
(r'hello raw string', True),
(42, False),
(True, False),
(b'hello bytes', sys.version_info[0] < 3),
])
def test_is_string(given, expected):
"""Test the is_string function in tools."""
> assert tools.is_string(given) == expected
E assert None == False
E + where None = (True)
E + where = tools.is_string
tests/test_tools.py:54: AssertionError
test_tools.py::test_is_string[hello bytes-False]
given = b'hello bytes', expected = False
@pytest.mark.parametrize("given, expected", [
("hello straight string", True),
(r'hello raw string', True),
(42, False),
(True, False),
(b'hello bytes', sys.version_info[0] < 3),
])
def test_is_string(given, expected):
"""Test the is_string function in tools."""
> assert tools.is_string(given) == expected
E AssertionError: assert None == False
E + where None = (b'hello bytes')
E + where = tools.is_string
tests/test_tools.py:54: AssertionError
test_tools.py::test_sys_write_flush
def test_sys_write_flush():
"""Test for sys_write-flush function. Check that stdout has no content after flushing."""
tools.sys_write_flush("hello world")
file = sys.stdout.read()
> assert file == b""
E AssertionError: assert '' == b''
tests/test_tools.py:62: AssertionError
Patch diff
diff --git a/moviepy/Clip.py b/moviepy/Clip.py
index da22c72..b5706bb 100644
--- a/moviepy/Clip.py
+++ b/moviepy/Clip.py
@@ -59,7 +59,15 @@ class Clip:
Gets a numpy array representing the RGB picture of the clip at time t
or (mono or stereo) value for a sound clip
"""
- pass
+ if self.memoize:
+ if t == self.memoized_t:
+ return self.memoized_frame
+ frame = self.make_frame(t)
+ self.memoized_t = t
+ self.memoized_frame = frame
+ return frame
+ else:
+ return self.make_frame(t)
def fl(self, fun, apply_to=None, keep_duration=True):
""" General processing of a clip.
@@ -98,7 +106,30 @@ class Clip:
>>> newclip = clip.fl(fl, apply_to='mask')
"""
- pass
+ newclip = self.copy()
+
+ def new_make_frame(t):
+ return fun(self.get_frame, t)
+
+ newclip.make_frame = new_make_frame
+
+ if not keep_duration:
+ newclip.duration = None
+ newclip.end = None
+
+ if apply_to is None:
+ apply_to = []
+ elif isinstance(apply_to, str):
+ apply_to = [apply_to]
+
+ for attr in apply_to:
+ if hasattr(newclip, attr):
+ a = getattr(newclip, attr)
+ if a is not None:
+ new_a = a.fl(fun, keep_duration=keep_duration)
+ setattr(newclip, attr, new_a)
+
+ return newclip
def fl_time(self, t_func, apply_to=None, keep_duration=False):
"""
@@ -133,6 +164,7 @@ class Clip:
"""
pass
+ @outplace
def fx(self, func, *args, **kwargs):
"""
@@ -154,7 +186,7 @@ class Clip:
>>> resize( volumex( mirrorx( clip ), 0.5), 0.3)
"""
- pass
+ return func(self, *args, **kwargs)
@apply_to_mask
@apply_to_audio
@@ -178,7 +210,20 @@ class Clip:
These changes are also applied to the ``audio`` and ``mask``
clips of the current clip, if they exist.
"""
- pass
+ self.start = t
+ if self.duration is not None:
+ if change_end:
+ self.end = t + self.duration
+ else:
+ self.duration = self.end - self.start
+
+ # Apply changes to audio and mask if they exist
+ if hasattr(self, 'audio') and self.audio is not None:
+ self.audio = self.audio.set_start(t, change_end)
+ if hasattr(self, 'mask') and self.mask is not None:
+ self.mask = self.mask.set_start(t, change_end)
+
+ return self
@apply_to_mask
@apply_to_audio
@@ -192,7 +237,20 @@ class Clip:
Also sets the duration of the mask and audio, if any,
of the returned clip.
"""
- pass
+ self.end = t
+ if self.start is None:
+ if self.duration is not None:
+ self.start = max(0, t - self.duration)
+ else:
+ self.duration = self.end - self.start
+
+ # Apply changes to audio and mask if they exist
+ if hasattr(self, 'audio') and self.audio is not None:
+ self.audio = self.audio.set_end(t)
+ if hasattr(self, 'mask') and self.mask is not None:
+ self.mask = self.mask.set_end(t)
+
+ return self
@apply_to_mask
@apply_to_audio
@@ -209,7 +267,21 @@ class Clip:
be modified in function of the duration and the preset end
of the clip.
"""
- pass
+ self.duration = t
+ if change_end:
+ self.end = self.start + t if self.start is not None else t
+ else:
+ if self.end is None:
+ raise ValueError("Cannot change duration of a clip with undefined end.")
+ self.start = self.end - t
+
+ # Apply changes to audio and mask if they exist
+ if hasattr(self, 'audio') and self.audio is not None:
+ self.audio = self.audio.set_duration(t, change_end)
+ if hasattr(self, 'mask') and self.mask is not None:
+ self.mask = self.mask.set_duration(t, change_end)
+
+ return self
@outplace
def set_make_frame(self, make_frame):
@@ -217,28 +289,29 @@ class Clip:
Sets a ``make_frame`` attribute for the clip. Useful for setting
arbitrary/complicated videoclips.
"""
- pass
+ self.make_frame = make_frame
+ return self
- @outplace
def set_fps(self, fps):
""" Returns a copy of the clip with a new default fps for functions like
write_videofile, iterframe, etc. """
- pass
+ self.fps = fps
+ return self
- @outplace
def set_ismask(self, ismask):
- """ Says wheter the clip is a mask or not (ismask is a boolean)"""
- pass
+ """ Says whether the clip is a mask or not (ismask is a boolean)"""
+ self.ismask = ismask
+ return self
@outplace
def set_memoize(self, memoize):
- """ Sets wheter the clip should keep the last frame read in memory """
- pass
+ """ Sets whether the clip should keep the last frame read in memory """
+ self.memoize = memoize
+ return self
@convert_to_seconds(['t'])
def is_playing(self, t):
"""
-
If t is a time, returns true if t is between the start and
the end of the clip. t can be expressed in seconds (15.35),
in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'.
@@ -246,7 +319,12 @@ class Clip:
theclip, else returns a vector [b_1, b_2, b_3...] where b_i
is true iff tti is in the clip.
"""
- pass
+ if isinstance(t, np.ndarray):
+ # vectorize is_playing
+ return np.vectorize(self.is_playing)(t)
+
+ return (((self.start is None) or (t >= self.start)) and
+ ((self.end is None) or (t <= self.end)))
@convert_to_seconds(['t_start', 't_end'])
@apply_to_mask
@@ -272,7 +350,27 @@ class Clip:
subclips of ``mask`` and ``audio`` the original clip, if
they exist.
"""
- pass
+ if t_start < 0:
+ t_start = self.duration + t_start
+ if t_end is None:
+ t_end = self.duration
+ elif t_end < 0:
+ t_end = self.duration + t_end
+
+ newclip = self.copy()
+
+ if self.duration is not None:
+ newclip.duration = t_end - t_start
+
+ newclip.start = self.start + t_start if self.start is not None else t_start
+ newclip.end = self.start + t_end if self.start is not None else t_end
+
+ if hasattr(newclip, 'audio') and newclip.audio is not None:
+ newclip.audio = newclip.audio.subclip(t_start, t_end)
+ if hasattr(newclip, 'mask') and newclip.mask is not None:
+ newclip.mask = newclip.mask.subclip(t_start, t_end)
+
+ return newclip
@apply_to_mask
@apply_to_audio
@@ -290,7 +388,27 @@ class Clip:
The resulting clip's ``audio`` and ``mask`` will also be cutout
if they exist.
"""
- pass
+ newclip = self.copy()
+ if self.duration is not None:
+ newclip.duration = self.duration - (tb - ta)
+
+ # Create a new make_frame function that skips the cutout
+ original_make_frame = newclip.make_frame
+ def new_make_frame(t):
+ if t < ta:
+ return original_make_frame(t)
+ else:
+ return original_make_frame(t + (tb - ta))
+
+ newclip.make_frame = new_make_frame
+
+ # Apply cutout to mask and audio if they exist
+ if hasattr(newclip, 'audio') and newclip.audio is not None:
+ newclip.audio = newclip.audio.cutout(ta, tb)
+ if hasattr(newclip, 'mask') and newclip.mask is not None:
+ newclip.mask = newclip.mask.cutout(ta, tb)
+
+ return newclip
@requires_duration
@use_clip_fps_by_default
@@ -320,15 +438,39 @@ class Clip:
for frame in myclip.iter_frames()])
"""
pass
+ # Implementation:
+ # if fps is None:
+ # fps = self.fps
+ # if fps is None:
+ # raise ValueError("No fps attribute specified")
+ #
+ # if dtype is None:
+ # dtype = self.dtype if hasattr(self, 'dtype') else 'uint8'
+ #
+ # t = 0
+ # while t < self.duration:
+ # frame = self.get_frame(t)
+ # if with_times:
+ # yield t, frame.astype(dtype)
+ # else:
+ # yield frame.astype(dtype)
+ # t += 1.0 / fps
+ # if logger is not None:
+ # logger(t=t, duration=self.duration, fps=fps, logger=logger)
def close(self):
"""
Release any resources that are in use.
"""
pass
+ # Implementation:
+ # if hasattr(self, 'audio') and self.audio is not None:
+ # self.audio.close()
+ # if hasattr(self, 'mask') and self.mask is not None:
+ # self.mask.close()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
- self.close()
\ No newline at end of file
+ self.close()