forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SANSIsisInstrumentTest.py
93 lines (73 loc) · 3.08 KB
/
SANSIsisInstrumentTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
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
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import unittest
import isis_instrument as instruments
from mantid.simpleapi import *
class SANSIsisInstrumentTest(unittest.TestCase):
def test_add_TOFs_for_ROI_is_correct(self):
# Arrange
start = 125
end = 10000
inst = instruments.LOQ()
inst.set_TOFs_for_ROI(start, end)
# Act
start_Tof, end_Tof = inst.get_TOFs_for_ROI()
# Assert
self.assertEqual(start, start_Tof)
self.assertEqual(end, end_Tof)
def test_Tofs_for_ROI_are_reset_to_None(self):
# Arrange
start = 125
end = 10000
inst = instruments.LOQ()
inst.set_TOFs_for_ROI(start, end)
inst.reset_TOFs_for_ROI()
# Act
start_Tof, end_Tof = inst.get_TOFs_for_ROI()
# Assert
self.assertEqual(None, start_Tof)
self.assertEqual(None, end_Tof)
class TestParameterMapModifications(unittest.TestCase):
def create_sample_workspace(self, ws_name, types, values, names):
ws = CreateSampleWorkspace(OutputWorkspace=ws_name)
length = len(types)
if any(len(element) != length for element in [types, values, names]):
return
for i in range(0, length):
SetInstrumentParameter(ws, ParameterName=names[i],
ParameterType=types[i],
Value=values[i])
def test_that_calibration_workspace_has_absent_entries_copied_over(self):
# Arrange
ws_name1 = "ws1"
types1 = ["Number", "String", "Number"]
values1 = ["100.4", "test", "200"]
names1 = ["val1", "val2", "val3"]
self.create_sample_workspace(ws_name1, types1, values1, names1)
ws_name2 = "ws2"
types2 = ["Number", "String", "Number"]
values2 = ["2.4", "test3", "3"]
names2 = ["val1", "val2", "val4"]
self.create_sample_workspace(ws_name2, types2, values2, names2)
inst = instruments.SANS2D()
# Act
inst._add_parmeters_absent_in_calibration(ws_name1, ws_name2)
# Assert
ws2 = mtd[ws_name2]
self.assertTrue(ws2.getInstrument().hasParameter("val1"))
self.assertTrue(ws2.getInstrument().hasParameter("val2"))
self.assertTrue(ws2.getInstrument().hasParameter("val3"))
self.assertTrue(ws2.getInstrument().hasParameter("val4"))
self.assertEqual(len(ws2.getInstrument().getNumberParameter("val1")), 1)
self.assertEqual(ws2.getInstrument().getNumberParameter("val1")[0], 2.4)
self.assertEqual(len(ws2.getInstrument().getIntParameter("val3")), 1)
self.assertEqual(ws2.getInstrument().getIntParameter("val3")[0], 200)
# Clean up
DeleteWorkspace(ws_name1)
DeleteWorkspace(ws_name2)
if __name__ == "__main__":
unittest.main()