From 70c2bcaeeb1f745f0ccb736087adfb84d2fdf7d1 Mon Sep 17 00:00:00 2001 From: Silke Schomann Date: Mon, 9 Dec 2024 09:30:12 +0000 Subject: [PATCH] Fixed ADS observer tests --- tests/workspacemanager_presenter_ads_test.py | 30 +++++--------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/tests/workspacemanager_presenter_ads_test.py b/tests/workspacemanager_presenter_ads_test.py index 25c3fab7..1c2a38f9 100644 --- a/tests/workspacemanager_presenter_ads_test.py +++ b/tests/workspacemanager_presenter_ads_test.py @@ -1,68 +1,52 @@ from __future__ import (absolute_import, division, print_function) import unittest -import mock from mock import MagicMock from mantid.api import AnalysisDataService -from mantid.simpleapi import RenameWorkspace +from mantid.simpleapi import CreateSampleWorkspace, RenameWorkspace from mslice.models.mslice_ads_observer import MSliceADSObserver -from mslice.models.workspacemanager.workspace_algorithms import export_workspace_to_ads -from mslice.presenters.interfaces.main_presenter import MainPresenterInterface from mslice.presenters.workspace_manager_presenter import WorkspaceManagerPresenter -from mslice.views.interfaces.mainview import MainView -from mslice.views.interfaces.workspace_view import WorkspaceView -from tests.testhelpers.workspace_creator import create_workspace class WorkspaceManagerPresenterTest(unittest.TestCase): - @classmethod - def setUpClass(cls): - cls.test_workspace = create_workspace('ws') - - def setUp(self): - self.view = mock.create_autospec(spec=WorkspaceView) - self.mainview = mock.create_autospec(MainView) - self.main_presenter = mock.create_autospec(MainPresenterInterface) - self.mainview.get_presenter = mock.Mock(return_value=self.main_presenter) - def test_ensure_that_the_ads_observer_calls_delete_handle(self): - presenter = WorkspaceManagerPresenter(self.view) + presenter = WorkspaceManagerPresenter(MagicMock()) presenter.delete_handle = MagicMock() self.assertTrue(isinstance(presenter._ads_observer, MSliceADSObserver)) presenter._ads_observer = MSliceADSObserver( presenter.delete_handle, presenter.clear_handle, presenter.rename_handle ) - export_workspace_to_ads(self.test_workspace) + CreateSampleWorkspace(OutputWorkspace="ws", StoreInADS=True) AnalysisDataService.remove("ws") presenter.delete_handle.assert_called_once_with("ws") def test_ensure_that_the_ads_observer_calls_rename_handle(self): - presenter = WorkspaceManagerPresenter(self.view) + presenter = WorkspaceManagerPresenter(MagicMock()) presenter.rename_handle = MagicMock() self.assertTrue(isinstance(presenter._ads_observer, MSliceADSObserver)) presenter._ads_observer = MSliceADSObserver( presenter.delete_handle, presenter.clear_handle, presenter.rename_handle ) - export_workspace_to_ads(self.test_workspace) + CreateSampleWorkspace(OutputWorkspace="ws", StoreInADS=True) RenameWorkspace(InputWorkspace="ws", OutputWorkspace="ws1") presenter.rename_handle.assert_called_once_with("ws", "ws1") def test_ensure_that_the_ads_observer_calls_clear_handle(self): - presenter = WorkspaceManagerPresenter(self.view) + presenter = WorkspaceManagerPresenter(MagicMock()) presenter.clear_handle = MagicMock() self.assertTrue(isinstance(presenter._ads_observer, MSliceADSObserver)) presenter._ads_observer = MSliceADSObserver( presenter.delete_handle, presenter.clear_handle, presenter.rename_handle ) - export_workspace_to_ads(self.test_workspace) + CreateSampleWorkspace(OutputWorkspace="ws", StoreInADS=True) AnalysisDataService.clear(True) presenter.clear_handle.assert_called_once()