Skip to content

Commit

Permalink
Merge pull request #37 from cibr-jyu/add-action-tests
Browse files Browse the repository at this point in the history
Add action tests
  • Loading branch information
teekuningas authored Mar 2, 2024
2 parents 18ed5bd + 590a103 commit 7f25a54
Show file tree
Hide file tree
Showing 57 changed files with 1,223 additions and 199 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ check:

.PHONY: test
test:
pytest -s
pytest

.PHONY: update_docs
update_docs:
Expand Down
7 changes: 4 additions & 3 deletions meggie/actions/epochs_create/tests/test_epochs_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@


class TestEpochsCreate(BaseTestAction):
def test_create_epochs_dialog(self):
def test_epochs_create(self):

self.run_action(
tab_id="epochs",
action_name="epochs_create",
handler=CreateEpochs,
dialog_path="meggie.actions.epochs_create.dialogs.createEpochsFromEventsDialogMain",
patch_paths=[
"meggie.actions.epochs_create.dialogs.createEpochsFromEventsDialogMain"
],
)
dialog = self.find_dialog(CreateEpochsFromEventsDialog)

Expand Down
15 changes: 15 additions & 0 deletions meggie/actions/epochs_delete/tests/test_epochs_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.epochs_delete import DeleteEpochs


class TestEpochsDelete(BaseTestAction):
def test_epochs_delete(self):

data = {"outputs": {"epochs": ["Epochs"]}}

self.run_action(
action_name="epochs_delete",
handler=DeleteEpochs,
data=data,
patch_paths=["meggie.actions.epochs_delete"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.epochs_delete_from_all import DeleteEpochsFromAll


class TestEpochsDeleteFromAll(BaseTestAction):
def test_epochs_delete_from_all(self):

data = {"outputs": {"epochs": ["Epochs"]}}

self.run_action(
action_name="epochs_delete_from_all",
handler=DeleteEpochsFromAll,
data=data,
patch_paths=["meggie.actions.epochs_delete_from_all"],
)
16 changes: 16 additions & 0 deletions meggie/actions/epochs_info/tests/test_epochs_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.epochs_info import Info


class TestEpochsInfo(BaseTestAction):
def test_epochs_info(self):

data = {"outputs": {"epochs": ["Epochs"]}}

content = self.run_action(
action_name="epochs_info",
handler=Info,
data=data,
patch_paths=["meggie.actions.epochs_info"],
)
assert content
15 changes: 15 additions & 0 deletions meggie/actions/epochs_plot/tests/test_epochs_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.epochs_plot import PlotEpochs


class TestEpochsPlot(BaseTestAction):
def test_epochs_plot(self):

data = {"outputs": {"epochs": ["Epochs"]}}

self.run_action(
action_name="epochs_plot",
handler=PlotEpochs,
data=data,
patch_paths=["meggie.actions.epochs_plot"],
)
15 changes: 15 additions & 0 deletions meggie/actions/epochs_plot_image/tests/test_epochs_plot_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.epochs_plot_image import PlotEpochsImage


class TestEpochsPlotImage(BaseTestAction):
def test_epochs_plot_image(self):

data = {"outputs": {"epochs": ["Epochs"]}}

self.run_action(
action_name="epochs_plot_image",
handler=PlotEpochsImage,
data=data,
patch_paths=["meggie.actions.epochs_plot_image"],
)
18 changes: 18 additions & 0 deletions meggie/actions/evoked_create/tests/test_evoked_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_create import CreateEvoked
from meggie.utilities.dialogs.simpleDialogMain import SimpleDialog


class TestEvokedCreate(BaseTestAction):
def test_evoked_create(self):

data = {"inputs": {"epochs": ["Epochs"]}}

self.run_action(
action_name="evoked_create",
handler=CreateEvoked,
data=data,
patch_paths=["meggie.utilities.dialogs.simpleDialogMain"],
)
dialog = self.find_dialog(SimpleDialog)
dialog.accept()
15 changes: 15 additions & 0 deletions meggie/actions/evoked_delete/tests/test_evoked_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_delete import DeleteEvoked


class TestEvokedDelete(BaseTestAction):
def test_evoked_delete(self):

data = {"outputs": {"evoked": ["Evoked"]}}

self.run_action(
action_name="evoked_delete",
handler=DeleteEvoked,
data=data,
patch_paths=["meggie.actions.evoked_delete"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_delete_from_all import DeleteEvokedFromAll


class TestEvokedDeleteFromAll(BaseTestAction):
def test_evoked_delete_from_all(self):

data = {"outputs": {"evoked": ["Evoked"]}}

self.run_action(
action_name="evoked_delete_from_all",
handler=DeleteEvokedFromAll,
data=data,
patch_paths=["meggie.actions.evoked_delete_from_all"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from PyQt5 import QtCore

from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_group_average import GroupAverage
from meggie.utilities.dialogs.groupSelectionDialogMain import (
GroupSelectionDialog,
)


class TestEvokedGroupAverage(BaseTestAction):
def test_evoked_group_average(self):

data = {"outputs": {"evoked": ["Evoked"]}}

self.run_action(
action_name="evoked_group_average",
handler=GroupAverage,
data=data,
patch_paths=["meggie.actions.evoked_group_average"],
)
dialog = self.find_dialog(GroupSelectionDialog)

dialog.ui.checkBoxGroup_0.setCheckState(QtCore.Qt.Checked)
dialog.ui.spinBoxGroup_0.setValue(1)
dialog.ui.checkBoxGroup_1.setCheckState(QtCore.Qt.Checked)
dialog.ui.spinBoxGroup_1.setValue(2)

dialog.accept()
16 changes: 16 additions & 0 deletions meggie/actions/evoked_info/tests/test_evoked_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_info import Info


class TestEvokedInfo(BaseTestAction):
def test_evoked_info(self):

data = {"outputs": {"evoked": ["Evoked"]}}

content = self.run_action(
action_name="evoked_info",
handler=Info,
data=data,
patch_paths=["meggie.actions.evoked_info"],
)
assert content
19 changes: 19 additions & 0 deletions meggie/actions/evoked_plot/tests/test_evoked_plot_all_channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_plot import PlotEvoked
from meggie.utilities.dialogs.outputOptionsMain import OutputOptions


class TestEvokedPlotAllChannels(BaseTestAction):
def test_evoked_plot_all_channels(self):

data = {"outputs": {"evoked": ["Evoked"]}}

self.run_action(
action_name="evoked_plot",
handler=PlotEvoked,
data=data,
patch_paths=["meggie.actions.evoked_plot"],
)
dialog = self.find_dialog(OutputOptions)
dialog.ui.radioButtonChannelAverages.setChecked(False)
dialog.accept()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_plot import PlotEvoked
from meggie.utilities.dialogs.outputOptionsMain import OutputOptions


class TestEvokedPlotChannelAverages(BaseTestAction):
def test_evoked_plot_channel_averages(self):

data = {"outputs": {"evoked": ["Evoked"]}}

self.run_action(
action_name="evoked_plot",
handler=PlotEvoked,
data=data,
patch_paths=["meggie.actions.evoked_plot"],
)
dialog = self.find_dialog(OutputOptions)
dialog.ui.radioButtonChannelAverages.setChecked(True)
dialog.accept()
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_plot_topomap import PlotEvokedTopomap
from meggie.actions.evoked_plot_topomap.dialogs.evokedTopomapDialogMain import (
EvokedTopomapDialog,
)


class TestEvokedPlotTopomap(BaseTestAction):
def test_evoked_plot_topomap(self):

data = {"outputs": {"evoked": ["Evoked"]}}

self.run_action(
action_name="evoked_plot_topomap",
handler=PlotEvokedTopomap,
data=data,
patch_paths=[
"meggie.actions.evoked_plot_topomap.dialogs.evokedTopomapDialogMain"
],
)
dialog = self.find_dialog(EvokedTopomapDialog)
dialog.accept()
19 changes: 19 additions & 0 deletions meggie/actions/evoked_save/tests/test_evoked_save_all_channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_save import SaveEvoked
from meggie.utilities.dialogs.outputOptionsMain import OutputOptions


class TestEvokedSaveAllChannels(BaseTestAction):
def test_evoked_save_all_channels(self):

data = {"outputs": {"evoked": ["Evoked"]}}

self.run_action(
action_name="evoked_save",
handler=SaveEvoked,
data=data,
patch_paths=["meggie.actions.evoked_save"],
)
dialog = self.find_dialog(OutputOptions)
dialog.ui.radioButtonChannelAverages.setChecked(False)
dialog.accept()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.evoked_save import SaveEvoked
from meggie.utilities.dialogs.outputOptionsMain import OutputOptions


class TestEvokedSaveChannelAverages(BaseTestAction):
def test_evoked_save_channel_averages(self):

data = {"outputs": {"evoked": ["Evoked"]}}

self.run_action(
action_name="evoked_save",
handler=SaveEvoked,
data=data,
patch_paths=["meggie.actions.evoked_save"],
)
dialog = self.find_dialog(OutputOptions)
dialog.ui.radioButtonChannelAverages.setChecked(True)
dialog.accept()
13 changes: 13 additions & 0 deletions meggie/actions/raw_event_info/tests/test_raw_event_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from meggie.utilities.testing import BaseTestAction
from meggie.actions.raw_event_info import Info


class TestRawEventInfo(BaseTestAction):
def test_raw_event_info(self):

content = self.run_action(
action_name="raw_event_info",
handler=Info,
patch_paths=["meggie.actions.raw_event_info"],
)
assert content
12 changes: 6 additions & 6 deletions meggie/actions/raw_events_from_annotations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class EventsFromAnnotations(Action):
applies a conversion from annotations to events.
"""

def run(self):
evs_from_annots_dialog = EventsFromAnnotationsDialog(
self.window, self.experiment, self.handler
)
evs_from_annots_dialog.show()

@subject_action
def handler(self, subject, params):
""" """
Expand All @@ -29,9 +35,3 @@ def conv_fun():
subject.save()

conv_fun(do_meanwhile=self.window.update_ui)

def run(self):
evs_from_annots_dialog = EventsFromAnnotationsDialog(
self.window, self.experiment, self.handler
)
evs_from_annots_dialog.show()
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import mne

from meggie.utilities.testing import BaseTestAction
from meggie.actions.raw_events_from_annotations import EventsFromAnnotations
from meggie.actions.raw_events_from_annotations.dialogs.eventsFromAnnotationsDialogMain import (
EventsFromAnnotationsDialog,
)


class TestRawEventsFromAnnotations(BaseTestAction):

def setup_experiment(self):
BaseTestAction.setup_experiment(self)
raw = self.experiment.active_subject.get_raw()

# create one annotation named "CAT"
annotations = mne.Annotations([2], [1], ["CAT"])
raw.set_annotations(annotations)

def test_raw_events_from_annotations(self):
self.run_action(
action_name="raw_events_from_annotations",
handler=EventsFromAnnotations,
patch_paths=[
"meggie.actions.raw_events_from_annotations.dialogs.eventsFromAnnotationsDialogMain"
],
)
dialog = self.find_dialog(EventsFromAnnotationsDialog)
dialog.items = [("CAT", 99, True)]
dialog.accept()
8 changes: 4 additions & 4 deletions meggie/actions/raw_filter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Filter(Action):
filtering the raw data.
"""

def run(self):
filter_dialog = FilterDialog(self.window, self.experiment, self.handler)
filter_dialog.show()

@subject_action
def handler(self, subject, params):
""" """
Expand All @@ -24,7 +28,3 @@ def filter_fun():
filter_data(subject, params)

filter_fun(do_meanwhile=self.window.update_ui)

def run(self):
filter_dialog = FilterDialog(self.window, self.experiment, self.handler)
filter_dialog.show()
Loading

0 comments on commit 7f25a54

Please sign in to comment.