ReflectometryQuickAuxiliaryTest.py 5.44 KB
Newer Older
1
import unittest
2
import numpy
3
4
5
6
7
8
9
from MantidFramework import mtd
mtd.initialise()
from mantid.simpleapi import *
from isis_reflgui import quick

class ReflectometryQuickAuxiliaryTest(unittest.TestCase):
    
10
11
12
13
14
15
16
17
18
19
20
    __wsName = None
    
    
    def __init__(self, methodName='runTest'):
        super(ReflectometryQuickAuxiliaryTest, self).__init__(methodName)
        self.__wsName = "TestWorkspace"
        LoadISISNexus(Filename='POLREF00004699', OutputWorkspace=self.__wsName)
    
    def __del__(self):
        DeleteWorkspace(mtd[self.__wsName])
        
21
22
    
    def test_cleanup(self):
23
        numObjectsOriginal = len(mtd.getObjectNames())
24
25
        todump =CreateSingleValuedWorkspace(OutputWorkspace='_toremove', DataValue=1, ErrorValue=1)
        tokeep =CreateSingleValuedWorkspace(OutputWorkspace='tokeep', DataValue=1, ErrorValue=1)
26
        self.assertEqual(numObjectsOriginal+2, len(mtd.getObjectNames()))  
27
28
29
        # Should remove workspaces starting with _
        quick.cleanup()
        cleaned_object_names = mtd.getObjectNames()
30
        self.assertEqual(numObjectsOriginal+1, len(cleaned_object_names))
31
32
        self.assertEqual(True, ('tokeep' in cleaned_object_names))
        
33
34
        DeleteWorkspace(tokeep)
        
35
36
37
38
39
40
    def test_coAdd_ws_in_ADS(self):
        inWS = CreateSingleValuedWorkspace(DataValue=1, ErrorValue=1)
        quick.coAdd('inWS', 'ProvidedName')
        outWS = mtd['_WProvidedName']
        result = CheckWorkspacesMatch(Workspace1=inWS, Workspace2=outWS)
        self.assertEquals("Success!", result)
41
        DeleteWorkspace(outWS)
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
        
    def test_coAdd_run_list(self):
        originalInstrument = config.getInstrument()
        try:
            # We have multiple runs from some MUSR files in AutoTest, lets use those.
            tempInstrument = "MUSR"
            config['default.instrument'] = tempInstrument
            runlist = '15189, 15190'
            
            # Run coAdd
            quick.coAdd(runlist, 'ProvidedName')
            
            # Get the output workspace and do some quick sanity checks
            outWS = mtd['_WProvidedName']
            self.assertEquals(outWS[0].getInstrument().getName(), tempInstrument)
            
            # Perform the addition of the two files manually
            a = LoadMuonNexus(Filename='15189')
            b = LoadMuonNexus(Filename='15190')
            c = Plus(LHSWorkspace=a[0], RHSWorkspace=b[0]) 
            
            #Check the expected calculated result against coAdd
            result = CheckWorkspacesMatch(Workspace1=c, Workspace2=outWS) 
            self.assertEquals("Success!", result)
        finally:
            config['default.instrument'] = originalInstrument.name()
68
69
70
71
72
73
74
75
76
77
            DeleteWorkspace(a[0])
            DeleteWorkspace(b[0])
            DeleteWorkspace(c)
            DeleteWorkspace(outWS)
        
    def test_groupGet_instrument(self):
        
        expectedInstrument = "POLREF"
        
        # Test with group workspace as input
78
        instrument = quick.groupGet(self.__wsName, 'inst')
79
80
81
        self.assertEquals(expectedInstrument, instrument.getName(), "Did not fetch the instrument from ws group")
        
        # Test with single workspace as input
82
        instrument = quick.groupGet(mtd[self.__wsName][0].name(), 'inst')
83
84
85
86
        self.assertEquals(expectedInstrument, instrument.getName(), "Did not fetch the instrument from ws")
        
    
    def test_groupGet_histogram_count(self):
87
        expectedNHistograms = mtd[self.__wsName][0].getNumberHistograms()
88
89
        
        # Test with group workspace as input
90
        nHistograms = quick.groupGet(self.__wsName, 'wksp')
91
92
93
        self.assertEquals(expectedNHistograms, nHistograms, "Did not fetch the n histograms from ws group")
        
        # Test with single workspace as input
94
        nHistograms = quick.groupGet(mtd[self.__wsName][0].name(), 'wksp')
95
96
97
98
99
100
101
102
        self.assertEquals(expectedNHistograms, nHistograms, "Did not fetch the n histograms from ws")
        
    
    def test_groupGet_log_single_value(self):
        
        expectedNPeriods = 2
        
        # Test with group workspace as input
103
        nPeriods = quick.groupGet(self.__wsName, 'samp', 'nperiods')
104
105
106
        self.assertEquals(expectedNPeriods, nPeriods, "Did not fetch the number of periods from ws group")
        
        # Test with single workspace as input
107
        nPeriods = quick.groupGet(mtd[self.__wsName][0].name(), 'samp', 'nperiods')
108
109
110
        self.assertEquals(expectedNPeriods, nPeriods, "Did not fetch the number of periods from ws")
        
    def test_groupGet_multi_value_log(self):
111

112
113
114
115
        # Expected start theta, taken from the last value of the time series log.
        expectedStartTheta = 0.4903 
        
        # Test with group workspace as input
116
        stheta = quick.groupGet(self.__wsName, 'samp', 'stheta')
117
118
119
        self.assertEquals(expectedStartTheta, round(float(stheta), 4))
        
        # Test with single workspace as input
120
        stheta = quick.groupGet(mtd[self.__wsName][0].name(), 'samp', 'stheta')
121
        self.assertEquals(expectedStartTheta, round(float(stheta), 4))
122
        
123
124
125
    def test_groupGet_unknown_log_error_code(self):
        errorCode = 0
        # Test with group workspace as input
126
        self.assertEquals(errorCode, quick.groupGet(self.__wsName, 'samp','MADE-UP-LOG-NAME'))
127
128
        
        # Test with group workspace as input
129
        self.assertEquals(errorCode, quick.groupGet(mtd[self.__wsName][0].name(), 'samp','MADE-UP-LOG-NAME'))
130
        
131
132
133

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