11
11
_save_output_files ,
12
12
_load_run_and_convert_to_dSpacing ,
13
13
process_vanadium ,
14
+ GROUP ,
14
15
)
15
16
16
17
enggutils_path = "Engineering.EnggUtils"
@@ -24,6 +25,20 @@ def setUp(self):
24
25
self .calibration .get_group_suffix .return_value = "all_banks"
25
26
self .calibration .get_foc_ws_suffix .return_value = "bank"
26
27
28
+ self .custom_calibration = create_autospec (CalibrationInfo (), instance = True )
29
+ self .custom_calibration .is_valid .return_value = True
30
+ self .custom_calibration .get_instrument .return_value = "ENGINX"
31
+ self .custom_calibration .get_group_suffix .return_value = "Custom_test"
32
+ self .custom_calibration .get_foc_ws_suffix .return_value = "Custom_test"
33
+ self .custom_calibration .group = GROUP .CUSTOM
34
+
35
+ self .cropped_calibration = create_autospec (CalibrationInfo (), instance = True )
36
+ self .cropped_calibration .is_valid .return_value = True
37
+ self .cropped_calibration .get_instrument .return_value = "ENGINX"
38
+ self .cropped_calibration .get_group_suffix .return_value = "Cropped"
39
+ self .cropped_calibration .get_foc_ws_suffix .return_value = "Cropped"
40
+ self .cropped_calibration .group = GROUP .CROPPED
41
+
27
42
# tests for code used in calibration tab of UI
28
43
29
44
@patch (enggutils_path + ".copy2" )
@@ -103,6 +118,46 @@ def test_process_vanadium_foc_curves_exist(self, mock_ads, mock_path):
103
118
self .assertEqual (ws_van_foc , "van_ws_foc" )
104
119
self .assertEqual (van_run , "123456" )
105
120
121
+ @patch (enggutils_path + "._smooth_vanadium" )
122
+ @patch (enggutils_path + "._focus_run_and_apply_roi_calibration" )
123
+ @patch (enggutils_path + "._load_run_and_convert_to_dSpacing" )
124
+ @patch (enggutils_path + ".path_handling.get_run_number_from_path" )
125
+ @patch (enggutils_path + ".ADS" )
126
+ def test_process_vanadium_foc_rerun_if_custom (self , mock_ads , mock_path , mock_load_run , mock_foc_run , mock_smooth_van ):
127
+ mock_path .return_value = "123456"
128
+ mock_ads .doesExist .side_effect = [True , True ]
129
+ mock_ads .retrieve .return_value = "van_ws_foc_old" # if we just retrieves the ws in the ADS, we would get this
130
+ mock_smooth_van .return_value = "van_ws_foc_new" # if we actually run a calibration we should get this
131
+
132
+ ws_van_foc , van_run = process_vanadium ("van_path" , self .custom_calibration , "full_calib" )
133
+
134
+ mock_ads .retrieve .assert_called_once_with ("123456" )
135
+ mock_load_run .assert_not_called ()
136
+ mock_foc_run .assert_called_once ()
137
+ mock_smooth_van .assert_called_once ()
138
+ self .assertEqual (ws_van_foc , "van_ws_foc_new" ) # we want this to be recalculated
139
+ self .assertEqual (van_run , "123456" )
140
+
141
+ @patch (enggutils_path + "._smooth_vanadium" )
142
+ @patch (enggutils_path + "._focus_run_and_apply_roi_calibration" )
143
+ @patch (enggutils_path + "._load_run_and_convert_to_dSpacing" )
144
+ @patch (enggutils_path + ".path_handling.get_run_number_from_path" )
145
+ @patch (enggutils_path + ".ADS" )
146
+ def test_process_vanadium_foc_rerun_if_cropped (self , mock_ads , mock_path , mock_load_run , mock_foc_run , mock_smooth_van ):
147
+ mock_path .return_value = "123456"
148
+ mock_ads .doesExist .side_effect = [True , True ]
149
+ mock_ads .retrieve .return_value = "van_ws_foc_old" # if we just retrieves the ws in the ADS, we would get this
150
+ mock_smooth_van .return_value = "van_ws_foc_new" # if we actually run a calibration we should get this
151
+
152
+ ws_van_foc , van_run = process_vanadium ("van_path" , self .cropped_calibration , "full_calib" )
153
+
154
+ mock_ads .retrieve .assert_called_once_with ("123456" )
155
+ mock_load_run .assert_not_called ()
156
+ mock_foc_run .assert_called_once ()
157
+ mock_smooth_van .assert_called_once ()
158
+ self .assertEqual (ws_van_foc , "van_ws_foc_new" ) # we want this to be recalculated
159
+ self .assertEqual (van_run , "123456" )
160
+
106
161
@patch (enggutils_path + "._smooth_vanadium" )
107
162
@patch (enggutils_path + "._focus_run_and_apply_roi_calibration" )
108
163
@patch (enggutils_path + "._load_run_and_convert_to_dSpacing" )
0 commit comments