Skip to content

Commit

Permalink
Fixed ADS observer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilkeSchomann committed Dec 9, 2024
1 parent e138c2e commit 70c2bca
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions tests/workspacemanager_presenter_ads_test.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 70c2bca

Please sign in to comment.