44# License: BSD-3-Clause
55
66import numpy as np
7+ import pytest
78from qtpy .QtTest import QTest
89from mne import Annotations
910from pyqtgraph .graphicsItems .FillBetweenItem import FillBetweenItem
1011
1112
13+ LESS_TIME = "Show fewer time points"
14+ MORE_TIME = "Show more time points"
15+ FEWER_CHANNELS = "Show fewer channels"
16+ MORE_CHANNELS = "Show more channels"
17+ REDUCE_AMPLITUDE = "Reduce amplitude"
18+ INCREASE_AMPLITUDE = "Increase amplitude"
19+ TOGGLE_ANNOTATIONS = "Toggle annotations mode"
20+ SHOW_PROJECTORS = "Show projectors"
21+
22+
1223def test_annotations_interactions (raw_orig , pg_backend ):
1324 """Test interactions specific to pyqtgraph-backend."""
1425 # Add test-annotations
@@ -143,6 +154,8 @@ def test_pg_settings_dialog(raw_orig, pg_backend):
143154 QTest .qWaitForWindowExposed (fig )
144155 QTest .qWait (50 )
145156 assert fig .mne .fig_settings is None
157+ with pytest .raises (ValueError , match = "FooAction" ):
158+ fig ._fake_click_on_toolbar_action ("FooAction" )
146159 fig ._fake_click_on_toolbar_action ("Settings" , wait_after = 500 )
147160 assert fig .mne .fig_settings is not None
148161 assert pg_backend ._get_n_figs () == 2
@@ -263,44 +276,44 @@ def test_pg_toolbar_time_plus_minus(raw_orig, pg_backend):
263276 for _ in range (100 ):
264277 if xmax - xmin <= min_duration :
265278 break
266- fig ._fake_click_on_toolbar_action ("- Time" , wait_after = 20 )
279+ fig ._fake_click_on_toolbar_action (LESS_TIME , wait_after = 20 )
267280 xmin , xmax = fig .mne .viewbox .viewRange ()[0 ]
268281 assert xmax - xmin == min_duration
269282
270283 eps = 0.01
271284 step = 0.25
272- fig ._fake_click_on_toolbar_action ("+ Time" , wait_after = 100 )
285+ fig ._fake_click_on_toolbar_action (MORE_TIME , wait_after = 100 )
273286 xmin_new , xmax_new = fig .mne .viewbox .viewRange ()[0 ]
274287 assert xmax_new - (xmax + (xmax - xmin * step )) < eps
275288
276289 xmin , xmax = fig .mne .viewbox .viewRange ()[0 ]
277290 for _ in range (100 ):
278291 if xmax + fig .mne .duration * step >= fig .mne .xmax :
279292 break
280- fig ._fake_click_on_toolbar_action ("+ Time" , wait_after = 20 )
293+ fig ._fake_click_on_toolbar_action (MORE_TIME , wait_after = 20 )
281294 xmin , xmax = fig .mne .viewbox .viewRange ()[0 ]
282295
283- fig ._fake_click_on_toolbar_action ("+ Time" , wait_after = 200 )
284- fig ._fake_click_on_toolbar_action ("+ Time" , wait_after = 200 )
296+ fig ._fake_click_on_toolbar_action (MORE_TIME , wait_after = 200 )
297+ fig ._fake_click_on_toolbar_action (MORE_TIME , wait_after = 200 )
285298
286299 xmin , xmax = fig .mne .viewbox .viewRange ()[0 ]
287- fig ._fake_click_on_toolbar_action ("+ Time" , wait_after = 200 )
300+ fig ._fake_click_on_toolbar_action (MORE_TIME , wait_after = 200 )
288301 xmin_new , xmax_new = fig .mne .viewbox .viewRange ()[0 ]
289302 assert xmax_new == xmax # no effect after span maxed
290303
291304 step = - 0.2
292305 xmin , xmax = fig .mne .viewbox .viewRange ()[0 ]
293- fig ._fake_click_on_toolbar_action ("- Time" , wait_after = 200 )
306+ fig ._fake_click_on_toolbar_action (LESS_TIME , wait_after = 200 )
294307 xmin_new , xmax_new = fig .mne .viewbox .viewRange ()[0 ]
295308 assert xmax_new == xmax + ((xmax - xmin ) * step )
296309
297310 xmin , xmax = fig .mne .viewbox .viewRange ()[0 ]
298- fig ._fake_click_on_toolbar_action ("- Time" , wait_after = 200 )
311+ fig ._fake_click_on_toolbar_action (LESS_TIME , wait_after = 200 )
299312 xmin_new , xmax_new = fig .mne .viewbox .viewRange ()[0 ]
300313 assert xmax_new == xmax + ((xmax - xmin ) * step )
301314
302315 for _ in range (7 ):
303- fig ._fake_click_on_toolbar_action ("- Time" , wait_after = 20 )
316+ fig ._fake_click_on_toolbar_action (LESS_TIME , wait_after = 20 )
304317
305318 assert pg_backend ._get_n_figs () == 1 # still alive
306319
@@ -313,11 +326,11 @@ def test_pg_toolbar_channels_plus_minus(raw_orig, pg_backend):
313326
314327 if fig .mne .butterfly is not True :
315328 fig ._fake_keypress ("b" ) # toggle butterfly mode
316- fig ._fake_click_on_toolbar_action ("- Channels" , wait_after = 100 )
329+ fig ._fake_click_on_toolbar_action (FEWER_CHANNELS , wait_after = 100 )
317330 ymin , ymax = fig .mne .viewbox .viewRange ()[1 ]
318- fig ._fake_click_on_toolbar_action ("- Channels" , wait_after = 100 )
331+ fig ._fake_click_on_toolbar_action (FEWER_CHANNELS , wait_after = 100 )
319332 assert [ymin , ymax ] == fig .mne .viewbox .viewRange ()[1 ]
320- fig ._fake_click_on_toolbar_action ("+ Channels" , wait_after = 100 )
333+ fig ._fake_click_on_toolbar_action (MORE_CHANNELS , wait_after = 100 )
321334 assert [ymin , ymax ] == fig .mne .viewbox .viewRange ()[1 ]
322335
323336 if fig .mne .butterfly is True :
@@ -326,25 +339,25 @@ def test_pg_toolbar_channels_plus_minus(raw_orig, pg_backend):
326339 for _ in range (10 ):
327340 if ymax - ymin <= 2 :
328341 break
329- fig ._fake_click_on_toolbar_action ("- Channels" , wait_after = 40 )
342+ fig ._fake_click_on_toolbar_action (FEWER_CHANNELS , wait_after = 40 )
330343 ymin , ymax = fig .mne .viewbox .viewRange ()[1 ]
331344 assert ymax - ymin == 2
332- fig ._fake_click_on_toolbar_action ("- Channels" , wait_after = 40 )
345+ fig ._fake_click_on_toolbar_action (FEWER_CHANNELS , wait_after = 40 )
333346 ymin , ymax = fig .mne .viewbox .viewRange ()[1 ]
334347 assert ymax - ymin == 2
335348
336349 step = 10
337- fig ._fake_click_on_toolbar_action ("+ Channels" , wait_after = 100 )
350+ fig ._fake_click_on_toolbar_action (MORE_CHANNELS , wait_after = 100 )
338351 ymin_new , ymax_new = fig .mne .viewbox .viewRange ()[1 ]
339352 assert ymax_new == ymax + step
340353
341354 ymin , ymax = fig .mne .viewbox .viewRange ()[1 ]
342- fig ._fake_click_on_toolbar_action ("+ Channels" , wait_after = 100 )
355+ fig ._fake_click_on_toolbar_action (MORE_CHANNELS , wait_after = 100 )
343356 ymin_new , ymax_new = fig .mne .viewbox .viewRange ()[1 ]
344357 assert ymax_new == ymax + step
345358
346359 ymin , ymax = fig .mne .viewbox .viewRange ()[1 ]
347- fig ._fake_click_on_toolbar_action ("+ Channels" , wait_after = 100 )
360+ fig ._fake_click_on_toolbar_action (MORE_CHANNELS , wait_after = 100 )
348361 ymin_new , ymax_new = fig .mne .viewbox .viewRange ()[1 ]
349362 assert ymax_new == ymax + step
350363
@@ -359,21 +372,21 @@ def test_pg_toolbar_zoom(raw_orig, pg_backend):
359372
360373 step = 4 / 5
361374 scale_factor = fig .mne .scale_factor
362- fig ._fake_click_on_toolbar_action ("Zoom out" , wait_after = 100 )
375+ fig ._fake_click_on_toolbar_action (REDUCE_AMPLITUDE , wait_after = 100 )
363376 scale_factor_new = fig .mne .scale_factor
364377 assert scale_factor_new == scale_factor * step
365378
366379 for _ in range (6 ):
367- fig ._fake_click_on_toolbar_action ("Zoom out" , wait_after = 100 )
380+ fig ._fake_click_on_toolbar_action (REDUCE_AMPLITUDE , wait_after = 100 )
368381
369382 step = 5 / 4
370383 scale_factor = fig .mne .scale_factor
371- fig ._fake_click_on_toolbar_action ("Zoom in" , wait_after = 100 )
384+ fig ._fake_click_on_toolbar_action (INCREASE_AMPLITUDE , wait_after = 100 )
372385 scale_factor_new = fig .mne .scale_factor
373386 assert scale_factor_new == scale_factor * step
374387
375388 for _ in range (6 ):
376- fig ._fake_click_on_toolbar_action ("Zoom in" , wait_after = 100 )
389+ fig ._fake_click_on_toolbar_action (INCREASE_AMPLITUDE , wait_after = 100 )
377390
378391 assert pg_backend ._get_n_figs () == 1 # still alive
379392
@@ -385,12 +398,12 @@ def test_pg_toolbar_annotations(raw_orig, pg_backend):
385398 assert pg_backend ._get_n_figs () == 1
386399
387400 state_annotation_widget = fig .mne .annotation_mode
388- fig ._fake_click_on_toolbar_action ("Annotations" , wait_after = 100 )
401+ fig ._fake_click_on_toolbar_action (TOGGLE_ANNOTATIONS , wait_after = 100 )
389402 assert fig .mne .annotation_mode != state_annotation_widget
390403
391- fig ._fake_click_on_toolbar_action ("Annotations" , wait_after = 300 )
392- fig ._fake_click_on_toolbar_action ("Annotations" , wait_after = 300 )
393- fig ._fake_click_on_toolbar_action ("Annotations" , wait_after = 300 )
404+ fig ._fake_click_on_toolbar_action (TOGGLE_ANNOTATIONS , wait_after = 300 )
405+ fig ._fake_click_on_toolbar_action (TOGGLE_ANNOTATIONS , wait_after = 300 )
406+ fig ._fake_click_on_toolbar_action (TOGGLE_ANNOTATIONS , wait_after = 300 )
394407
395408 assert pg_backend ._get_n_figs () == 1 # still alive
396409
@@ -404,7 +417,7 @@ def test_pg_toolbar_actions(raw_orig, pg_backend):
404417 QTest .qWaitForWindowExposed (fig )
405418 assert pg_backend ._get_n_figs () == 1
406419
407- fig ._fake_click_on_toolbar_action ("SSP" , wait_after = 200 )
420+ fig ._fake_click_on_toolbar_action (SHOW_PROJECTORS , wait_after = 200 )
408421 assert pg_backend ._get_n_figs () == 2
409422 fig ._fake_click_on_toolbar_action ("Settings" , wait_after = 200 )
410423 assert pg_backend ._get_n_figs () == 3
@@ -414,7 +427,7 @@ def test_pg_toolbar_actions(raw_orig, pg_backend):
414427 assert pg_backend ._get_n_figs () == 3
415428 fig ._fake_click_on_toolbar_action ("Settings" , wait_after = 200 )
416429 assert pg_backend ._get_n_figs () == 4
417- fig ._fake_click_on_toolbar_action ("SSP" , wait_after = 200 )
430+ fig ._fake_click_on_toolbar_action (SHOW_PROJECTORS , wait_after = 200 )
418431 assert pg_backend ._get_n_figs () == 3
419432 fig ._fake_click_on_toolbar_action ("Settings" , wait_after = 100 )
420433 assert pg_backend ._get_n_figs () == 2
0 commit comments