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

Skip to content

Commit 8a3f1dd

Browse files
committed
Fix and simplify test_draw_frame.
The `pytest.raises` context should have the exception-raising code as the very last line. Anything that follows is ignored, since the exception stops execution. This means that the second and subsequent checks in `test_draw_frame` are not run. So, parametrize the test so that doesn't happen.
1 parent fd41efc commit 8a3f1dd

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

lib/matplotlib/tests/test_animation.py

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

1514

1615
class NullMovieWriter(animation.AbstractMovieWriter):
@@ -275,34 +274,32 @@ def frames_generator():
275274
assert (f() is None) != cache_frame_data
276275

277276

278-
def test_draw_frame():
277+
@pytest.mark.parametrize('return_value', [
278+
# User forgot to return (returns None).
279+
None,
280+
# User returned a string.
281+
'string',
282+
# User returned an int.
283+
1,
284+
# User returns a sequence of other objects, e.g., string instead of Artist.
285+
('string', ),
286+
# User forgot to return a sequence (handled in `animate` below.)
287+
'artist',
288+
])
289+
def test_draw_frame(return_value):
279290
# test _draw_frame method
280291

281292
fig, ax = plt.subplots()
282293
line, = ax.plot([])
283294

284-
def animate(i, arg):
295+
def animate(i):
285296
# general update func
286297
line.set_data([0, 1], [0, i])
287-
if arg:
288-
return arg
298+
if return_value == 'artist':
299+
# *not* a sequence
300+
return line
301+
else:
302+
return return_value
289303

290304
with pytest.raises(RuntimeError):
291-
292-
# user forgot to return (returns None)
293-
animation.FuncAnimation(fig, animate, blit=True, fargs=(None,))
294-
295-
# user (for some reason) returned a string...AttributeError is raised
296-
animation.FuncAnimation(fig, animate, blit=True, fargs=('string', ))
297-
298-
# user (for some reason) returned a string...AttributeError is raised
299-
animation.FuncAnimation(fig, animate, blit=True, fargs=(1, ))
300-
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',), ))
304-
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, ))
305+
animation.FuncAnimation(fig, animate, blit=True)

0 commit comments

Comments
 (0)