-
Notifications
You must be signed in to change notification settings - Fork 43
/
test_celluloid.py
88 lines (64 loc) · 2.07 KB
/
test_celluloid.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""Test animations."""
# pylint: disable=wrong-import-position
import numpy as np
import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt
from celluloid import Camera
def test_single():
"""Test plt.figure()"""
fig = plt.figure()
camera = Camera(fig)
for _ in range(10):
plt.plot(range(5))
plt.plot(-np.arange(5))
artists = camera.snap()
assert len(artists) == 2
# pylint: disable=protected-access
assert sum(len(x) for x in camera._photos) == 2 * 10
anim = camera.animate()
assert len(list(anim.frame_seq)) == 10
def test_two_axes():
"""Test subplots."""
fig, axes = plt.subplots(2)
camera = Camera(fig)
axes[0].plot(np.zeros(100))
axes[1].plot(np.zeros(100))
artists = camera.snap()
assert len(artists) == 2
axes[0].plot(np.ones(100))
axes[1].plot(np.ones(100))
artists = camera.snap()
# pylint: disable=protected-access
assert sum(len(x) for x in camera._photos) == 4
anim = camera.animate()
assert len(list(anim.frame_seq)) == 2
def test_legends():
"""Test subplots."""
camera = Camera(plt.figure())
plt.legend(plt.plot(range(5)), ['hello'])
artists = camera.snap()
assert len(artists) == 2
plt.legend(plt.plot(range(5)), ['world'])
artists = camera.snap()
assert len(artists) == 2
# pylint: disable=protected-access
assert camera._photos[0][1].texts[0]._text == 'hello'
assert camera._photos[1][1].texts[0]._text == 'world'
# pylint: disable=protected-access
assert sum(len(x) for x in camera._photos) == 4
anim = camera.animate()
assert len(list(anim.frame_seq)) == 2
def test_images():
"""Test subplots."""
camera = Camera(plt.figure())
plt.imshow(np.ones((5, 5)))
artists = camera.snap()
assert len(artists) == 1
plt.imshow(np.zeros((5, 5)))
artists = camera.snap()
assert len(artists) == 1
# pylint: disable=protected-access
assert sum(len(x) for x in camera._photos) == 2
anim = camera.animate()
assert len(list(anim.frame_seq)) == 2