forked from Zulko/moviepy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_examples.py
43 lines (28 loc) · 927 Bytes
/
test_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""MoviePy examples tests."""
import os
import numpy as np
import pytest
from moviepy.video.io.bindings import mplfig_to_npimage
from moviepy.video.VideoClip import VideoClip
try:
import matplotlib.pyplot
except ImportError:
matplotlib = None
else:
matplotlib = True
@pytest.mark.skipif(not matplotlib, reason="no matplotlib")
def test_matplotlib_simple_example(util):
import matplotlib.pyplot as plt
plt.switch_backend("Agg")
x = np.linspace(-2, 2, 200)
duration = 0.5
fig, ax = plt.subplots()
def make_frame(t):
ax.clear()
ax.plot(x, np.sinc(x**2) + np.sin(x + 2 * np.pi / duration * t), lw=3)
ax.set_ylim(-1.5, 2.5)
return mplfig_to_npimage(fig)
animation = VideoClip(make_frame, duration=duration)
filename = os.path.join(util.TMP_DIR, "matplotlib.gif")
animation.write_gif(filename, fps=20)
assert os.path.isfile(filename)