Skip to content

Commit

Permalink
gui tests now disable stdout gathering by default
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyTeichman committed Dec 20, 2023
1 parent e207f88 commit 0c82759
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
35 changes: 20 additions & 15 deletions rnalysis/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2866,8 +2866,27 @@ class MainWindow(QtWidgets.QMainWindow):

jobQueued = QtCore.pyqtSignal()

def __init__(self):
def __init__(self, gather_stdout: bool = True):
super().__init__()
if gather_stdout:
self.queue_stdout = Queue()
# create console text read thread + receiver object
self.thread_stdout_queue_listener = QtCore.QThread()
self.stdout_receiver = gui_widgets.ThreadStdOutStreamTextQueueReceiver(self.queue_stdout)
sys.stdout = gui_widgets.WriteStream(self.queue_stdout)

# attach console text receiver to console text thread
self.stdout_receiver.moveToThread(self.thread_stdout_queue_listener)
# connect receiver object to widget for text update
self.stdout_receiver.queue_stdout_element_received_signal.connect(self.append_text_to_current_console)
# attach to start / stop methods
self.thread_stdout_queue_listener.started.connect(self.stdout_receiver.run)
self.thread_stdout_queue_listener.start()
else:
self.queue_stdout = None
self.stdout_receiver = None
self.thread_stdout_queue_listener = None

self._generate_report = False
self.report = None
self.tabs = ReactiveTabWidget(self)
Expand Down Expand Up @@ -2909,20 +2928,6 @@ def __init__(self):
self.init_menu_ui()
self.init_shortcuts()

self.queue_stdout = Queue()
# create console text read thread + receiver object
self.thread_stdout_queue_listener = QtCore.QThread()
self.stdout_receiver = gui_widgets.ThreadStdOutStreamTextQueueReceiver(self.queue_stdout)
sys.stdout = gui_widgets.WriteStream(self.queue_stdout)

# attach console text receiver to console text thread
self.stdout_receiver.moveToThread(self.thread_stdout_queue_listener)
# connect receiver object to widget for text update
self.stdout_receiver.queue_stdout_element_received_signal.connect(self.append_text_to_current_console)
# attach to start / stop methods
self.thread_stdout_queue_listener.started.connect(self.stdout_receiver.run)
self.thread_stdout_queue_listener.start()

# init thread execution attributes
self.current_worker = None
self.thread = QtCore.QThread()
Expand Down
7 changes: 5 additions & 2 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def main_window(qtbot, monkeypatch, use_temp_settings_file):
monkeypatch.setattr(gui_widgets.ThreadStdOutStreamTextQueueReceiver, 'run', lambda self: None)
monkeypatch.setattr(gui_quickstart.QuickStartWizard, '__init__', lambda *args, **kwargs: None)
settings.set_show_tutorial_settings(False)
qtbot, window = widget_setup(qtbot, MainWindow)
qtbot, window = widget_setup(qtbot, MainWindow, gather_stdout=False)
warnings.showwarning = customwarn
# sys.excepthook = window.excepthook
builtins.input = window.input
Expand All @@ -103,7 +103,10 @@ def main_window(qtbot, monkeypatch, use_temp_settings_file):
app = QtWidgets.QApplication.instance()
if app is not None:
for w in app.topLevelWidgets():
w.close()
try:
w.close()
except RuntimeError:
continue


@pytest.fixture
Expand Down

0 comments on commit 0c82759

Please sign in to comment.