Skip to content

Commit 266ee9c

Browse files
add tests for error messages
1 parent e4307f6 commit 266ee9c

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/diffpy/labpdfproc/tests/test_functions.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import re
2+
13
import numpy as np
24
import pytest
35

4-
from diffpy.labpdfproc.functions import Gridded_circle, apply_corr, compute_cve
6+
from diffpy.labpdfproc.functions import CVE_METHODS, Gridded_circle, apply_corr, compute_cve
57
from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object
68

79
params1 = [
@@ -85,6 +87,30 @@ def test_compute_cve(mocker):
8587
assert actual_cve_do == expected_cve_do
8688

8789

90+
params_cve_bad = [
91+
(
92+
[7, "polynomial_interpolation"],
93+
[
94+
f"mu*D is out of the acceptable range (0.5 to 6) for polynomial interpolation. "
95+
f"Please rerun with a value within this range or specifying another method from {* CVE_METHODS, }."
96+
],
97+
),
98+
([1, "invalid_method"], [f"Unknown method: invalid_method. Allowed methods are {*CVE_METHODS, }."]),
99+
([7, "invalid_method"], [f"Unknown method: invalid_method. Allowed methods are {*CVE_METHODS, }."]),
100+
]
101+
102+
103+
@pytest.mark.parametrize("inputs, msg", params_cve_bad)
104+
def test_compute_cve_bad(mocker, inputs, msg):
105+
xarray, yarray = np.array([90, 90.1, 90.2]), np.array([2, 2, 2])
106+
expected_cve = np.array([0.5, 0.5, 0.5])
107+
mocker.patch("diffpy.labpdfproc.functions.TTH_GRID", xarray)
108+
mocker.patch("numpy.interp", return_value=expected_cve)
109+
input_pattern = _instantiate_test_do(xarray, yarray)
110+
with pytest.raises(ValueError, match=re.escape(msg[0])):
111+
compute_cve(input_pattern, mud=inputs[0], method=inputs[1])
112+
113+
88114
def test_apply_corr(mocker):
89115
xarray, yarray = np.array([90, 90.1, 90.2]), np.array([2, 2, 2])
90116
expected_cve = np.array([0.5, 0.5, 0.5])

0 commit comments

Comments
 (0)