ReflectometryQuickAuxiliaryTest.py 5.63 KB
Newer Older
1
import unittest
2
import numpy
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from MantidFramework import mtd
mtd.initialise()
from mantid.simpleapi import *
from isis_reflgui import quick

class ReflectometryQuickAuxiliaryTest(unittest.TestCase):
    
    
    def test_cleanup(self):
        todump =CreateSingleValuedWorkspace(OutputWorkspace='_toremove', DataValue=1, ErrorValue=1)
        tokeep =CreateSingleValuedWorkspace(OutputWorkspace='tokeep', DataValue=1, ErrorValue=1)
        self.assertEqual(2, len(mtd.getObjectNames()))  
        # Should remove workspaces starting with _
        quick.cleanup()
        cleaned_object_names = mtd.getObjectNames()
        self.assertEqual(1, len(cleaned_object_names))
        self.assertEqual(True, ('tokeep' in cleaned_object_names))
        
21
22
        DeleteWorkspace(tokeep)
        
23
24
25
26
27
28
    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)
29
        DeleteWorkspace(outWS)
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        
    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()
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
            DeleteWorkspace(a[0])
            DeleteWorkspace(b[0])
            DeleteWorkspace(c)
            DeleteWorkspace(outWS)
        
    def test_groupGet_instrument(self):
        wsName = "TestWorkspace"
        LoadISISNexus(Filename='POLREF00004699', OutputWorkspace=wsName)
        
        expectedInstrument = "POLREF"
        
        # Test with group workspace as input
        instrument = quick.groupGet(wsName, 'inst')
        self.assertEquals(expectedInstrument, instrument.getName(), "Did not fetch the instrument from ws group")
        
        # Test with single workspace as input
        instrument = quick.groupGet(mtd[wsName][0].name(), 'inst')
        self.assertEquals(expectedInstrument, instrument.getName(), "Did not fetch the instrument from ws")
        
        DeleteWorkspace(mtd[wsName])
    
    def test_groupGet_histogram_count(self):
        wsName = "TestWorkspace"
        LoadISISNexus(Filename='POLREF00004699', OutputWorkspace=wsName)
        expectedNHistograms = mtd[wsName][0].getNumberHistograms()
        
        # Test with group workspace as input
        nHistograms = quick.groupGet(wsName, 'wksp')
        self.assertEquals(expectedNHistograms, nHistograms, "Did not fetch the n histograms from ws group")
        
        # Test with single workspace as input
        nHistograms = quick.groupGet(mtd[wsName][0].name(), 'wksp')
        self.assertEquals(expectedNHistograms, nHistograms, "Did not fetch the n histograms from ws")
        
        DeleteWorkspace(mtd[wsName])
    
    def test_groupGet_log_single_value(self):
        wsName = "TestWorkspace"
        LoadISISNexus(Filename='POLREF00004699', OutputWorkspace=wsName)
        
        expectedNPeriods = 2
        
        # Test with group workspace as input
        nPeriods = quick.groupGet(wsName, 'samp', 'nperiods')
        self.assertEquals(expectedNPeriods, nPeriods, "Did not fetch the number of periods from ws group")
        
        # Test with single workspace as input
        nPeriods = quick.groupGet(mtd[wsName][0].name(), 'samp', 'nperiods')
        self.assertEquals(expectedNPeriods, nPeriods, "Did not fetch the number of periods from ws")
        
        DeleteWorkspace(mtd[wsName])
        
    def test_groupGet_multi_value_log(self):
        wsName = "TestWorkspace"
        LoadISISNexus(Filename='POLREF00004699', OutputWorkspace=wsName)
        
        # Expected start theta, taken from the last value of the time series log.
        expectedStartTheta = 0.4903 
        
        # Test with group workspace as input
        stheta = quick.groupGet(wsName, 'samp', 'stheta')
        self.assertEquals(expectedStartTheta, round(float(stheta), 4))
        
        # Test with single workspace as input
        stheta = quick.groupGet(mtd[wsName][0].name(), 'samp', 'stheta')
        self.assertEquals(expectedStartTheta, round(float(stheta), 4))
122
        
123
        DeleteWorkspace(mtd[wsName])
124
        
125
126
127
128
129
130
131
132
133
134
135
    def test_groupGet_unknown_log_error_code(self):
        wsName = "TestWorkspace"
        LoadISISNexus(Filename='POLREF00004699', OutputWorkspace=wsName)
        
        errorCode = 0
        # Test with group workspace as input
        self.assertEquals(errorCode, quick.groupGet(wsName, 'samp','MADE-UP-LOG-NAME'))
        
        # Test with group workspace as input
        self.assertEquals(errorCode, quick.groupGet(mtd[wsName][0].name(), 'samp','MADE-UP-LOG-NAME'))
        
136
137
138

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