Skip to content

Commit

Permalink
Move new tests to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
SilkeSchomann committed Dec 6, 2024
1 parent 8ca0c83 commit fd918ca
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 47 deletions.
68 changes: 68 additions & 0 deletions tests/workspacemanager_presenter_ads_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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 mslice.models.mslice_ads_observer import MSliceADSObserver
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 mslice.util.mantid.mantid_algorithms import CreateSampleWorkspace


class WorkspaceManagerPresenterTest(unittest.TestCase):

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
)

CreateSampleWorkspace(OutputWorkspace="ws", StoreInADS=True)
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()
self.assertTrue(isinstance(presenter._ads_observer, MSliceADSObserver))
presenter._ads_observer = MSliceADSObserver(
presenter.delete_handle, presenter.clear_handle, presenter.rename_handle
)

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

CreateSampleWorkspace(OutputWorkspace="ws", StoreInADS=True)
RenameWorkspace(InputWorkspace="ws", OutputWorkspace="ws1")

presenter.rename_handle.assert_called_once_with("ws", "ws1")


if __name__ == '__main__':
unittest.main()
49 changes: 2 additions & 47 deletions tests/workspacemanager_presenter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
import unittest

import mock
from mock import call, patch, MagicMock
from mock import call, patch
import numpy as np

from mantid.api import AnalysisDataService
from mantid.simpleapi import RenameWorkspace

from mslice.models.mslice_ads_observer import MSliceADSObserver
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 mslice.widgets.workspacemanager.command import Command
from mslice.widgets.workspacemanager import TAB_2D, TAB_NONPSD
from mslice.util.mantid.mantid_algorithms import (AddSampleLog, CreateWorkspace, CreateSimulationWorkspace,
ConvertToMD, CloneWorkspace, CreateSampleWorkspace)
ConvertToMD, CloneWorkspace)


class WorkspaceManagerPresenterTest(unittest.TestCase):
Expand Down Expand Up @@ -436,47 +432,6 @@ def test_compose_error(self):
self.presenter.notify(Command.ComposeWorkspace)
self.view._display_error.assert_called()

# 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
# )

# CreateSampleWorkspace(OutputWorkspace="ws", StoreInADS=True)
# 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()
# self.assertTrue(isinstance(presenter._ads_observer, MSliceADSObserver))
# presenter._ads_observer = MSliceADSObserver(
# presenter.delete_handle, presenter.clear_handle, presenter.rename_handle
# )

# CreateSampleWorkspace(OutputWorkspace="ws", StoreInADS=True)
# print(AnalysisDataService.getObjectNames())
# 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.rename_handle = MagicMock()
self.assertTrue(isinstance(presenter._ads_observer, MSliceADSObserver))
presenter._ads_observer = MSliceADSObserver(
presenter.delete_handle, presenter.clear_handle, presenter.rename_handle
)

CreateSampleWorkspace(OutputWorkspace="ws", StoreInADS=True)
print(AnalysisDataService.getObjectNames())
RenameWorkspace(InputWorkspace="ws", OutputWorkspace="ws1")

presenter.rename_handle.assert_called_once_with("ws", "ws1")


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

0 comments on commit fd918ca

Please sign in to comment.