|
1 | 1 | import os
|
2 | 2 | from pathlib import Path
|
3 | 3 | import platform
|
| 4 | +import re |
4 | 5 | import subprocess
|
5 | 6 | import sys
|
6 | 7 | import weakref
|
@@ -233,8 +234,11 @@ def test_animation_repr_html(writer, html, want, anim):
|
233 | 234 | assert want in html
|
234 | 235 |
|
235 | 236 |
|
236 |
| -@pytest.mark.parametrize('anim', [dict(frames=iter(range(5)))], |
237 |
| - indirect=['anim']) |
| 237 | +@pytest.mark.parametrize( |
| 238 | + 'anim', |
| 239 | + [{'save_count': 10, 'frames': iter(range(5))}], |
| 240 | + indirect=['anim'] |
| 241 | +) |
238 | 242 | def test_no_length_frames(anim):
|
239 | 243 | anim.save('unused.null', writer=NullMovieWriter())
|
240 | 244 |
|
@@ -330,9 +334,11 @@ def frames_generator():
|
330 | 334 |
|
331 | 335 | yield frame
|
332 | 336 |
|
| 337 | + MAX_FRAMES = 100 |
333 | 338 | anim = animation.FuncAnimation(fig, animate, init_func=init,
|
334 | 339 | frames=frames_generator,
|
335 |
| - cache_frame_data=cache_frame_data) |
| 340 | + cache_frame_data=cache_frame_data, |
| 341 | + save_count=MAX_FRAMES) |
336 | 342 |
|
337 | 343 | writer = NullMovieWriter()
|
338 | 344 | anim.save('unused.null', writer=writer)
|
@@ -372,7 +378,9 @@ def animate(i):
|
372 | 378 | return return_value
|
373 | 379 |
|
374 | 380 | with pytest.raises(RuntimeError):
|
375 |
| - animation.FuncAnimation(fig, animate, blit=True) |
| 381 | + animation.FuncAnimation( |
| 382 | + fig, animate, blit=True, cache_frame_data=False |
| 383 | + ) |
376 | 384 |
|
377 | 385 |
|
378 | 386 | def test_exhausted_animation(tmpdir):
|
@@ -440,3 +448,61 @@ def animate(i):
|
440 | 448 |
|
441 | 449 | # 5th frame's data
|
442 | 450 | ax.plot(x, np.sin(x + 4 / 100))
|
| 451 | + |
| 452 | + |
| 453 | +@pytest.mark.parametrize('anim', [dict(klass=dict)], indirect=['anim']) |
| 454 | +def test_save_count_override_warnings_has_length(anim): |
| 455 | + |
| 456 | + save_count = 5 |
| 457 | + frames = list(range(2)) |
| 458 | + match_target = ( |
| 459 | + f'You passed in an explicit {save_count=} ' |
| 460 | + "which is being ignored in favor of " |
| 461 | + f"{len(frames)=}." |
| 462 | + ) |
| 463 | + |
| 464 | + with pytest.warns(UserWarning, match=re.escape(match_target)): |
| 465 | + anim = animation.FuncAnimation( |
| 466 | + **{**anim, 'frames': frames, 'save_count': save_count} |
| 467 | + ) |
| 468 | + assert anim._save_count == len(frames) |
| 469 | + anim._init_draw() |
| 470 | + |
| 471 | + |
| 472 | +@pytest.mark.parametrize('anim', [dict(klass=dict)], indirect=['anim']) |
| 473 | +def test_save_count_override_warnings_scaler(anim): |
| 474 | + save_count = 5 |
| 475 | + frames = 7 |
| 476 | + match_target = ( |
| 477 | + f'You passed in an explicit {save_count=} ' + |
| 478 | + "which is being ignored in favor of " + |
| 479 | + f"{frames=}." |
| 480 | + ) |
| 481 | + |
| 482 | + with pytest.warns(UserWarning, match=re.escape(match_target)): |
| 483 | + anim = animation.FuncAnimation( |
| 484 | + **{**anim, 'frames': frames, 'save_count': save_count} |
| 485 | + ) |
| 486 | + |
| 487 | + assert anim._save_count == frames |
| 488 | + anim._init_draw() |
| 489 | + |
| 490 | + |
| 491 | +@pytest.mark.parametrize('anim', [dict(klass=dict)], indirect=['anim']) |
| 492 | +def test_disable_cache_warning(anim): |
| 493 | + cache_frame_data = True |
| 494 | + frames = iter(range(5)) |
| 495 | + match_target = ( |
| 496 | + f"{frames=!r} which we can infer the length of, " |
| 497 | + "did not pass an explicit *save_count* " |
| 498 | + f"and passed {cache_frame_data=}. To avoid a possibly " |
| 499 | + "unbounded cache, frame data caching has been disabled. " |
| 500 | + "To suppress this warning either pass " |
| 501 | + "`cache_frame_data=False` or `save_count=MAX_FRAMES`." |
| 502 | + ) |
| 503 | + with pytest.warns(UserWarning, match=re.escape(match_target)): |
| 504 | + anim = animation.FuncAnimation( |
| 505 | + **{**anim, 'cache_frame_data': cache_frame_data, 'frames': frames} |
| 506 | + ) |
| 507 | + assert anim._cache_frame_data is False |
| 508 | + anim._init_draw() |
0 commit comments