Skip to content

Commit

Permalink
Optimise test suite speed (Zulko#1463)
Browse files Browse the repository at this point in the history
* Optimise test suite speed

* Apply black
  • Loading branch information
tburrows13 authored Jan 17, 2021
1 parent 98805b5 commit ebd4925
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 27 deletions.
16 changes: 6 additions & 10 deletions media/subtitles.srt
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
0
00:00:00,000 --> 00:00:04,000
00:00:00,000 --> 00:00:01,000
Red!

1
00:00:05,000 --> 00:00:09,000
00:00:02,000 --> 00:00:03,500
More Red!

2
00:00:10,000 --> 00:00:14,000
00:00:5,000 --> 00:00:6,000
Green!

3
00:00:15,000 --> 00:00:19,000
More Green!

4
00:00:20,000 --> 00:00:24,000
00:00:7,000 --> 00:00:8,000
Blue

5
00:00:25,000 --> 00:00:29,000
4
00:00:9,000 --> 00:00:10,000
More Blue!

6 changes: 4 additions & 2 deletions tests/test_PR.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_PR_515():
def test_PR_528():
with ImageClip("media/vacation_2017.jpg") as clip:
new_clip = scroll(clip, w=1000, x_speed=50)
new_clip = new_clip.with_duration(1)
new_clip = new_clip.with_duration(0.2)
new_clip.fps = 24
new_clip.write_videofile(os.path.join(TMP_DIR, "pano.mp4"))

Expand All @@ -105,7 +105,9 @@ def test_PR_1137_video():
"""
Test support for path-like objects as arguments for VideoFileClip.
"""
with VideoFileClip(Path("media/big_buck_bunny_432_433.webm")) as video:
with VideoFileClip(Path("media/big_buck_bunny_432_433.webm")).subclip(
0.2, 0.4
) as video:
video.write_videofile(Path(TMP_DIR) / "pathlike.mp4")
assert isinstance(video.filename, str)

Expand Down
3 changes: 1 addition & 2 deletions tests/test_Videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def test_afterimage():
some_background_clip = ColorClip((800, 600), color=(255, 255, 255))
final_clip = CompositeVideoClip(
[some_background_clip, masked_clip], use_bgclip=True
)
final_clip.duration = 5
).with_duration(0.2)
final_clip.write_videofile(os.path.join(TMP_DIR, "afterimage.mp4"), fps=30)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_matplotlib_simple_example():
plt.switch_backend("agg")

x = np.linspace(-2, 2, 200)
duration = 2
duration = 0.5

fig, ax = plt.subplots()

Expand Down
9 changes: 5 additions & 4 deletions tests/test_fx.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,17 @@ def test_loop():
target3 = BitmapClip([["R"], ["G"], ["B"], ["R"], ["G"]], fps=1)
assert clip3 == target3

clip = get_test_video()
clip1 = loop(clip).with_duration(3) # infinite looping
clip = get_test_video().subclip(0.2, 0.3) # 0.1 seconds long
clip1 = loop(clip).with_duration(0.5) # infinite looping
clip1.write_videofile(os.path.join(TMP_DIR, "loop1.webm"))

clip2 = loop(clip, duration=10) # loop for 10 seconds
clip2 = loop(clip, duration=0.5) # loop for 1 second
clip2.write_videofile(os.path.join(TMP_DIR, "loop2.webm"))

clip3 = loop(clip, n=3) # loop 3 times
clip3.write_videofile(os.path.join(TMP_DIR, "loop3.webm"))

# Test audio looping
clip = AudioClip(
lambda t: np.sin(440 * 2 * np.pi * t) * (t % 1) + 0.5, duration=2.5, fps=44100
)
Expand Down Expand Up @@ -373,7 +374,7 @@ def test_painting():

def test_resize():
# TODO update to use BitmapClip
clip = get_test_video()
clip = get_test_video().subclip(0.2, 0.3)

clip1 = resize(clip, (460, 720)) # New resolution: (460,720)
assert clip1.size == (460, 720)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_issue_354():


def test_issue_359():
with ColorClip((800, 600), color=(255, 0, 0)).with_duration(5) as video:
with ColorClip((800, 600), color=(255, 0, 0)).with_duration(0.2) as video:
video.fps = 30
video.write_gif(filename=os.path.join(TMP_DIR, "issue_359.gif"), tempfiles=True)

Expand Down Expand Up @@ -301,7 +301,7 @@ def make_frame(t):

return mplfig_to_npimage(fig)

animation = VideoClip(make_frame, duration=2)
animation = VideoClip(make_frame, duration=0.2)
animation.write_gif(os.path.join(TMP_DIR, "svm.gif"), fps=20)


Expand Down
11 changes: 5 additions & 6 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@


MEDIA_SUBTITLES_DATA = [
([0.0, 4.0], "Red!"),
([5.0, 9.0], "More Red!"),
([10.0, 14.0], "Green!"),
([15.0, 19.0], "More Green!"),
([20.0, 24.0], "Blue"),
([25.0, 29.0], "More Blue!"),
([0.0, 1.0], "Red!"),
([2.0, 3.5], "More Red!"),
([5.0, 6.0], "Green!"),
([7.0, 8.0], "Blue"),
([9.0, 10.0], "More Blue!"),
]

MEDIA_SUBTITLES_UNICODE_DATA = [
Expand Down

0 comments on commit ebd4925

Please sign in to comment.