2020 LoadInstrument ,
2121 mtd ,
2222)
23+ from snapred .backend .recipe .algorithm .MantidSnapper import MantidSnapper
2324from util .Config_helpers import Config_override
2425from util .dao import DAOFactory
2526from util .helpers import (
@@ -249,6 +250,7 @@ def setUp(self):
249250 self .instance .dataExportService .dataService = self .localDataService
250251 self .instance .dataFactoryService .lookupService = self .localDataService
251252 self .instance .groceryService .dataService = self .localDataService
253+ self .instance .groceryService .mantidSnapper = MantidSnapper (None , __name__ )
252254 self .outputNameFormat = "{}_calibration_reduction_result"
253255 # Mock the _calculatePixelGroupingParameters method to return a predefined value
254256 self .instance ._calculatePixelGroupingParameters = lambda calib , focus_def , lite_mode , nBins : { # noqa: ARG005
@@ -766,7 +768,6 @@ def test_fetchDiffractionCalibrationGroceries(self):
766768 }
767769 )
768770 self .instance .groceryService .fetchCompatiblePixelMask = mock .Mock (side_effect = lambda n , _ , __ : n )
769- self .instance .groceryService .mantidSnapper .mtd .doesExist = mock .Mock (side_effect = lambda _ : True )
770771 self .instance .groceryService .mantidSnapper .BinaryOperateMasks = mock .Mock ()
771772 self .instance .validateRequest = mock .Mock ()
772773
@@ -778,7 +779,8 @@ def test_fetchDiffractionCalibrationGroceries(self):
778779 startingTableVersion = 0 ,
779780 pixelMasks = [],
780781 )
781- with mock .patch ("snapred.meta.Time.timestamp" , return_value = timestamp ):
782+ with (mock .patch ("snapred.meta.Time.timestamp" , return_value = timestamp ),
783+ mock .patch .object (self .instance .groceryService .mantidSnapper .mtd , "doesExist" , mock .Mock (side_effect = lambda _ : True ))):
782784 result = self .instance .fetchDiffractionCalibrationGroceries (request )
783785
784786 assert self .instance .groceryClerk .buildDict .call_count == 1
@@ -1104,7 +1106,6 @@ def test_diffractionCalibration_with_bad_masking(
11041106 self .instance .groceryService .fetchGroceryDict = mock .Mock (return_value = {"maskWorkspace" : self .sampleMaskWS })
11051107 self .instance .groceryService .getWorkspaceForName = mock .Mock (side_effect = [False , mtd [self .sampleMaskWS ]])
11061108 self .instance .groceryService .fetchCompatiblePixelMask = mock .Mock (side_effect = lambda n , _ , __ : n )
1107- self .instance .groceryService .mantidSnapper .mtd .doesExist = mock .Mock (side_effect = lambda _ : True )
11081109 self .instance .groceryService .mantidSnapper .BinaryOperateMasks = mock .Mock ()
11091110 # Call the method with the provided parameters
11101111 request = DiffractionCalibrationRequest (
@@ -1115,7 +1116,8 @@ def test_diffractionCalibration_with_bad_masking(
11151116 focusGroup = FocusGroup (name = "all" , definition = "path/to/all" ),
11161117 continueFlags = ContinueWarning .Type .UNSET ,
11171118 )
1118- with pytest .raises (Exception , match = r".*pixels failed calibration*" ):
1119+ with (pytest .raises (Exception , match = r".*pixels failed calibration*" ),
1120+ mock .patch .object (self .instance .groceryService .mantidSnapper .mtd , "doesExist" , mock .Mock (side_effect = lambda _ : True ))):
11191121 self .instance .diffractionCalibration (request )
11201122 GroupRx ().cook .assert_not_called ()
11211123
0 commit comments