Skip to content

Commit 77549a4

Browse files
committed
added EnggUtils test coverage for custom and cropped groups
1 parent 2cb3b22 commit 77549a4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

scripts/Engineering/test/test_EnggUtils.py

+55
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
_save_output_files,
1212
_load_run_and_convert_to_dSpacing,
1313
process_vanadium,
14+
GROUP,
1415
)
1516

1617
enggutils_path = "Engineering.EnggUtils"
@@ -24,6 +25,20 @@ def setUp(self):
2425
self.calibration.get_group_suffix.return_value = "all_banks"
2526
self.calibration.get_foc_ws_suffix.return_value = "bank"
2627

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+
2742
# tests for code used in calibration tab of UI
2843

2944
@patch(enggutils_path + ".copy2")
@@ -103,6 +118,46 @@ def test_process_vanadium_foc_curves_exist(self, mock_ads, mock_path):
103118
self.assertEqual(ws_van_foc, "van_ws_foc")
104119
self.assertEqual(van_run, "123456")
105120

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+
106161
@patch(enggutils_path + "._smooth_vanadium")
107162
@patch(enggutils_path + "._focus_run_and_apply_roi_calibration")
108163
@patch(enggutils_path + "._load_run_and_convert_to_dSpacing")

0 commit comments

Comments
 (0)