Skip to content

Commit de82a77

Browse files
committed
Clean up tests for catching error
1 parent 889fac3 commit de82a77

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/test_diffraction_objects.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,28 @@ def test_dump(tmp_path, mocker):
241241
test.name = "test"
242242
test.scat_quantity = "x-ray"
243243

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
245245
with warnings.catch_warnings(record=True) as captured_warnings:
246+
# Configure the warnings system to capture all warnings
246247
warnings.simplefilter("always")
248+
249+
# Perform the method call that is expected to trigger the RuntimeWarning due to the specified wavelength
247250
test.insert_scattering_quantity(
248251
x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}}
249252
)
250253

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
252255
assert any(
253256
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
257263
mocker.patch("importlib.metadata.version", return_value="3.3.0")
258264

265+
259266
with freeze_time("2012-01-14"):
260267
test.dump(file, "q")
261268

0 commit comments

Comments
 (0)