1
1
import pytest
2
2
import moviepy as mpy
3
- from vidtoolz_apply_fadein_fadeout .applyfadeinfadeout import apply_fade_effect
3
+ from vidtoolz_apply_fadein_fadeout .applyfadeinfadeout import apply_fade_effect
4
4
import vidtoolz_apply_fadein_fadeout as w
5
5
6
6
from argparse import Namespace , ArgumentParser
7
7
8
+
8
9
def test_create_parser ():
9
10
subparser = ArgumentParser ().add_subparsers ()
10
11
parser = w .create_parser (subparser )
11
12
12
13
assert parser is not None
13
14
14
- result = parser .parse_args ([' test.mp4' , ' fadein' ])
15
+ result = parser .parse_args ([" test.mp4" , " fadein" ])
15
16
assert result .video == "test.mp4"
16
17
assert result .fade_type == "fadein"
17
18
assert result .duration == 1
@@ -24,11 +25,13 @@ def test_plugin(capsys):
24
25
assert "Hello! This is an example ``vidtoolz`` plugin." in captured .out
25
26
26
27
27
-
28
28
@pytest .fixture
29
29
def sample_clip ():
30
30
"""Create a short test video clip."""
31
- return mpy .ColorClip (size = (640 , 480 ), color = (255 , 0 , 0 ), duration = 5 ).with_fps (30 ) # Red video
31
+ return mpy .ColorClip (size = (640 , 480 ), color = (255 , 0 , 0 ), duration = 5 ).with_fps (
32
+ 30
33
+ ) # Red video
34
+
32
35
33
36
@pytest .mark .parametrize ("fade_type" , ["fadein" , "fadeout" , "both" ])
34
37
def test_apply_fade_effect_with_clip (sample_clip , fade_type ):
@@ -37,30 +40,38 @@ def test_apply_fade_effect_with_clip(sample_clip, fade_type):
37
40
processed_clip , fps = apply_fade_effect (sample_clip , fade_type , duration )
38
41
39
42
assert isinstance (processed_clip , mpy .VideoClip ), "Output should be a VideoClip"
40
- assert processed_clip .duration == sample_clip .duration , "Clip duration should remain unchanged"
43
+ assert (
44
+ processed_clip .duration == sample_clip .duration
45
+ ), "Clip duration should remain unchanged"
41
46
assert fps == sample_clip .fps , "FPS should be preserved"
42
47
43
48
sample_clip .close ()
44
49
processed_clip .close ()
45
50
51
+
46
52
@pytest .mark .parametrize ("fade_type" , ["fadein" , "fadeout" , "both" ])
47
53
def test_apply_fade_effect_with_path (tmp_path , fade_type ):
48
54
"""Test fade effects using a file path."""
49
55
test_video_path = str (tmp_path / "test.mp4" )
50
- sample_clip = mpy .ColorClip (size = (640 , 480 ), color = (255 , 0 , 0 ), duration = 5 ).with_fps (30 )
56
+ sample_clip = mpy .ColorClip (
57
+ size = (640 , 480 ), color = (255 , 0 , 0 ), duration = 5
58
+ ).with_fps (30 )
51
59
sample_clip .write_videofile (test_video_path , codec = "libx264" , fps = 30 , audio = False )
52
60
53
61
duration = 1 # 1-second fade duration
54
62
processed_clip , fps = apply_fade_effect (test_video_path , fade_type , duration )
55
63
56
64
assert isinstance (processed_clip , mpy .VideoClip ), "Output should be a VideoClip"
57
- assert processed_clip .duration == sample_clip .duration , "Clip duration should remain unchanged"
65
+ assert (
66
+ processed_clip .duration == sample_clip .duration
67
+ ), "Clip duration should remain unchanged"
58
68
assert fps == sample_clip .fps , "FPS should be preserved"
59
69
60
70
sample_clip .close ()
61
71
processed_clip .close ()
62
72
73
+
63
74
def test_invalid_fade_type (sample_clip ):
64
75
"""Test with an invalid fade type."""
65
76
with pytest .raises (ValueError , match = "Invalid fade type" ):
66
- apply_fade_effect (sample_clip , "invalid_type" , 1 )
77
+ apply_fade_effect (sample_clip , "invalid_type" , 1 )
0 commit comments