Skip to content

Commit f0df1f9

Browse files
author
Dimitar Tasev
committed
Return tests, mock out other instantiations of MainWindowView
1 parent 1c0f69a commit f0df1f9

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

mantidimaging/gui/windows/main/test/view_test.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
class MainWindowViewTest(unittest.TestCase):
2424
def setUp(self) -> None:
2525
with mock.patch("mantidimaging.gui.windows.main.view.WelcomeScreenPresenter"):
26-
self.view = MainWindowView()
26+
with mock.patch("mantidimaging.gui.windows.main.view.has_other_shared_arrays", return_value=False):
27+
self.view = MainWindowView()
2728
self.presenter = mock.MagicMock()
2829
self.view.presenter = self.presenter
2930

@@ -306,3 +307,34 @@ def test_get_images_from_stack_uuid(self):
306307

307308
self.presenter.get_stack_visualiser.assert_called_once_with(uuid)
308309
self.assertEqual(images, return_value)
310+
311+
@mock.patch("mantidimaging.gui.windows.main.view.has_other_shared_arrays")
312+
@mock.patch("mantidimaging.gui.windows.main.view.free_all")
313+
@mock.patch("mantidimaging.gui.windows.main.view.QMessageBox")
314+
def test_ask_user_to_free_data(self, QMessageBox: Mock, free_all: Mock, has_other_shared_arrays: Mock):
315+
has_other_shared_arrays.return_value = True
316+
# makes the clickedButton the same return value mock as the addButton return
317+
QMessageBox.return_value.clickedButton.return_value = QMessageBox.return_value.addButton.return_value
318+
319+
self.view.ask_user_to_free_data()
320+
321+
QMessageBox.return_value.setWindowTitle.assert_called_once()
322+
QMessageBox.return_value.setText.assert_called_once()
323+
self.assertEquals(QMessageBox.return_value.addButton.call_count, 2)
324+
QMessageBox.return_value.exec.assert_called_once()
325+
free_all.assert_called_once()
326+
327+
@mock.patch("mantidimaging.gui.windows.main.view.has_other_shared_arrays")
328+
@mock.patch("mantidimaging.gui.windows.main.view.free_all")
329+
@mock.patch("mantidimaging.gui.windows.main.view.QMessageBox")
330+
def test_ask_user_to_free_data_ignore_pressed(self, QMessageBox: Mock, free_all: Mock,
331+
has_other_shared_arrays: Mock):
332+
has_other_shared_arrays.return_value = True
333+
334+
self.view.ask_user_to_free_data()
335+
336+
QMessageBox.return_value.setWindowTitle.assert_called_once()
337+
QMessageBox.return_value.setText.assert_called_once()
338+
self.assertEquals(QMessageBox.return_value.addButton.call_count, 2)
339+
QMessageBox.return_value.exec.assert_called_once()
340+
free_all.assert_not_called()

mantidimaging/gui/windows/operations/test/test_view.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class OperationsWindowsViewTest(unittest.TestCase):
1717
def setUp(self):
1818
# mock the view so it has the same methods
1919
with mock.patch("mantidimaging.gui.windows.main.view.WelcomeScreenPresenter"):
20-
self.main_window = MainWindowView()
20+
with mock.patch("mantidimaging.gui.windows.main.view.has_other_shared_arrays", return_value=False):
21+
self.main_window = MainWindowView()
2122
self.window = FiltersWindowView(self.main_window)
2223

2324
def test_collapse(self):

mantidimaging/gui/windows/stack_visualiser/test/view_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def tearDown(self) -> None:
3838

3939
def setUp(self):
4040
with mock.patch("mantidimaging.gui.windows.main.view.WelcomeScreenPresenter"):
41-
self.window = MainWindowView()
41+
with mock.patch("mantidimaging.gui.windows.main.view.has_other_shared_arrays", return_value=False):
42+
self.window = MainWindowView()
4243
self.window.remove_stack = mock.Mock()
4344
self.dock, self.view, self.test_data = self._add_stack_visualiser()
4445

0 commit comments

Comments
 (0)