Skip to content

Commit

Permalink
Use add_to_ads
Browse files Browse the repository at this point in the history
  • Loading branch information
SilkeSchomann committed Dec 6, 2024
1 parent 63536ca commit 26955a4
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions tests/workspacemanager_presenter_ads_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import mock
from mock import MagicMock
import numpy as np

from mantid.api import AnalysisDataService
from mantid.simpleapi import RenameWorkspace
Expand All @@ -12,30 +13,25 @@
from mslice.presenters.workspace_manager_presenter import WorkspaceManagerPresenter
from mslice.views.interfaces.mainview import MainView
from mslice.views.interfaces.workspace_view import WorkspaceView
from mslice.util.mantid.mantid_algorithms import CreateSampleWorkspace
from mslice.util.mantid.mantid_algorithms import CreateWorkspace
from mslice.util.mantid.algorithm_wrapper import add_to_ads


class WorkspaceManagerPresenterTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
x = np.linspace(0, 99, 100)
y = x * 1
e = y * 0 + 2
cls.m_workspace = CreateWorkspace(x, y, e, OutputWorkspace="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_clear_handle(self):
presenter = WorkspaceManagerPresenter(self.view)
presenter.clear_handle = MagicMock()
self.assertTrue(isinstance(presenter._ads_observer, MSliceADSObserver))
presenter._ads_observer = MSliceADSObserver(
presenter.delete_handle, presenter.clear_handle, presenter.rename_handle
)

AnalysisDataService.addOrReplace("ws", CreateSampleWorkspace(OutputWorkspace="ws"))
AnalysisDataService.clear(True)

presenter.clear_handle.assert_called_once()

def test_ensure_that_the_ads_observer_calls_delete_handle(self):
presenter = WorkspaceManagerPresenter(self.view)
presenter.delete_handle = MagicMock()
Expand All @@ -44,7 +40,7 @@ def test_ensure_that_the_ads_observer_calls_delete_handle(self):
presenter.delete_handle, presenter.clear_handle, presenter.rename_handle
)

AnalysisDataService.addOrReplace("ws", CreateSampleWorkspace(OutputWorkspace="ws"))
add_to_ads(self.m_workspace)
AnalysisDataService.remove("ws")

presenter.delete_handle.assert_called_once_with("ws")
Expand All @@ -57,11 +53,24 @@ def test_ensure_that_the_ads_observer_calls_rename_handle(self):
presenter.delete_handle, presenter.clear_handle, presenter.rename_handle
)

AnalysisDataService.addOrReplace("ws", CreateSampleWorkspace(OutputWorkspace="ws"))
add_to_ads(self.m_workspace)
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.clear_handle = MagicMock()
self.assertTrue(isinstance(presenter._ads_observer, MSliceADSObserver))
presenter._ads_observer = MSliceADSObserver(
presenter.delete_handle, presenter.clear_handle, presenter.rename_handle
)

add_to_ads(self.m_workspace)
AnalysisDataService.clear(True)

presenter.clear_handle.assert_called_once()


if __name__ == '__main__':
unittest.main()

0 comments on commit 26955a4

Please sign in to comment.