@@ -63,9 +63,8 @@ def setUp(self):
6363 "p_final" : two_d_output ,
6464 "p_max_all" : three_d_output ,
6565 }
66- self .mock_dict = MagicMock ()
67- self .mock_dict .__getitem__ .side_effect = self .mock_dict_values .__getitem__
68- self .mock_dict .__contains__ .side_effect = self .mock_dict_values .__contains__
66+ # Use a real dictionary instead of a mock
67+ self .mock_dict = self .mock_dict_values .copy ()
6968
7069 def tearDown (self ):
7170 # Stop patchers
@@ -180,45 +179,68 @@ def test_sensor_data_cropping_with_pml_outside(self):
180179 self .mock_proc .returncode = 0
181180 self .simulation_options .pml_inside = False
182181
182+ # Create a mock that tracks calls before being replaced
183+ original_two_d_output = MagicMock ()
184+ original_two_d_output .ndim = 2
185+ original_three_d_output = MagicMock ()
186+ original_three_d_output .ndim = 3
187+
188+ # Update the mock dict to use these tracking mocks
189+ self .mock_dict ["p_final" ] = original_two_d_output
190+ self .mock_dict ["p_max_all" ] = original_three_d_output
191+
183192 # Instantiate the Executor
184193 executor = Executor (self .execution_options , self .simulation_options )
185194
186195 # Mock the parse_executable_output method
187196 with patch .object (executor , "parse_executable_output" , return_value = self .mock_dict ):
188197 sensor_data = executor .run_simulation ("input.h5" , "output.h5" , ["options" ])
189198
190- # because pml is outside, the output should be cropped
191- two_d_output = sensor_data ["p_final" ]
192- two_d_output .__getitem__ .assert_called_once_with ((slice (2 , 18 ), slice (2 , 18 )))
193- three_d_output = sensor_data ["p_max_all" ]
194- three_d_output .__getitem__ .assert_called_once_with ((slice (2 , 18 ), slice (2 , 18 ), slice (2 , 18 )))
199+ # Verify that sensor_data is a SimulationResult
200+ self .assertIsInstance (sensor_data , SimulationResult )
201+
202+ # Verify that the original mock objects were called for cropping
203+ original_two_d_output .__getitem__ .assert_called_once_with ((slice (2 , 18 ), slice (2 , 18 )))
204+ original_three_d_output .__getitem__ .assert_called_once_with ((slice (2 , 18 ), slice (2 , 18 ), slice (2 , 18 )))
195205
196- # check that the other fields are changed
197- for field in self .mock_dict_values .keys ():
206+ # check that the other fields are unchanged
207+ for field in self .mock_dict .keys ():
198208 if field not in ["p_final" , "p_max_all" ]:
199- self .assertEqual (sensor_data [field ], self .mock_dict_values [field ])
209+ self .assertEqual (sensor_data [field ], self .mock_dict [field ])
200210
201211 def test_sensor_data_cropping_with_pml_inside (self ):
202212 """If pml is inside, no field should be cropped."""
203213 self .mock_proc .returncode = 0
204214
215+ # Create a mock that tracks calls before being replaced
216+ original_two_d_output = MagicMock ()
217+ original_two_d_output .ndim = 2
218+ original_three_d_output = MagicMock ()
219+ original_three_d_output .ndim = 3
220+
221+ # Update the mock dict to use these tracking mocks
222+ self .mock_dict ["p_final" ] = original_two_d_output
223+ self .mock_dict ["p_max_all" ] = original_three_d_output
224+
205225 # Instantiate the Executor
206226 executor = Executor (self .execution_options , self .simulation_options )
207227
208228 # Mock the parse_executable_output method
209229 with patch .object (executor , "parse_executable_output" , return_value = self .mock_dict ):
210230 sensor_data = executor .run_simulation ("input.h5" , "output.h5" , ["options" ])
211231
232+ # Verify that sensor_data is a SimulationResult
233+ self .assertIsInstance (sensor_data , SimulationResult )
234+
212235 # because pml is inside, the output should not be cropped
213- two_d_output = sensor_data ["p_final" ]
214- two_d_output .__getitem__ .assert_not_called ()
215- three_d_output = sensor_data ["p_max_all" ]
216- three_d_output .__getitem__ .assert_not_called ()
236+ # The mock objects should not have been called for cropping
237+ original_two_d_output .__getitem__ .assert_not_called ()
238+ original_three_d_output .__getitem__ .assert_not_called ()
217239
218- # check that the other fields are changed
219- for field in self .mock_dict_values .keys ():
240+ # check that the other fields are unchanged
241+ for field in self .mock_dict .keys ():
220242 if field not in ["p_final" , "p_max_all" ]:
221- self .assertEqual (sensor_data [field ], self .mock_dict_values [field ])
243+ self .assertEqual (sensor_data [field ], self .mock_dict [field ])
222244
223245 def test_executor_file_not_found_on_non_darwin (self ):
224246 # Configure the mock path object
0 commit comments