Skip to content

Commit 25cb875

Browse files
committed
Catch warnings in zero to test_tth_to_d
1 parent b7ad810 commit 25cb875

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

tests/test_transforms.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,33 +163,38 @@ def test_d_to_q(d, expected_q):
163163

164164

165165
@pytest.mark.parametrize(
166-
"wavelength, tth, expected_d",
167-
[
168-
# UC0: User specified empty tth values (without wavelength)
169-
(None, np.array([]), np.array([])),
170-
# UC1: User specified empty tth values (with wavelength)
171-
(4 * np.pi, np.array([]), np.array([])),
172-
# UC2: User specified valid tth values between 0-180 degrees (without wavelength)
166+
"wavelength, tth, expected_d, divide_by_zero_warning_expected",
167+
[
168+
# Test conversion of q to d with valid values
169+
# Case 1: empty tth values, no, expect empty d values
170+
(None, np.array([]), np.array([]), False),
171+
# Case 2: empty tth values, wavelength provided, expect empty d values
172+
(4 * np.pi, np.array([]), np.array([]), False),
173+
# Case 3: User specified valid tth values between 0-180 degrees (without wavelength)
173174
(
174175
None,
175176
np.array([0, 30, 60, 90, 120, 180]),
176177
np.array([0, 1, 2, 3, 4, 5]),
178+
False
177179
),
178-
# UC3: User specified valid tth values between 0-180 degrees (with wavelength)
180+
# Case 4: User specified valid tth values between 0-180 degrees (with wavelength)
179181
(
180182
4 * np.pi,
181183
np.array([0, 30.0, 60.0, 90.0, 120.0, 180.0]),
182184
np.array([np.inf, 24.27636, 12.56637, 8.88577, 7.25520, 6.28319]),
185+
True
183186
),
184187
],
185188
)
186-
def test_tth_to_d(wavelength, tth, expected_d, wavelength_warning_msg):
189+
def test_tth_to_d(wavelength, tth, expected_d, divide_by_zero_warning_expected, wavelength_warning_msg):
187190
if wavelength is None:
188191
with pytest.warns(UserWarning, match=re.escape(wavelength_warning_msg)):
189192
actual_d = tth_to_d(tth, wavelength)
193+
elif divide_by_zero_warning_expected:
194+
with pytest.warns(RuntimeWarning, match="divide by zero encountered in divide"):
195+
actual_d = tth_to_d(tth, wavelength)
190196
else:
191197
actual_d = tth_to_d(tth, wavelength)
192-
193198
assert np.allclose(actual_d, expected_d)
194199

195200

0 commit comments

Comments
 (0)