-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from cibr-jyu/test-actions
Test actions
- Loading branch information
Showing
6 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
black | ||
pylama | ||
nose | ||
pytest | ||
pytest-qt | ||
mkdocs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from PyQt5 import QtWidgets | ||
|
||
from meggie.utilities.testing import BaseTestAction | ||
from meggie.actions.epochs_create import CreateEpochs | ||
from meggie.actions.epochs_create.dialogs.createEpochsFromEventsDialogMain import ( | ||
CreateEpochsFromEventsDialog, | ||
) | ||
|
||
|
||
class TestEpochsCreate(BaseTestAction): | ||
def test_create_epochs_dialog(self): | ||
def patched_exc_messagebox(parent, exc, exec_=False): | ||
raise exc | ||
|
||
self.monkeypatch.setattr( | ||
"meggie.actions.epochs_create.dialogs.createEpochsFromEventsDialogMain.exc_messagebox", | ||
patched_exc_messagebox, | ||
) | ||
|
||
self.run_action( | ||
tab_id="epochs", action_name="epochs_create", handler=CreateEpochs | ||
) | ||
dialog = self.find_dialog(CreateEpochsFromEventsDialog) | ||
|
||
event = {"event_id": 1, "mask": 0} | ||
item = QtWidgets.QListWidgetItem( | ||
"%s, %s" % ("ID " + str(event["event_id"]), "mask=" + str(event["mask"])) | ||
) | ||
dialog.ui.listWidgetEvents.addItem(item) | ||
dialog.events = [event] | ||
|
||
dialog.accept() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
|
||
|
||
class PlotTSE(Action): | ||
|
||
def run(self): | ||
"""Plots a TSE from TFR object.""" | ||
try: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import tempfile | ||
import pytest | ||
import json | ||
import os | ||
import pkg_resources | ||
|
||
from PyQt5.QtWidgets import QApplication, QMainWindow | ||
|
||
from meggie.utilities.generate_experiments import create_evoked_conditions_experiment | ||
|
||
os.environ["QT_QPA_PLATFORM"] = "offscreen" | ||
|
||
|
||
class MockMainWindow(QMainWindow): | ||
def __init__(self, *args, **kwargs): | ||
self.ui = None | ||
QMainWindow.__init__(self) | ||
|
||
def update_ui(self): | ||
pass | ||
|
||
def initialize_ui(self): | ||
pass | ||
|
||
|
||
def load_action_spec(action_name): | ||
action_path = pkg_resources.resource_filename("meggie", "actions") | ||
config_path = os.path.join(action_path, action_name, "configuration.json") | ||
with open(config_path, "r") as f: | ||
action_spec = json.load(f) | ||
return action_spec | ||
|
||
|
||
class BaseTestAction: | ||
@pytest.fixture(autouse=True) | ||
def setup_common(self, qtbot, monkeypatch): | ||
os.environ["QT_QPA_PLATFORM"] = "offscreen" | ||
self.qtbot = qtbot | ||
self.monkeypatch = monkeypatch | ||
self.mock_main_window = MockMainWindow() | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
self.dirpath = tmpdirname | ||
self.setup_experiment() | ||
yield | ||
|
||
def setup_experiment(self): | ||
self.experiment = create_evoked_conditions_experiment( | ||
self.dirpath, "test_experiment", n_subjects=1 | ||
) | ||
self.experiment.activate_subject("sample_01-raw") | ||
|
||
def run_action(self, tab_id, action_name, handler): | ||
data = {"tab_id": tab_id} | ||
action_spec = load_action_spec(action_name) | ||
self.action_instance = handler( | ||
self.experiment, data, self.mock_main_window, action_spec | ||
) | ||
self.action_instance.run() | ||
|
||
def find_dialog(self, dialog_class): | ||
dialog = None | ||
for widget in QApplication.topLevelWidgets(): | ||
if isinstance(widget, dialog_class): | ||
dialog = widget | ||
break | ||
assert dialog is not None | ||
return dialog |