Skip to content

Commit 1f9f142

Browse files
edit tests
1 parent 1344a7d commit 1f9f142

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

src/diffpy/utils/diffraction_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def on_xtype(self, xtype):
394394
elif xtype.lower() in DQUANTITIES:
395395
return self.on_d()
396396
else:
397-
warnings.warn(_xtype_wmsg(xtype))
397+
raise ValueError(_xtype_wmsg(xtype))
398398

399399
def dump(self, filepath, xtype=None):
400400
if xtype is None:

tests/test_diffraction_objects.py

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
import pytest
66
from freezegun import freeze_time
77

8-
from diffpy.utils.diffraction_objects import (
9-
ANGLEQUANTITIES,
10-
DQUANTITIES,
11-
QQUANTITIES,
12-
XQUANTITIES,
13-
DiffractionObject,
14-
)
8+
from diffpy.utils.diffraction_objects import XQUANTITIES, DiffractionObject
159

1610

1711
def compare_dicts(dict1, dict2):
@@ -208,38 +202,21 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected):
208202
assert dicts_equal(diffraction_object1.__dict__, diffraction_object2.__dict__) == expected
209203

210204

211-
params_on_xtype = [
212-
(
213-
[
214-
np.array([100, 200, 300, 400, 500, 600]), # intensity array
215-
np.array([0, 30, 60, 90, 120, 180]), # tth array
216-
np.array([1, 2, 3, 4, 5, 6]), # q array
217-
np.array([10, 20, 30, 40, 50, 60]), # d array
218-
],
219-
[
220-
np.array([[0, 30, 60, 90, 120, 180], [100, 200, 300, 400, 500, 600]]), # expected on_tth
221-
np.array([[1, 2, 3, 4, 5, 6], [100, 200, 300, 400, 500, 600]]), # expected on_q
222-
np.array([[10, 20, 30, 40, 50, 60], [100, 200, 300, 400, 500, 600]]), # expected on_d
223-
],
224-
)
225-
]
226-
227-
228-
@pytest.mark.parametrize("inputs, expected", params_on_xtype)
229-
def test_on_xtype(inputs, expected):
230-
test = DiffractionObject()
231-
test.on_tth = np.array([inputs[1], inputs[0]])
232-
test.on_q = np.array([inputs[2], inputs[0]])
233-
test.on_d = np.array([inputs[3], inputs[0]])
234-
for xtype_list, expected_value in zip([ANGLEQUANTITIES, QQUANTITIES, DQUANTITIES], expected):
235-
for xtype in xtype_list:
236-
assert np.allclose(test.on_xtype(xtype), expected_value)
205+
def test_on_xtype():
206+
test = DiffractionObject(wavelength=2 * np.pi, xarray=np.array([30, 60]), yarray=np.array([1, 2]), xtype="tth")
207+
assert np.allclose(test.on_xtype("tth"), [np.array([30, 60]), np.array([1, 2])])
208+
assert np.allclose(test.on_xtype("q"), [np.array([0.51763809, 1]), np.array([1, 2])])
209+
assert np.allclose(test.on_xtype("d"), [np.array([12.13818192, 6.28318531]), np.array([1, 2])])
237210

238211

239212
def test_on_xtype_bad():
240213
test = DiffractionObject()
241214
with pytest.raises(
242-
ValueError, match=re.escape(f"Unknown xtype: invalid. Allowed xtypes are {*XQUANTITIES, }.")
215+
ValueError,
216+
match=re.escape(
217+
f"WARNING: I don't know how to handle the xtype, 'invalid'. Please rerun specifying an "
218+
f"xtype from {*XQUANTITIES, }"
219+
),
243220
):
244221
test.on_xtype("invalid")
245222

0 commit comments

Comments
 (0)