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

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
33
34
35
36
37
        DeleteWorkspace(tokeep)
        
    def test_groupGet_instrument(self):
        
        expectedInstrument = "POLREF"
        
        # Test with group workspace as input
38
        instrument = quick.groupGet(self.__wsName, 'inst')
39
40
41
        self.assertEquals(expectedInstrument, instrument.getName(), "Did not fetch the instrument from ws group")
        
        # Test with single workspace as input
42
        instrument = quick.groupGet(mtd[self.__wsName][0].name(), 'inst')
43
44
45
46
        self.assertEquals(expectedInstrument, instrument.getName(), "Did not fetch the instrument from ws")
        
    
    def test_groupGet_histogram_count(self):
47
        expectedNHistograms = mtd[self.__wsName][0].getNumberHistograms()
48
49
        
        # Test with group workspace as input
50
        nHistograms = quick.groupGet(self.__wsName, 'wksp')
51
52
53
        self.assertEquals(expectedNHistograms, nHistograms, "Did not fetch the n histograms from ws group")
        
        # Test with single workspace as input
54
        nHistograms = quick.groupGet(mtd[self.__wsName][0].name(), 'wksp')
55
56
57
58
59
60
61
62
        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
63
        nPeriods = quick.groupGet(self.__wsName, 'samp', 'nperiods')
64
65
66
        self.assertEquals(expectedNPeriods, nPeriods, "Did not fetch the number of periods from ws group")
        
        # Test with single workspace as input
67
        nPeriods = quick.groupGet(mtd[self.__wsName][0].name(), 'samp', 'nperiods')
68
69
70
        self.assertEquals(expectedNPeriods, nPeriods, "Did not fetch the number of periods from ws")
        
    def test_groupGet_multi_value_log(self):
71

72
73
74
75
        # Expected start theta, taken from the last value of the time series log.
        expectedStartTheta = 0.4903 
        
        # Test with group workspace as input
76
        stheta = quick.groupGet(self.__wsName, 'samp', 'stheta')
77
78
79
        self.assertEquals(expectedStartTheta, round(float(stheta), 4))
        
        # Test with single workspace as input
80
        stheta = quick.groupGet(mtd[self.__wsName][0].name(), 'samp', 'stheta')
81
        self.assertEquals(expectedStartTheta, round(float(stheta), 4))
82
        
83
84
85
    def test_groupGet_unknown_log_error_code(self):
        errorCode = 0
        # Test with group workspace as input
86
        self.assertEquals(errorCode, quick.groupGet(self.__wsName, 'samp','MADE-UP-LOG-NAME'))
87
88
        
        # Test with group workspace as input
89
        self.assertEquals(errorCode, quick.groupGet(mtd[self.__wsName][0].name(), 'samp','MADE-UP-LOG-NAME'))
90
        
91
92

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