@@ -129,14 +129,32 @@ def test_file_transferred_to(
129129 ) == destination_dir / file .relative_to (visit_dir )
130130
131131
132+ @pytest .mark .parametrize (
133+ "test_params" ,
134+ ( # File type to test | Use environment? | Find source? | Find destination?
135+ ("drift_correction" , True , True , True ),
136+ ("drift_correction" , False , True , True ),
137+ ("drift_correction" , True , False , True ),
138+ ("drift_correction" , True , True , False ),
139+ ),
140+ )
132141def test_fib_autotem_context (
133142 mocker : MockerFixture ,
143+ test_params : tuple [str , bool , bool , bool ],
134144 tmp_path : Path ,
135145 visit_dir : Path ,
136146 fib_autotem_dc_images : list [Path ],
137147):
148+ # Unpack test params
149+ file_type , use_env , find_source , find_dst = test_params
150+
138151 # Mock the environment
139- mock_environment = MagicMock ()
152+ mock_environment = None
153+ if use_env :
154+ mock_environment = MagicMock ()
155+
156+ # Mock the logger to check if specific logs are triggered
157+ mock_logger = mocker .patch ("murfey.client.contexts.fib.logger" )
140158
141159 # Create a list of destinations
142160 destination_dir = tmp_path / "fib" / "data" / "current_year" / "visit"
@@ -145,11 +163,9 @@ def test_fib_autotem_context(
145163 ]
146164
147165 # Mock the functions used in 'post_transfer'
148- mock_get_source = mocker .patch (
149- "murfey.client.contexts.fib._get_source" , return_value = tmp_path
150- )
166+ mock_get_source = mocker .patch ("murfey.client.contexts.fib._get_source" )
151167 mock_file_transferred_to = mocker .patch (
152- "murfey.client.contexts.fib._file_transferred_to" , side_effect = destination_files
168+ "murfey.client.contexts.fib._file_transferred_to"
153169 )
154170 mock_capture_post = mocker .patch ("murfey.client.contexts.fib.capture_post" )
155171
@@ -162,18 +178,38 @@ def test_fib_autotem_context(
162178 token = "" ,
163179 )
164180
165- # Parse images one-by-one and check that expected calls were made
166- for file in fib_autotem_dc_images :
167- context .post_transfer (file , environment = mock_environment )
168- mock_get_source .assert_called_with (file , mock_environment )
169- mock_file_transferred_to .assert_called_with (
170- environment = mock_environment ,
171- source = basepath ,
172- file_path = file ,
173- rsync_basepath = Path ("" ),
174- )
175- assert mock_capture_post .call_count == len (fib_autotem_dc_images )
176- assert len (context ._drift_correction_images ) == num_lamellae
181+ match file_type :
182+ case "drift_correction" :
183+ # Add case-specific return values and side-effects to the mocks
184+ mock_get_source .return_value = tmp_path if find_source else None
185+ if find_dst :
186+ mock_file_transferred_to .side_effect = destination_files
187+ else :
188+ mock_file_transferred_to .return_value = None
189+
190+ # Parse images one-by-one and check that expected calls were made
191+ for file in fib_autotem_dc_images :
192+ context .post_transfer (file , environment = mock_environment )
193+ if not use_env :
194+ mock_logger .warning .assert_called_with ("No environment passed in" )
195+ elif not find_source :
196+ mock_logger .warning .assert_called_with (
197+ f"No source found for file { file } "
198+ )
199+ elif not find_dst :
200+ mock_logger .warning .assert_called_with (
201+ f"File { file .name !r} not found on storage system"
202+ )
203+ else :
204+ mock_get_source .assert_called_with (file , mock_environment )
205+ mock_file_transferred_to .assert_called_with (
206+ environment = mock_environment ,
207+ source = basepath ,
208+ file_path = file ,
209+ rsync_basepath = Path ("" ),
210+ )
211+ assert mock_capture_post .call_count == len (fib_autotem_dc_images )
212+ assert len (context ._drift_correction_images ) == num_lamellae
177213
178214
179215def test_fib_maps_context (
0 commit comments