Skip to content
Snippets Groups Projects
ISISIndirectSimulationTest.py 2.38 KiB
Newer Older
#pylint: disable=no-init,attribute-defined-outside-init
from __future__ import (absolute_import, division, print_function)
import stresstesting
import mantid.simpleapi as ms

#====================================================================================================
class MolDynCdlTest(stresstesting.MantidStressTest):

    def runTest(self):
Dan Nixon's avatar
Dan Nixon committed
        ms.MolDyn(Data='DISF_NaF.cdl',
                  Functions=['Fqt-total', 'Sqw-total'],
                  OutputWorkspace='ISISIndirectSimulationTest_MolDynCdl')

    def validate(self):
        self.tolerance = 1e-2
        self.disableChecking.append("Instrument")

        ms.Load(Filename='ISISIndirectSimulation_MolDynCDL.nxs',
                OutputWorkspace='ISISIndirectSimulation_MolDynCDL')
        ms.Load(Filename='ISISIndirectSimulation_MolDynCDL_SQW.nxs',
                OutputWorkspace='ISISIndirectSimulation_MolDynCDL_SQW')

        # check each of the resulting workspaces match
        ws1Match = self.checkWorkspacesMatch('DISF_NaF_Fqt-total', 'ISISIndirectSimulation_MolDynCDL')
        ws2Match = self.checkWorkspacesMatch('DISF_NaF_Sqw-total', 'ISISIndirectSimulation_MolDynCDL_SQW')

        return  ws1Match and ws2Match

    def checkWorkspacesMatch(self, ws1, ws2):
        """
        Function to check two workspaces match
        Used when the result of a test produces more than a single workspace
        """

Gagik Vardanyan's avatar
Gagik Vardanyan committed
        checker = ms.AlgorithmManager.create("CompareWorkspaces")
        checker.setLogging(True)
        checker.setPropertyValue("Workspace1", ws1)
        checker.setPropertyValue("Workspace2", ws2)
        checker.setPropertyValue("Tolerance", str(self.tolerance))
        checker.setPropertyValue("CheckInstrument","0")

        checker.execute()

Gagik Vardanyan's avatar
Gagik Vardanyan committed
        if not checker.getProperty("Result"):
            print(self.__class__.__name__)
            ms.SaveNexus(InputWorkspace=ws2,Filename=self.__class__.__name__+'-mismatch.nxs')
            return False

        return True


#====================================================================================================
class MolDynDatTest(stresstesting.MantidStressTest):

    def runTest(self):
Dan Nixon's avatar
Dan Nixon committed
        ms.MolDyn(Data='WSH_test.dat',
                  OutputWorkspace='WSH_test_iqt')

    def validate(self):
        self.tolerance = 1e-2
        self.disableChecking.append("Instrument")

        return 'WSH_test_iqt', 'ISISIndirectSimulation_MolDynDAT.nxs'