@@ -169,25 +169,48 @@ def test_plot_projs_topomap_joint(meg, vlim, raw):
169169 assert len (fig .axes ) == 4 # 2 mag, 2 grad
170170
171171
172- def test_plot_topomap_animation (capsys ):
172+ def test_plot_topomap_animation (capsys , tmp_path ):
173173 """Test topomap plotting."""
174- # evoked
175174 evoked = read_evokeds (evoked_fname , "Left Auditory" , baseline = (None , 0 ))
176-
177- # Test animation
178- fig , anim = evoked .animate_topomap (
179- ch_type = "grad" ,
180- times = [0 , 0.1 ],
181- cmap = "viridis" ,
182- butterfly = False ,
183- time_unit = "s" ,
184- verbose = "debug" ,
185- )
186- anim ._func (1 ) # _animate has to be tested separately on 'Agg' backend.
175+ with pytest .warns (FutureWarning , match = ".* vmin .* deprecated.*" ):
176+ fig , anim = evoked .animate_topomap (
177+ times = [0 , 0.1 ],
178+ cmap = "viridis" ,
179+ vmin = 0 ,
180+ vmax = 10 ,
181+ verbose = "debug" ,
182+ )
187183 out , _ = capsys .readouterr ()
188184 assert "extrapolation mode local to mean" in out
189185 assert fig .axes [0 ].images [0 ].get_cmap ().name == "viridis"
190186
187+ # saving
188+ PIL = pytest .importorskip ("PIL" )
189+ gif_path = tmp_path / "test.gif"
190+ anim .save (gif_path , writer = "pillow" )
191+ assert gif_path .exists ()
192+ with PIL .Image .open (gif_path ) as img :
193+ assert img .format == "GIF"
194+ assert img .n_frames == 2
195+ for frame in PIL .ImageSequence .Iterator (img ):
196+ assert frame .format == "GIF"
197+ data = np .array (frame )
198+ assert data .any () # not all empty
199+
200+ # failure modes
201+ evoked .pick ("mag" )
202+ with pytest .raises (ValueError , match = "No channels of type" ):
203+ evoked .animate_topomap (ch_type = "eeg" )
204+ fig , axes = plt .subplots (1 , 4 )
205+ with pytest .raises (ValueError , match = "it must have length 2" ):
206+ evoked .animate_topomap (axes = axes )
207+ with pytest .raises (ValueError , match = "it must have length 3" ):
208+ evoked .animate_topomap (axes = axes , butterfly = True )
209+ with pytest .raises (TypeError , match = "axes must be an instance" ):
210+ evoked .animate_topomap (axes = "test" )
211+ with pytest .raises (TypeError , match = r"axes\[0\] must be an instance" ):
212+ evoked .animate_topomap (axes = ["test" , "test" ])
213+
191214
192215def test_plot_topomap_animation_csd (capsys ):
193216 """Test topomap plotting of CSD data."""
@@ -204,14 +227,9 @@ def test_plot_topomap_animation_csd(capsys):
204227 assert "extrapolation mode head to mean" in out
205228
206229
207- @pytest .mark .filterwarnings ("ignore:.*No contour levels.*:UserWarning" )
208- def test_plot_topomap_animation_nirs (fnirs_evoked , capsys ):
230+ def test_plot_topomap_animation_nirs (fnirs_evoked ):
209231 """Test topomap plotting for nirs data."""
210- fig , anim = fnirs_evoked .animate_topomap (ch_type = "hbo" , verbose = "debug" )
211- anim ._func (1 ) # _animate has to be tested separately on 'Agg' backend.
212- out , _ = capsys .readouterr ()
213- assert "extrapolation mode head to mean" in out
214- assert len (fig .axes ) == 2
232+ fnirs_evoked .animate_topomap (ch_type = "hbo" , verbose = "debug" )
215233
216234
217235def test_plot_evoked_topomap_errors (evoked , monkeypatch ):
0 commit comments