Commit 9ec37bd8 authored by Samuel Jones's avatar Samuel Jones
Browse files

Re #30308 Ensure correct closeEvent is called.

parent 5812ecc2
......@@ -176,16 +176,12 @@ class PeaksViewerCollectionPresenterTest(unittest.TestCase):
presenter.remove_peaksworkspace.assert_called_once_with("ws")
presenter.append_peaksworkspace.assert_called_once_with("ws1")
def test_ensure_close_called(self, _):
def test_ensure_clear_observer_sets_observer_to_none(self, _):
presenter = PeaksViewerCollectionPresenter(MagicMock())
presenter._view = MagicMock()
presenter._child_presenters = MagicMock()
presenter._ads_observer = MagicMock()
presenter.close_called()
presenter.clear_observer()
self.assertEqual(presenter._view, None)
self.assertEqual(presenter._child_presenters, [])
self.assertEqual(presenter._ads_observer, None)
......
......@@ -426,7 +426,7 @@ class SliceViewerTest(unittest.TestCase):
self.view.setWindowTitle.assert_called_with(self.model.get_title())
presenter.new_plot.assert_called_once()
def test_close_event_peaks_presenter_not_none(self):
def test_clear_observer_peaks_presenter_not_none(self):
presenter, _ = _create_presenter(self.model,
self.view,
mock.MagicMock(),
......@@ -434,11 +434,11 @@ class SliceViewerTest(unittest.TestCase):
supports_nonortho=False)
presenter._peaks_presenter = mock.MagicMock()
presenter.close_called()
presenter.clear_observer()
presenter._peaks_presenter.close_called.assert_called_once()
presenter._peaks_presenter.clear_observer.assert_called_once()
def test_close_event_peaks_presenter_is_none(self):
def test_clear_observer_peaks_presenter_is_none(self):
presenter, _ = _create_presenter(self.model,
self.view,
mock.MagicMock(),
......@@ -447,7 +447,7 @@ class SliceViewerTest(unittest.TestCase):
presenter._peaks_presenter = None
# Will raise exception if misbehaving.
presenter.close_called()
presenter.clear_observer()
if __name__ == '__main__':
......
......@@ -13,10 +13,8 @@ from unittest.mock import patch
from numpy import hstack
import matplotlib as mpl
from mantidqt.widgets.colorbar.colorbar import MIN_LOG_VALUE
mpl.use('Agg')
from mantidqt.widgets.colorbar.colorbar import MIN_LOG_VALUE # noqa: E402
from mantid.simpleapi import ( # noqa: E402
CreateMDHistoWorkspace, CreateMDWorkspace, CreateSampleWorkspace, DeleteWorkspace,
FakeMDEventData, ConvertToDistribution, Scale, SetUB, RenameWorkspace)
......@@ -26,6 +24,7 @@ from mantidqt.utils.qt.testing.qt_widget_finder import QtWidgetFinder # noqa: E
from mantidqt.widgets.sliceviewer.presenter import SliceViewer # noqa: E402
from mantidqt.widgets.sliceviewer.toolbar import ToolItemText # noqa: E402
from qtpy.QtWidgets import QApplication # noqa: E402
from qtpy.QtGui import QCloseEvent # noqa: E402
from math import inf # noqa: E402
......@@ -243,11 +242,11 @@ class SliceViewerViewTest(unittest.TestCase, QtWidgetFinder):
def test_close_event(self):
pres = SliceViewer(self.histo_ws)
self.assert_widget_created()
pres.close_called = mock.MagicMock()
pres.clear_observer = mock.MagicMock()
pres.view.closeEvent()
pres.view.closeEvent(QCloseEvent())
pres.close_called.assert_called_once()
pres.clear_observer.assert_called_once()
def test_plot_matrix_xlimits_ignores_monitors(self):
xmin = 5000
......
......@@ -526,7 +526,7 @@ class SliceViewerDataView(QWidget):
self.conf.set(POWERSCALE, exponent)
class SliceViewerView(QWidget, ObservingView):
class SliceViewerView(ObservingView, QWidget):
"""Combines the data view for the slice viewer with the optional peaks viewer."""
close_signal = Signal()
rename_signal = Signal(str)
......@@ -610,7 +610,3 @@ class SliceViewerView(QWidget, ObservingView):
def _on_rename(self, new_title):
self.setWindowTitle(new_title)
def closeEvent(self, event):
super().closeEvent(event)
self.presenter.clear_observer()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment