4
4
# License: BSD-3-Clause
5
5
6
6
import numpy as np
7
+ import pytest
7
8
from qtpy .QtTest import QTest
8
9
from mne import Annotations
9
10
from pyqtgraph .graphicsItems .FillBetweenItem import FillBetweenItem
10
11
11
12
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
+
12
23
def test_annotations_interactions (raw_orig , pg_backend ):
13
24
"""Test interactions specific to pyqtgraph-backend."""
14
25
# Add test-annotations
@@ -143,6 +154,8 @@ def test_pg_settings_dialog(raw_orig, pg_backend):
143
154
QTest .qWaitForWindowExposed (fig )
144
155
QTest .qWait (50 )
145
156
assert fig .mne .fig_settings is None
157
+ with pytest .raises (ValueError , match = "FooAction" ):
158
+ fig ._fake_click_on_toolbar_action ("FooAction" )
146
159
fig ._fake_click_on_toolbar_action ("Settings" , wait_after = 500 )
147
160
assert fig .mne .fig_settings is not None
148
161
assert pg_backend ._get_n_figs () == 2
@@ -263,44 +276,44 @@ def test_pg_toolbar_time_plus_minus(raw_orig, pg_backend):
263
276
for _ in range (100 ):
264
277
if xmax - xmin <= min_duration :
265
278
break
266
- fig ._fake_click_on_toolbar_action ("- Time" , wait_after = 20 )
279
+ fig ._fake_click_on_toolbar_action (LESS_TIME , wait_after = 20 )
267
280
xmin , xmax = fig .mne .viewbox .viewRange ()[0 ]
268
281
assert xmax - xmin == min_duration
269
282
270
283
eps = 0.01
271
284
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 )
273
286
xmin_new , xmax_new = fig .mne .viewbox .viewRange ()[0 ]
274
287
assert xmax_new - (xmax + (xmax - xmin * step )) < eps
275
288
276
289
xmin , xmax = fig .mne .viewbox .viewRange ()[0 ]
277
290
for _ in range (100 ):
278
291
if xmax + fig .mne .duration * step >= fig .mne .xmax :
279
292
break
280
- fig ._fake_click_on_toolbar_action ("+ Time" , wait_after = 20 )
293
+ fig ._fake_click_on_toolbar_action (MORE_TIME , wait_after = 20 )
281
294
xmin , xmax = fig .mne .viewbox .viewRange ()[0 ]
282
295
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 )
285
298
286
299
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 )
288
301
xmin_new , xmax_new = fig .mne .viewbox .viewRange ()[0 ]
289
302
assert xmax_new == xmax # no effect after span maxed
290
303
291
304
step = - 0.2
292
305
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 )
294
307
xmin_new , xmax_new = fig .mne .viewbox .viewRange ()[0 ]
295
308
assert xmax_new == xmax + ((xmax - xmin ) * step )
296
309
297
310
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 )
299
312
xmin_new , xmax_new = fig .mne .viewbox .viewRange ()[0 ]
300
313
assert xmax_new == xmax + ((xmax - xmin ) * step )
301
314
302
315
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 )
304
317
305
318
assert pg_backend ._get_n_figs () == 1 # still alive
306
319
@@ -313,11 +326,11 @@ def test_pg_toolbar_channels_plus_minus(raw_orig, pg_backend):
313
326
314
327
if fig .mne .butterfly is not True :
315
328
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 )
317
330
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 )
319
332
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 )
321
334
assert [ymin , ymax ] == fig .mne .viewbox .viewRange ()[1 ]
322
335
323
336
if fig .mne .butterfly is True :
@@ -326,25 +339,25 @@ def test_pg_toolbar_channels_plus_minus(raw_orig, pg_backend):
326
339
for _ in range (10 ):
327
340
if ymax - ymin <= 2 :
328
341
break
329
- fig ._fake_click_on_toolbar_action ("- Channels" , wait_after = 40 )
342
+ fig ._fake_click_on_toolbar_action (FEWER_CHANNELS , wait_after = 40 )
330
343
ymin , ymax = fig .mne .viewbox .viewRange ()[1 ]
331
344
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 )
333
346
ymin , ymax = fig .mne .viewbox .viewRange ()[1 ]
334
347
assert ymax - ymin == 2
335
348
336
349
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 )
338
351
ymin_new , ymax_new = fig .mne .viewbox .viewRange ()[1 ]
339
352
assert ymax_new == ymax + step
340
353
341
354
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 )
343
356
ymin_new , ymax_new = fig .mne .viewbox .viewRange ()[1 ]
344
357
assert ymax_new == ymax + step
345
358
346
359
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 )
348
361
ymin_new , ymax_new = fig .mne .viewbox .viewRange ()[1 ]
349
362
assert ymax_new == ymax + step
350
363
@@ -359,21 +372,21 @@ def test_pg_toolbar_zoom(raw_orig, pg_backend):
359
372
360
373
step = 4 / 5
361
374
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 )
363
376
scale_factor_new = fig .mne .scale_factor
364
377
assert scale_factor_new == scale_factor * step
365
378
366
379
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 )
368
381
369
382
step = 5 / 4
370
383
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 )
372
385
scale_factor_new = fig .mne .scale_factor
373
386
assert scale_factor_new == scale_factor * step
374
387
375
388
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 )
377
390
378
391
assert pg_backend ._get_n_figs () == 1 # still alive
379
392
@@ -385,12 +398,12 @@ def test_pg_toolbar_annotations(raw_orig, pg_backend):
385
398
assert pg_backend ._get_n_figs () == 1
386
399
387
400
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 )
389
402
assert fig .mne .annotation_mode != state_annotation_widget
390
403
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 )
394
407
395
408
assert pg_backend ._get_n_figs () == 1 # still alive
396
409
@@ -404,7 +417,7 @@ def test_pg_toolbar_actions(raw_orig, pg_backend):
404
417
QTest .qWaitForWindowExposed (fig )
405
418
assert pg_backend ._get_n_figs () == 1
406
419
407
- fig ._fake_click_on_toolbar_action ("SSP" , wait_after = 200 )
420
+ fig ._fake_click_on_toolbar_action (SHOW_PROJECTORS , wait_after = 200 )
408
421
assert pg_backend ._get_n_figs () == 2
409
422
fig ._fake_click_on_toolbar_action ("Settings" , wait_after = 200 )
410
423
assert pg_backend ._get_n_figs () == 3
@@ -414,7 +427,7 @@ def test_pg_toolbar_actions(raw_orig, pg_backend):
414
427
assert pg_backend ._get_n_figs () == 3
415
428
fig ._fake_click_on_toolbar_action ("Settings" , wait_after = 200 )
416
429
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 )
418
431
assert pg_backend ._get_n_figs () == 3
419
432
fig ._fake_click_on_toolbar_action ("Settings" , wait_after = 100 )
420
433
assert pg_backend ._get_n_figs () == 2
0 commit comments