Skip to content

Commit d9193df

Browse files
authored
test: Add test for animation with transparency and exhausted warning
1 parent e59706f commit d9193df

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/matplotlib/tests/test_animation.py

+28
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,31 @@ def test_movie_writer_invalid_path(anim):
526526
with pytest.raises(FileNotFoundError, match=match_str):
527527
anim.save("/foo/bar/aardvark/thiscannotreallyexist.mp4",
528528
writer=animation.FFMpegFileWriter())
529+
530+
531+
def test_exhausted_animation_with_transparency(tmp_path):
532+
fig, ax = plt.subplots()
533+
rect = plt.Rectangle((0, 0), 1, 1, color='red', alpha=0.5)
534+
ax.add_patch(rect)
535+
ax.set_xlim(0, 1)
536+
ax.set_ylim(0, 1)
537+
538+
def update(frame):
539+
# Modify transparency in each frame
540+
rect.set_alpha(0.1 + frame * 0.1)
541+
return [rect]
542+
543+
# Create and save animation
544+
anim = animation.FuncAnimation(
545+
fig, update, frames=iter(range(5)), repeat=False,
546+
cache_frame_data=False,
547+
548+
)
549+
tmp_file = tmp_path / "test_transparent.gif"
550+
anim.save(tmp_file, writer='pillow', savefig_kwargs={"transparent": True})
551+
552+
# Verify exhausted warning
553+
with pytest.warns(UserWarning, match="exhausted"):
554+
anim._start()
555+
556+
plt.close(fig)

0 commit comments

Comments
 (0)