From 49a09b099cd98d5429000cc7145b7fe359f420f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Mon, 15 Feb 2021 10:34:19 +0100 Subject: [PATCH] tests: add basic test for lme4 (#55) --- .gitignore | 1 + shapeout2/gui/compute/comp_lme4.py | 16 +++++-- tests/data/version_2_5_0_dcor_lme4.so2 | Bin 0 -> 5207 bytes tests/test_gui_lme4.py | 55 +++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 tests/data/version_2_5_0_dcor_lme4.so2 create mode 100644 tests/test_gui_lme4.py diff --git a/.gitignore b/.gitignore index e8d3e45..a8e26d2 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,4 @@ _version_save.py docs/*.bib.bak .idea +build-recipes/ShapeOut2Launcher.spec diff --git a/shapeout2/gui/compute/comp_lme4.py b/shapeout2/gui/compute/comp_lme4.py index 2bdea4f..043c950 100644 --- a/shapeout2/gui/compute/comp_lme4.py +++ b/shapeout2/gui/compute/comp_lme4.py @@ -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): diff --git a/tests/data/version_2_5_0_dcor_lme4.so2 b/tests/data/version_2_5_0_dcor_lme4.so2 new file mode 100644 index 0000000000000000000000000000000000000000..afef5050aa2dfc5e0efe38b8aaa1b6d18d455bca GIT binary patch literal 5207 zcmeHLUufh+7*D&ctvx}}s@Df4jh=9FvrRHdHmS&oJ!@-wb?vDSo^nnmlQv#Q+L5Td2D#W6g zTCZjnaj1G_uW?kBc9?ZTN7f7^$-P2Z#P<9>M-q!t*EnralBuN=OLETF1H!V>nk>Pw zNHuh9hxk+@Oh?5!BMHqQg6mYAkS7gl74W9#xzx-?Zjh$C-J%*LPZh;99YPgVSc$sy zUGvZgx zhRX^Hedk>9mB6bqObI7YhyvFO>ExRz%Z3~$jhaO{&1~g8*up*7DtoY1Z)lsOp}=v& z-0=LEnS5>u>8yW*ZR5k%Iu8)_2)&(7Ob(#L{$*8%3#m+ zB6L2WPD>|LH3FxAeJ`M^%srb;KNaz|E3wifAk1u;g4Lm$LS}{Us_5kbdwIYpcnTMa zWUKDhgKVTt2~VoXbaSgxNVOGWInja=riklKA>U`~G+rVtR-Q%JvJ{Amg3!TyP+KNG z>97khjpj!zDpXLlj@%BDkW^}fQf-~OPx3NsvRW3b;RM(VoN$He7tlgFN89DuLT{Pl z^gLks5u$rCX8NC{hRNh+aQdGmn8~1!_Seo!EsK-&lyb_cQ&YU8)!l&iNiAkAp@za` z*57g%)`H222@89Eu~KtsTPj*)0@a)eIKf^WUX>~X;x~>v)}y+Hv5J%ufSO_gY^yr3 z4FUnilB8G`)JYS044MkPxwSz3&|-SGU#(tRr*Qf_7~IPh$kls!1 zKqz=cL&F3RR6>A2&7%0WA)p*y(sdPEB?c0NbLhr9i^q3f3+w1Js@{OrH*Y21< z_Q!4VJJhE2*gV4Vk+zRJ%yC;k-%&4o-D{f=} literal 0 HcmV?d00001 diff --git a/tests/test_gui_lme4.py b/tests/test_gui_lme4.py new file mode 100644 index 0000000..b83813d --- /dev/null +++ b/tests/test_gui_lme4.py @@ -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"