Skip to content

Commit 0be53be

Browse files
authored
TEST: Update animation test to use PillowWriter for transparency handling
1 parent d9193df commit 0be53be

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

lib/matplotlib/tests/test_animation.py

+9-19
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import matplotlib as mpl
1414
from matplotlib import pyplot as plt
1515
from matplotlib import animation
16+
from matplotlib.animation import PillowWriter
1617
from matplotlib.testing.decorators import check_figures_equal
1718

1819

@@ -528,29 +529,18 @@ def test_movie_writer_invalid_path(anim):
528529
writer=animation.FFMpegFileWriter())
529530

530531

531-
def test_exhausted_animation_with_transparency(tmp_path):
532+
def test_animation_with_transparency():
533+
"""Test animation exhaustion with transparency using PillowWriter directly"""
532534
fig, ax = plt.subplots()
533535
rect = plt.Rectangle((0, 0), 1, 1, color='red', alpha=0.5)
534536
ax.add_patch(rect)
535537
ax.set_xlim(0, 1)
536538
ax.set_ylim(0, 1)
537539

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-
540+
writer = PillowWriter(fps=30)
541+
writer.setup(fig, 'unused.gif', dpi=100)
542+
writer.grab_frame(transparent=True)
543+
frame = writer._frames[-1]
544+
# Check that the alpha channel is not 255, so frame has transparency
545+
assert frame.getextrema()[3][0] < 255
556546
plt.close(fig)

0 commit comments

Comments
 (0)