@@ -241,21 +241,28 @@ def test_dump(tmp_path, mocker):
241
241
test .name = "test"
242
242
test .scat_quantity = "x-ray"
243
243
244
- # Capture warnings due to invalid arcsin input value due to the wavelenght being 1.54
244
+ # Setup the testing environment to capture warnings triggered by an invalid arcsin input
245
245
with warnings .catch_warnings (record = True ) as captured_warnings :
246
+ # Configure the warnings system to capture all warnings
246
247
warnings .simplefilter ("always" )
248
+
249
+ # Perform the method call that is expected to trigger the RuntimeWarning due to the specified wavelength
247
250
test .insert_scattering_quantity (
248
251
x , y , "q" , metadata = {"thing1" : 1 , "thing2" : "thing2" , "package_info" : {"package2" : "3.4.5" }}
249
252
)
250
253
251
- # Assert that a RuntimeWarning was raised
254
+ # Verify that at least one RuntimeWarning is raised due to the arcsin domain error from wavelength 1.54
252
255
assert any (
253
256
isinstance (w .message , RuntimeWarning ) for w in captured_warnings
254
- ), "Expected a RuntimeWarning due to invalid arcsin input value from the wavelenght set to 1.54"
255
- # Expect only one warning message produced
256
- assert len (captured_warnings ) == 1
257
+ ), "Expected a RuntimeWarning due to invalid arcsin input value from the wavelength set to 1.54"
258
+
259
+ # Ensure that exactly one warning was captured to confirm that no additional unexpected warnings are raised
260
+ assert len (captured_warnings ) == 1 , "Expected exactly one warning to be captured"
261
+
262
+ # Patch the version lookup to control the external dependency in the test environment
257
263
mocker .patch ("importlib.metadata.version" , return_value = "3.3.0" )
258
264
265
+
259
266
with freeze_time ("2012-01-14" ):
260
267
test .dump (file , "q" )
261
268
0 commit comments