Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1808472

Browse files
committed
test code clean up
1 parent d89a93d commit 1808472

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

lib/matplotlib/animation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,9 @@ def _draw_frame(self, framedata):
17161716
# Call the func with framedata and args. If blitting is desired,
17171717
# func needs to return a sequence of any artists that were modified.
17181718
self._drawn_artists = self._func(framedata, *self._args)
1719+
17191720
if self._blit:
1721+
17201722
err = RuntimeError('The animation function must return a '
17211723
'sequence of Artist objects.')
17221724
try:

lib/matplotlib/tests/test_animation.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import matplotlib as mpl
1111
from matplotlib import pyplot as plt
1212
from matplotlib import animation
13+
from matplotlib import artist
1314

1415

1516
class NullMovieWriter(animation.AbstractMovieWriter):
@@ -280,32 +281,29 @@ def test_draw_frame():
280281
fig, ax = plt.subplots()
281282
line, = ax.plot([])
282283

283-
def init():
284-
pass
284+
def animate(i, arg):
285+
# general update func
286+
line.set_data([0, 1], [0, i])
287+
if arg:
288+
return arg
289+
290+
with pytest.raises(RuntimeError):
285291

286-
def animate_case_1(i):
287292
# user forgot to return (returns None)
288-
line.set_data([0, 1], [0, i])
289-
# return line
293+
animation.FuncAnimation(fig, animate, blit=True, fargs=(None,))
290294

291-
def animate_case_2(i):
292-
# user forgot to put comma or return a sequence
293-
# TypeError will be raised (same with returning a number or bool)
294-
line.set_data([0, 1], [0, i])
295-
return line
295+
# user (for some reason) returned a string...AttributeError is raised
296+
animation.FuncAnimation(fig, animate, blit=True, fargs=('string', ))
296297

297-
def animate_case_3(i):
298298
# user (for some reason) returned a string...AttributeError is raised
299-
line.set_data([0, 1], [0, i])
300-
return 'a string'
299+
animation.FuncAnimation(fig, animate, blit=True, fargs=(1, ))
301300

302-
def animate_case_4(i):
303-
# user returns a sequence other objects instead of Artist.
304-
line.set_data([0, 1], [0, i])
305-
return 'a string',
301+
# user returns a sequence of other objects
302+
# e.g. a string instead of Artist
303+
animation.FuncAnimation(fig, animate, blit=True, fargs=(('string',), ))
306304

307-
with pytest.raises(RuntimeError) as context:
308-
animation.FuncAnimation(fig, animate_case_1, blit=True)
309-
animation.FuncAnimation(fig, animate_case_2, blit=True)
310-
animation.FuncAnimation(fig, animate_case_3, blit=True)
311-
animation.FuncAnimation(fig, animate_case_4, blit=True)
305+
# user forgot to put comma or return a sequence
306+
# TypeError will be raised (same with returning a number or bool)
307+
artist_obj = artist.Artist()
308+
animation.FuncAnimation(fig, animate, blit=True, fargs=(artist_obj, ))
309+

0 commit comments

Comments
 (0)