@@ -225,12 +225,49 @@ class TestCalcEffectiveDetuning:
225225
226226 def test_calc_effective_detuning_empty_optics (self ):
227227 """Test with empty optics dictionary."""
228- result = calc_effective_detuning ({}, pd .Series (dtype = float ))
228+ result = calc_effective_detuning ({}, pd .Series (0 , index = [ Mock ( ip = None )], dtype = float ))
229229
230230 # Returns empty dict with no beams
231231 assert isinstance (result , dict )
232232 assert len (result ) == 0
233233
234+ @patch ("ir_amplitude_detuning.detuning.calculations.calculate_matrix_row" )
235+ def test_calc_effective_detuning_no_ips (self , mock_calculate_matrix_row ):
236+ """Test with correctors without IPs."""
237+ # Create mocks ---
238+ all_correctors = [
239+ Corrector (
240+ field = field ,
241+ length = 0.5 ,
242+ magnet = f"{ type_ } ip{ ip or 0 } { field } " ,
243+ circuit = f"k{ type_ } ip{ ip or 0 } { field } " ,
244+ ip = ip ,
245+ )
246+ for type_ , field , ip in (
247+ ("c1" , FieldComponent .b4 , None ),
248+ ("c2" , FieldComponent .b4 , None ),
249+ )
250+ ]
251+ values = pd .Series ([1 , 2 ], index = all_correctors , dtype = float )
252+
253+ mock_optics = {1 : Mock ()}
254+ def mocked_calulation (beam , optics , correctors , term ):
255+ assert correctors == all_correctors # no filtering as all ips are None, and both have same field
256+ return np .ones ([1 , len (correctors )])
257+
258+ mock_calculate_matrix_row .side_effect = mocked_calulation
259+ all_terms = list (FirstOrderTerm ) + list (SecondOrderTerm )
260+
261+ # Run ---
262+ result = calc_effective_detuning (mock_optics , values )
263+
264+ # Check results ---
265+ assert isinstance (result , dict )
266+ assert len (result ) == 1 # one beam
267+ assert len (result [1 ]) == 1 # one field, "one" ip (None)
268+ assert all (result [1 ].loc [:, all_terms ] == values .sum ()) # calculation returns [1, 1]
269+ assert mock_calculate_matrix_row .call_count == len (all_terms )
270+
234271 @patch ("ir_amplitude_detuning.detuning.calculations.calculate_matrix_row" )
235272 def test_calc_effective_detuning (self , mock_calculate_matrix_row ):
236273 """Test with single beam."""
0 commit comments