Skip to content

Commit 899d99d

Browse files
committed
tests: fix broken and speed-up GUI tests
1 parent 9f2aa43 commit 899d99d

3 files changed

Lines changed: 20 additions & 44 deletions

File tree

dcoraid/dbmodel/meta_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _initialize(self, circle_ids=None):
146146

147147
#: Dict of dataset ID indices
148148
self._dataset_index_dict = {
149-
ds_id:ii for (ii, ds_id) in enumerate(self._dataset_ids)}
149+
ds_id: ii for (ii, ds_id) in enumerate(self._dataset_ids)}
150150

151151
def __enter__(self):
152152
return self

tests/test_dbmodel_api.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,19 @@ def test_search_dataset_since_time():
189189
db = db_api.APIInterrogator(api=api)
190190
tstart = time.time()
191191

192-
# Normally, this should not return anything, except for a race
193-
# condition when multiple tests are running at the same time.
194-
de0 = db.search_dataset_via_api(since_time=tstart)
195-
196192
# Create a dataset
197193
ds_dict = common.make_dataset_for_download()
198194

199-
time.sleep(.5)
200-
201195
# Run the query again
202-
de1 = db.search_dataset_via_api(since_time=tstart)
203-
# The new dataset should be in the results.
204-
assert len(de1) > len(de0)
205-
206-
for item in de1:
207-
if item["id"] == ds_dict["id"]:
196+
for ii in range(10):
197+
de1 = db.search_dataset_via_api(since_time=tstart-10,
198+
limit=0)
199+
# The new dataset should be in the results.
200+
ids = [d["id"] for d in de1]
201+
if ds_dict["id"] in ids:
208202
break
209203
else:
210-
assert False, "created dataset not found"
204+
assert False, "Created dataset does not exist"
211205

212206

213207
@pytest.mark.skipif(not HAS_FIGSHARE_ACCESS,

tests/test_gui.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from dcoraid.gui.panel_uploads import widget_upload
1313

1414
import pytest
15-
from PyQt6 import QtCore, QtGui, QtWidgets, QtTest
15+
from PyQt6 import QtCore, QtGui, QtWidgets
1616
from PyQt6.QtWidgets import QInputDialog, QMessageBox
1717

1818
from . import common
@@ -33,27 +33,21 @@ def mw(qtbot):
3333
QtCore.QSettings.setDefaultFormat(QtCore.QSettings.Format.IniFormat)
3434
settings = QtCore.QSettings()
3535
settings.setValue("auth/server", common.SERVER)
36-
QtTest.QTest.qWait(100)
3736
QtWidgets.QApplication.processEvents(
38-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
39-
qtbot.wait(100)
37+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
4038
# Code that will run before your test
4139
mw = DCORAid()
4240
qtbot.addWidget(mw)
4341
QtWidgets.QApplication.setActiveWindow(mw)
44-
QtTest.QTest.qWait(100)
4542
QtWidgets.QApplication.processEvents(
46-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
47-
qtbot.wait(100)
43+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
4844
# Run test
4945
yield mw
5046
# Make sure that all daemons are gone
5147
mw.close()
5248
# It is extremely weird, but this seems to be important to avoid segfaults!
53-
QtTest.QTest.qWait(100)
5449
QtWidgets.QApplication.processEvents(
55-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
56-
qtbot.wait(100)
50+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
5751

5852

5953
@pytest.mark.filterwarnings("ignore::UserWarning",
@@ -86,8 +80,7 @@ def test_gui_anonymous(qtbot):
8680
qtbot.addWidget(mw)
8781
QtWidgets.QApplication.setActiveWindow(mw)
8882
QtWidgets.QApplication.processEvents(
89-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
90-
qtbot.wait(100)
83+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
9184
# sanity check
9285
assert mw.settings.value("user scenario") == "anonymous"
9386
assert mw.settings.value("auth/server") == "dcor.mpl.mpg.de"
@@ -100,10 +93,8 @@ def test_gui_anonymous(qtbot):
10093
spath.unlink()
10194
shutil.copy2(stmp, spath)
10295
mw.close()
103-
QtTest.QTest.qWait(500)
10496
QtWidgets.QApplication.processEvents(
105-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
106-
qtbot.wait(100)
97+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
10798

10899

109100
def test_gui_mydata_dataset_add_to_collection(mw, qtbot):
@@ -169,18 +160,14 @@ def test_gui_start_with_bad_server(qtbot):
169160
mw = DCORAid()
170161
qtbot.addWidget(mw)
171162
QtWidgets.QApplication.setActiveWindow(mw)
172-
QtTest.QTest.qWait(200)
173163
QtWidgets.QApplication.processEvents(
174-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
175-
qtbot.wait(100)
164+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
176165
# just make sure that DCOR-Aid thinks it is offline
177166
assert not mw.panel_upload.isEnabled()
178167
assert not mw.panel_download.isEnabled()
179168
mw.close()
180-
QtTest.QTest.qWait(500)
181169
QtWidgets.QApplication.processEvents(
182-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
183-
qtbot.wait(100)
170+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
184171
except BaseException:
185172
raise
186173
finally:
@@ -201,19 +188,15 @@ def test_gui_start_with_bad_api_key(qtbot):
201188
mw = DCORAid()
202189
qtbot.addWidget(mw)
203190
QtWidgets.QApplication.setActiveWindow(mw)
204-
QtTest.QTest.qWait(200)
205191
QtWidgets.QApplication.processEvents(
206-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
207-
qtbot.wait(100)
192+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
208193
# just make sure that DCOR-Aid thinks it is offline
209194
assert not mw.panel_upload.isEnabled()
210195
# downloads should still be possible
211196
assert mw.panel_download.isEnabled()
212197
mw.close()
213-
QtTest.QTest.qWait(500)
214198
QtWidgets.QApplication.processEvents(
215-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
216-
qtbot.wait(100)
199+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
217200
except BaseException:
218201
raise
219202
finally:
@@ -242,7 +225,7 @@ def test_gui_upload_simple(mw, qtbot):
242225

243226
mw.panel_upload.widget_jobs.update_job_status()
244227
QtWidgets.QApplication.processEvents(
245-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 500)
228+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
246229
assert mw.database.get_dataset_dictionary(dlg.dataset_id)
247230

248231

@@ -379,8 +362,7 @@ def test_gui_upload_task_missing_circle(mw, qtbot):
379362
tpath = common.make_upload_task(task_id=task_id,
380363
dataset_dict=dataset_dict)
381364
QtWidgets.QApplication.processEvents(
382-
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 300)
383-
qtbot.wait(100)
365+
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
384366
defaults = common.get_test_defaults()
385367
with mock.patch.object(
386368
QtWidgets.QFileDialog, "getOpenFileNames",

0 commit comments

Comments
 (0)