Skip to content

Commit f2feb58

Browse files
committed
tests: reduce segmentation faults during testing (#14)
1 parent 267e82a commit f2feb58

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- enh: add logging tab in GUI
44
- docs: improve doc strings
55
- ref: improve logging
6+
- tests: reduce segmentation faults during testing (#14)
67
0.14.1
78
- setup: fix build pipeline (remove editable install)
89
0.14.0

dcoraid/gui/download/widget_download.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ def download_resource(self, resource_id, condensed=False):
6868
dl_path = self.settings.value("downloads/default path", fallback)
6969
self.widget_jobs.jobs.new_job(resource_id, dl_path, condensed)
7070

71-
def stop_timers(self):
71+
def prepare_quit(self):
7272
"""Should be called before the application quits"""
7373
self.init_timer.stop()
7474
if self.widget_jobs.timer is not None:
7575
self.widget_jobs.timer.stop()
76+
if self.jobs is not None:
77+
self.jobs.__del__()
7678

7779

7880
class DownloadTableWidget(QtWidgets.QTableWidget):

dcoraid/gui/logs/widget_log.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323

2424
class StringSignalLogHandler(logging.Handler):
25+
new_message = QtCore.pyqtSignal(str)
26+
2527
def __init__(self, signal, *args, **kwargs):
2628
super(StringSignalLogHandler, self).__init__(*args, **kwargs)
2729
self.signal = signal

dcoraid/gui/main.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,13 @@ def __init__(self, *args, **kwargs):
121121
self.status_widget.request_status_update()
122122

123123
def closeEvent(self, event):
124-
self.panel_upload.stop_timers()
125-
self.panel_download.stop_timers()
126-
self.status_widget.stop_timers()
124+
root_logger = logging.getLogger()
125+
while len(root_logger.handlers) > 0:
126+
h = root_logger.handlers[0]
127+
root_logger.removeHandler(h)
128+
self.panel_upload.prepare_quit()
129+
self.panel_download.prepare_quit()
130+
self.status_widget.prepare_quit()
127131
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents,
128132
300)
129133
event.accept()

dcoraid/gui/status_widget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def set_status(self, text, tooltip, icon, server):
9696
self.toolButton_user.setToolTip(tooltip)
9797
self.toolButton_user.setIcon(QtGui.QIcon.fromTheme(icon))
9898

99-
def stop_timers(self):
99+
def prepare_quit(self):
100100
if self.timer is not None:
101101
self.timer.stop()
102102

dcoraid/gui/upload/widget_upload.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,13 @@ def on_upload_task(
348348
"\n\n".join(messages),
349349
)
350350

351-
def stop_timers(self):
351+
def prepare_quit(self):
352352
"""Should be called before the application quits"""
353353
self.init_timer.stop()
354354
if self.widget_jobs.timer is not None:
355355
self.widget_jobs.timer.stop()
356+
if self._jobs is not None:
357+
self._jobs.__del__()
356358

357359

358360
class UploadTableWidget(QtWidgets.QTableWidget):

tests/test_gui.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pathlib
22
import shutil
33
import tempfile
4-
import time
54
from unittest import mock
65

76
import uuid
@@ -42,7 +41,6 @@ def mw(qtbot):
4241
# Make sure that all daemons are gone
4342
mw.close()
4443
# It is extremely weird, but this seems to be important to avoid segfaults!
45-
time.sleep(1)
4644
QtTest.QTest.qWait(100)
4745
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents, 5000)
4846

@@ -86,7 +84,6 @@ def test_gui_anonymous(qtbot):
8684
spath.unlink()
8785
shutil.copy2(stmp, spath)
8886
mw.close()
89-
time.sleep(1)
9087
QtTest.QTest.qWait(500)
9188
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents, 500)
9289

0 commit comments

Comments
 (0)