Commit d627d12d authored by Gemma Guest's avatar Gemma Guest
Browse files

Add test for validating workspace groups

Re #32125
parent d19fbb23
......@@ -5,7 +5,7 @@
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
from mantid.api import (AlgorithmFactory, DataProcessorAlgorithm, MatrixWorkspaceProperty, WorkspaceGroup)
from mantid.api import (AlgorithmFactory, DataProcessorAlgorithm, MatrixWorkspaceProperty, MatrixWorkspace, WorkspaceGroup)
from mantid.kernel import (CompositeValidator, StringArrayLengthValidator, StringArrayMandatoryValidator,
StringArrayProperty, Direction)
from mantid.simpleapi import LoadEventNexus, LoadNexus
......@@ -61,12 +61,15 @@ class ReflectometryISISPreprocess(DataProcessorAlgorithm):
workspace = self._loadRun(self.getPropertyValue(self._RUNS))
self.setProperty(self._OUTPUT_WS, workspace)
def _loadRun(self, run):
def _loadRun(self, run: str) -> MatrixWorkspace:
"""Load a run as an event workspace if slicing is requested, or a histogram
workspace otherwise. Transmission runs are always loaded as histogram workspaces."""
event_mode = self.getProperty(self._EVENT_MODE).value
if event_mode:
ws = LoadEventNexus(Filename=run, LoadMonitors=True, StoreInADS=False).OutputWorkspace
alg = LoadEventNexus(Filename=run, LoadMonitors=True, StoreInADS=False)
ws = alg.OutputWorkspace
# TODO
# monitors = alg.MonitorWorkspace
self._validate_event_ws(ws)
self.log().information('Loaded event workspace')
else:
......
......@@ -7,7 +7,7 @@
import unittest
from unittest import mock
from mantid.api import IEventWorkspace, MatrixWorkspace
from mantid.api import IEventWorkspace, MatrixWorkspace, WorkspaceGroup
from mantid.simpleapi import CreateSampleWorkspace, ReflectometryISISPreprocess
......@@ -45,6 +45,17 @@ class ReflectometryISISPreprocessTest(unittest.TestCase):
with self.assertRaisesRegex(RuntimeError, "proton_charge"):
ReflectometryISISPreprocess(**args)
@mock.patch("ReflectometryISISPreprocess.LoadEventNexus")
def test_validation_of_event_workspace_group_throws(self, mocked_loader):
args = {'InputRunList': '13460',
"EventMode": True,
"OutputWorkspace": "ws"}
ws = WorkspaceGroup()
mocked_loader.return_value.OutputWorkspace = ws
with self.assertRaisesRegex(RuntimeError, "Workspace Groups"):
ReflectometryISISPreprocess(**args)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment