Test annotation mode of the plotter.
(raw, browser_backend)
| 789 | |
| 790 | @pytest.mark.slowtest |
| 791 | def test_plot_annotations(raw, browser_backend): |
| 792 | """Test annotation mode of the plotter.""" |
| 793 | ismpl = browser_backend.name == "matplotlib" |
| 794 | with raw.info._unlock(): |
| 795 | raw.info["lowpass"] = 10.0 |
| 796 | _annotation_helper(raw, browser_backend) |
| 797 | _annotation_helper(raw, browser_backend, events=True) |
| 798 | |
| 799 | annot = Annotations([42], [1], "test", raw.info["meas_date"]) |
| 800 | with pytest.warns(RuntimeWarning, match="expanding outside"): |
| 801 | raw.set_annotations(annot) |
| 802 | _annotation_helper(raw, browser_backend) |
| 803 | # test annotation visibility toggle |
| 804 | fig = raw.plot() |
| 805 | if ismpl: |
| 806 | assert len(fig.mne.annotations) == 1 |
| 807 | assert len(fig.mne.annotation_texts) == 1 |
| 808 | else: |
| 809 | assert len(fig.mne.regions) == 1 |
| 810 | fig._fake_keypress("a") # start annotation mode |
| 811 | if ismpl: |
| 812 | checkboxes = fig.mne.show_hide_annotation_checkboxes |
| 813 | checkboxes.set_active(0) |
| 814 | assert len(fig.mne.annotations) == 0 |
| 815 | assert len(fig.mne.annotation_texts) == 0 |
| 816 | checkboxes.set_active(0) |
| 817 | assert len(fig.mne.annotations) == 1 |
| 818 | assert len(fig.mne.annotation_texts) == 1 |
| 819 | else: |
| 820 | fig.mne.visible_annotations["test"] = False |
| 821 | fig._update_regions_visible() |
| 822 | assert not fig.mne.regions[0].isVisible() |
| 823 | fig.mne.visible_annotations["test"] = True |
| 824 | fig._update_regions_visible() |
| 825 | assert fig.mne.regions[0].isVisible() |
| 826 | |
| 827 | # Check if single annotation toggle works |
| 828 | ch_pick = fig.mne.inst.ch_names[0] |
| 829 | fig._toggle_single_channel_annotation(ch_pick, 0) |
| 830 | assert fig.mne.inst.annotations.ch_names[0] == (ch_pick,) |
| 831 | |
| 832 | # Check if annotation filtering works - All annotations |
| 833 | annot = Annotations([42, 50], [1, 1], ["test", "test2"], raw.info["meas_date"]) |
| 834 | with pytest.warns(RuntimeWarning, match="expanding outside"): |
| 835 | raw.set_annotations(annot) |
| 836 | |
| 837 | fig = raw.plot() |
| 838 | |
| 839 | assert fig.mne.visible_annotations["test"] and fig.mne.visible_annotations["test2"] |
| 840 | |
| 841 | # Check if annotation filtering works - filtering annotations |
| 842 | # This should only make test2 visible and hide test |
| 843 | fig = raw.plot(annotation_regex="2$") |
| 844 | |
| 845 | assert ( |
| 846 | not fig.mne.visible_annotations["test"] and fig.mne.visible_annotations["test2"] |
| 847 | ) |
| 848 |
nothing calls this directly
no test coverage detected