ReflectometryQuickAuxiliaryTest.py 5.39 KB
Newer Older
1
import unittest
2
import numpy
3
4
5
6
7
from mantid.simpleapi import *
from isis_reflgui import quick

class ReflectometryQuickAuxiliaryTest(unittest.TestCase):
    
8
9
10
11
12
13
14
15
16
17
18
    __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])
        
19
20
    
    def test_cleanup(self):
21
        numObjectsOriginal = len(mtd.getObjectNames())
22
23
        todump =CreateSingleValuedWorkspace(OutputWorkspace='_toremove', DataValue=1, ErrorValue=1)
        tokeep =CreateSingleValuedWorkspace(OutputWorkspace='tokeep', DataValue=1, ErrorValue=1)
24
        self.assertEqual(numObjectsOriginal+2, len(mtd.getObjectNames()))  
25
26
27
        # Should remove workspaces starting with _
        quick.cleanup()
        cleaned_object_names = mtd.getObjectNames()
28
        self.assertEqual(numObjectsOriginal+1, len(cleaned_object_names))
29
30
        self.assertEqual(True, ('tokeep' in cleaned_object_names))
        
31
32
        DeleteWorkspace(tokeep)
        
33
34
35
36
37
38
    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)
39
        DeleteWorkspace(outWS)
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
        
    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()
66
67
68
69
70
71
72
73
74
75
            DeleteWorkspace(a[0])
            DeleteWorkspace(b[0])
            DeleteWorkspace(c)
            DeleteWorkspace(outWS)
        
    def test_groupGet_instrument(self):
        
        expectedInstrument = "POLREF"
        
        # Test with group workspace as input
76
        instrument = quick.groupGet(self.__wsName, 'inst')
77
78
79
        self.assertEquals(expectedInstrument, instrument.getName(), "Did not fetch the instrument from ws group")
        
        # Test with single workspace as input
80
        instrument = quick.groupGet(mtd[self.__wsName][0].name(), 'inst')
81
82
83
84
        self.assertEquals(expectedInstrument, instrument.getName(), "Did not fetch the instrument from ws")
        
    
    def test_groupGet_histogram_count(self):
85
        expectedNHistograms = mtd[self.__wsName][0].getNumberHistograms()
86
87
        
        # Test with group workspace as input
88
        nHistograms = quick.groupGet(self.__wsName, 'wksp')
89
90
91
        self.assertEquals(expectedNHistograms, nHistograms, "Did not fetch the n histograms from ws group")
        
        # Test with single workspace as input
92
        nHistograms = quick.groupGet(mtd[self.__wsName][0].name(), 'wksp')
93
94
95
96
97
98
99
100
        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
101
        nPeriods = quick.groupGet(self.__wsName, 'samp', 'nperiods')
102
103
104
        self.assertEquals(expectedNPeriods, nPeriods, "Did not fetch the number of periods from ws group")
        
        # Test with single workspace as input
105
        nPeriods = quick.groupGet(mtd[self.__wsName][0].name(), 'samp', 'nperiods')
106
107
108
        self.assertEquals(expectedNPeriods, nPeriods, "Did not fetch the number of periods from ws")
        
    def test_groupGet_multi_value_log(self):
109

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

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