Skip to content

Commit 781e358

Browse files
committed
Capture no wavelenght warning for test_q_to_tth
1 parent 84b402f commit 781e358

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

tests/test_transforms.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,30 @@
55

66
params_q_to_tth = [
77
# UC1: Empty q values, no wavelength, return empty arrays
8-
([None, np.empty((0))], np.empty((0))),
9-
# UC2: Empty q values, wavelength specified, return empty arrays
10-
([4 * np.pi, np.empty((0))], np.empty(0)),
8+
(None, np.empty((0)), np.empty((0))),
9+
# # UC2: Empty q values, wavelength specified, return empty arrays
10+
(4 * np.pi, np.empty((0)), np.empty(0)),
1111
# UC3: User specified valid q values, no wavelength, return empty arrays
1212
(
13-
[None, np.array([0, 0.2, 0.4, 0.6, 0.8, 1])],
13+
None,
14+
np.array([0, 0.2, 0.4, 0.6, 0.8, 1]),
1415
np.array([0, 1, 2, 3, 4, 5]),
1516
),
1617
# UC4: User specified valid q values (with wavelength)
1718
# expected tth values are 2*arcsin(q) in degrees
18-
([4 * np.pi, np.array([0, 1 / np.sqrt(2), 1.0])], np.array([0, 90.0, 180.0])),
19+
(4 * np.pi, np.array([0, 1 / np.sqrt(2), 1.0]), np.array([0, 90.0, 180.0])),
1920
]
2021

22+
@pytest.mark.parametrize("wavelength, q, expected_tth", params_q_to_tth)
23+
def test_q_to_tth(wavelength, q, expected_tth):
24+
25+
if wavelength is None:
26+
with pytest.warns(UserWarning, match="INFO: no wavelength has been specified"):
27+
actual_tth = q_to_tth(q, wavelength)
28+
else:
29+
actual_tth = q_to_tth(q, wavelength)
2130

22-
@pytest.mark.parametrize("inputs, expected", params_q_to_tth)
23-
def test_q_to_tth(inputs, expected):
24-
actual = q_to_tth(inputs[1], inputs[0])
25-
assert np.allclose(expected, actual)
31+
assert np.allclose(expected_tth, actual_tth)
2632

2733

2834
params_q_to_tth_bad = [

0 commit comments

Comments
 (0)