ReflectometryISISPreprocessTest.py 3.17 KB
Newer Older
1
2
3
4
5
6
7
8
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
#   NScD Oak Ridge National Laboratory, European Spallation Source,
#   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import unittest

9
from mantid.api import IEventWorkspace, MatrixWorkspace, WorkspaceGroup
10
11
12
from mantid.simpleapi import CreateSampleWorkspace
from plugins.algorithms.WorkflowAlgorithms.ReflectometryISISPreprocess import ReflectometryISISPreprocess
from testhelpers import create_algorithm
13
14


15
16
17
18
class ReflectometryISISPreprocessTest(unittest.TestCase):
    def test_input_run_is_loaded_histo_mode_by_default(self):
        args = {'InputRunList': '13460',
                "OutputWorkspace": "ws"}
19
        output_ws = self._run_test(args)
20
21
        self.assertIsInstance(output_ws, MatrixWorkspace)
        self.assertEqual("Workspace2D", output_ws.id())
22

23
24
25
26
    def test_input_run_is_loaded_histo_mode(self):
        args = {'InputRunList': '13460',
                "EventMode": False,
                "OutputWorkspace": "ws"}
27
        output_ws = self._run_test(args)
28
29
        self.assertIsInstance(output_ws, MatrixWorkspace)
        self.assertEqual("Workspace2D", output_ws.id())
30

31
32
33
34
    def test_input_run_is_loaded_event_mode(self):
        args = {'InputRunList': '13460',
                "EventMode": True,
                "OutputWorkspace": "ws"}
35
        output_ws = self._run_test(args)
36
37
        self.assertIsInstance(output_ws, IEventWorkspace)

38
    def test_validation_of_event_workspaces_without_proton_charge_throws(self):
39
        ws = CreateSampleWorkspace()
40

41
42
        with self.assertRaisesRegex(RuntimeError, "proton_charge"):
            ReflectometryISISPreprocess._validate_event_ws(ws)
43

44
    def test_validation_of_event_workspace_group_throws(self):
45
        ws = WorkspaceGroup()
46

47
        with self.assertRaisesRegex(RuntimeError, "Workspace Groups"):
48
49
            ReflectometryISISPreprocess._validate_event_ws(ws)

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    def test_monitors_are_not_loaded_in_histo_mode(self):
        args = {'InputRunList': '13460',
                "EventMode": False,
                "OutputWorkspace": "ws"}
        output_ws, monitor_ws = self._run_test_with_monitors(args)
        self.assertIsInstance(output_ws, MatrixWorkspace)
        self.assertIsNone(monitor_ws)

    def test_monitors_are_loaded_in_event_mode(self):
        args = {'InputRunList': '13460',
                "EventMode": True,
                "OutputWorkspace": "ws"}
        output_ws, monitor_ws = self._run_test_with_monitors(args)
        self.assertIsInstance(output_ws, IEventWorkspace)
        self.assertIsInstance(monitor_ws, MatrixWorkspace)

    def _run_test_with_monitors(self, args):
67
68
69
70
71
        alg = create_algorithm('ReflectometryISISPreprocess', **args)
        alg.setChild(True)
        alg.setRethrows(True)
        alg.execute()
        output_ws = alg.getProperty('OutputWorkspace').value
72
73
74
75
76
        monitor_ws = alg.getProperty('MonitorWorkspace').value
        return output_ws, monitor_ws

    def _run_test(self, args):
        output_ws, _ = self._run_test_with_monitors(args)
77
        return output_ws
78

79
80
81

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