Skip to content

Commit

Permalink
tests: add basic test for lme4 (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Feb 15, 2021
1 parent ac75133 commit 49a09b0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ _version_save.py

docs/*.bib.bak
.idea
build-recipes/ShapeOut2Launcher.spec
16 changes: 13 additions & 3 deletions shapeout2/gui/compute/comp_lme4.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,24 @@ def model(self):
return "glmer+loglink"

@QtCore.pyqtSlot()
def on_lme4(self):
"""Run lme4 analysis"""
def on_lme4(self, ret_dlg=False):
"""Run lme4 analysis
Parameters
----------
ret_dlg: bool
If set to True, then the dialog is returned without
`_exec`uting it (used for testing).
"""
rlme4 = lme4.Rlme4(model=self.model, feature=self.feature)
for wds in self.datasets:
wds.add_to_rlme4(self.pipeline, rlme4)
result = rlme4.fit()
dlg = Rlme4ResultsDialog(self, result)
dlg.exec_()
if ret_dlg:
return dlg
else:
dlg.exec_()

@QtCore.pyqtSlot()
def on_close(self):
Expand Down
Binary file added tests/data/version_2_5_0_dcor_lme4.so2
Binary file not shown.
55 changes: 55 additions & 0 deletions tests/test_gui_lme4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Test lme4 functionality"""
import pathlib

from shapeout2.gui.main import ShapeOut2
from shapeout2 import session
from shapeout2.gui.compute.comp_lme4 import ComputeSignificance
import pytest


data_path = pathlib.Path(__file__).parent / "data"


@pytest.fixture(autouse=True)
def run_around_tests():
# Code that will run before your test, for example:
session.clear_session()
# A test function will be run at this point
yield
# Code that will run after your test, for example:
session.clear_session()


def test_lme4_with_dcor_session(qtbot):
"""
Open a session with DCOR data and perform lme4 analysis from
dclab docs at
https://dclab.readthedocs.io/en/stable/sec_av_lme4.html
"""
mw = ShapeOut2()
qtbot.addWidget(mw)
mw.on_action_open(data_path / "version_2_5_0_dcor_lme4.so2")

# create dialog manually
dlg = ComputeSignificance(mw, pipeline=mw.pipeline)

# set the variables
# treatment rep 1
dlg.datasets[0].comboBox_group.setCurrentIndex(1)
# treatment rep 2
dlg.datasets[1].comboBox_group.setCurrentIndex(1)
dlg.datasets[0].spinBox_repeat.setValue(2)
# control rep 1
pass
# control rep 2
dlg.datasets[3].spinBox_repeat.setValue(2)
# control rep 3
dlg.datasets[4].spinBox_repeat.setValue(3)

# set the feature
feat_id = dlg.comboBox_feat.findData("deform")
dlg.comboBox_feat.setCurrentIndex(feat_id)

dlgr = dlg.on_lme4(ret_dlg=True)

assert dlgr.lineEdit_pvalue.text() == "0.012969"

0 comments on commit 49a09b0

Please sign in to comment.