Browse Source

Merge pull request #165 from bpoldrack/tst-click-cmdui

Add cmdui test
Michael Hanke 1 year ago
parent
commit
133a4dfbf6

+ 14 - 0
datalad_gooey/conftest.py

@@ -4,9 +4,23 @@ import pytest
 
 from PySide6.QtWidgets import QApplication
 
+from .app import GooeyApp
+
 
 @pytest.fixture(scope="package", autouse=True)
 def get_headless_qtapp():
     qtapp = QApplication.instance()
     if not qtapp:
         QApplication(['test_app', '-platform', 'offscreen'])
+
+
+@pytest.fixture(scope="function")
+def gooey_app(tmp_path):
+    try:
+        gooey = GooeyApp(tmp_path)
+        # maybe leave that to a caller?
+        gooey.main_window.show()
+        yield gooey
+    finally:
+        if gooey is not None:
+            gooey.deinit()

+ 3 - 0
datalad_gooey/dataladcmd_ui.py

@@ -101,6 +101,9 @@ class GooeyDataladCmdUI(QObject):
             get_cmd_displayname(api, cmdname).replace('&', '')
         )
         self._cmd_title.setToolTip(f'API command: `{cmdname}`')
+        # deposit the command name in the widget, to be retrieved later by
+        # retrieve_parameters()
+        self.pform.datalad_cmd_name = cmdname
         # make sure the UI is visible
         self.pwidget.setEnabled(True)
 

+ 0 - 3
datalad_gooey/param_form_utils.py

@@ -47,9 +47,6 @@ def populate_form_w_params(
     # localize to potentially delay heavy import
     from datalad import api as dlapi
 
-    # deposit the command name in the widget, to be retrieved later by
-    # retrieve_parameters()
-    formlayout.datalad_cmd_name = cmdname
     # get the matching callable from the DataLad API
     cmd = getattr(dlapi, cmdname)
     cmd_api_spec = api.get(cmdname, {})

+ 41 - 4
datalad_gooey/tests/test_dataladcmd_ui.py

@@ -1,7 +1,44 @@
-from PySide6.QtWidgets import QWidget
+from PySide6.QtWidgets import (
+    QDialogButtonBox,
+    QPushButton
+)
+from PySide6.QtCore import Qt
+
 from ..dataladcmd_ui import GooeyDataladCmdUI
+from datalad.tests.utils_pytest import (
+    assert_equal,
+    assert_false,
+    assert_in,
+    assert_is_not_none,
+    assert_true,
+)
+
+
+def test_GooeyDataladCmdUI(gooey_app, *, qtbot):
+    qtbot.addWidget(gooey_app.main_window)
+    cmdui = GooeyDataladCmdUI(gooey_app, gooey_app.get_widget('cmdTab'))
+
+    cmdui.configure('wtf', {})
+
+    # command tab is set up:
+    assert_true(cmdui.pwidget.isEnabled())
+    assert_equal(
+        gooey_app.get_widget('contextTabs').currentWidget().objectName(),
+        "cmdTab")
+    assert_equal(cmdui._cmd_title.text().lower(), "wtf")
+
+    # click OK and see the correct signal:
+    buttonbox = cmdui.pwidget.findChild(QDialogButtonBox, 'cmdTabButtonBox')
+    ok_button = buttonbox.button(QDialogButtonBox.StandardButton.Ok)
+    assert_is_not_none(ok_button)
+
+    with qtbot.waitSignal(cmdui.configured_dataladcmd) as blocker:
+        qtbot.mouseClick(ok_button, Qt.LeftButton)
 
+    assert_equal(blocker.args[0], 'wtf')
+    assert_in("decor", blocker.args[1].keys())
 
-def test_GooeyDataladCmdUI():
-    parent = QWidget()
-    GooeyDataladCmdUI(None, parent)
+    # reset_form
+    cmdui.reset_form()
+    assert_equal(cmdui._cmd_title.text().lower(), "")
+    assert_false(cmdui.pwidget.isEnabled())

+ 2 - 4
datalad_gooey/tests/test_fsbrowser_item.py

@@ -8,7 +8,6 @@ from datalad.tests.utils_pytest import (
     assert_in,
     assert_not_in,
     assert_raises,
-    with_tempfile,
 
 )
 from PySide6.QtCore import (
@@ -18,9 +17,8 @@ from PySide6.QtCore import (
 from ..status_light import GooeyStatusLight
 
 
-@with_tempfile
-def test_GooeyStatusLight(path=None):
-    ds = Dataset(path).create()
+def test_GooeyStatusLight(tmp_path):
+    ds = Dataset(tmp_path).create()
     GooeyStatusLight.__call__(dataset=ds, path=ds.pathobj)
 
 

+ 2 - 5
datalad_gooey/tests/test_status_light.py

@@ -1,12 +1,9 @@
 
 from datalad.distribution.dataset import Dataset
 
-from datalad.tests.utils_pytest import with_tempfile
-
 from ..status_light import GooeyStatusLight
 
 
-@with_tempfile
-def test_GooeyStatusLight(path=None):
-    ds = Dataset(path).create()
+def test_GooeyStatusLight(tmp_path):
+    ds = Dataset(tmp_path).create()
     GooeyStatusLight.__call__(dataset=ds, path=ds.pathobj)