IMaskWorkspaceTest.py 1.36 KB
Newer Older
1
2
3
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
#   NScD Oak Ridge National Laboratory, European Spallation Source,
#   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
# SPDX - License - Identifier: GPL - 3.0 +
7
8
9
10
import unittest
from mantid.api import AnalysisDataService, IMaskWorkspace
from testhelpers import run_algorithm, WorkspaceCreationHelper

11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class IMaskWorkspaceTest(unittest.TestCase):

    def test_MaskWorkspace_Is_Retrievable(self):
        dummy_ws = WorkspaceCreationHelper.create2DWorkspaceWithFullInstrument(2, 102, False) # no monitors
        ws_name = "dummy"
        AnalysisDataService.add(ws_name, dummy_ws)
        run_algorithm('MaskDetectors', Workspace=ws_name, WorkspaceIndexList=1)
        mask_name = 'mask_ws'
        run_algorithm('ExtractMask', InputWorkspace=ws_name, OutputWorkspace=mask_name)
        masked_ws = AnalysisDataService[mask_name]

        self.assertTrue(isinstance(masked_ws, IMaskWorkspace))
        self.assertEqual(1, masked_ws.getNumberMasked())
        # single number
        self.assertTrue(not masked_ws.isMasked(1))
        self.assertTrue(masked_ws.isMasked(2))
        # list
        self.assertTrue(not masked_ws.isMasked([1]))
        self.assertTrue(masked_ws.isMasked([2]))


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