|
5 | 5 | import pytest |
6 | 6 | from freezegun import freeze_time |
7 | 7 |
|
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 |
15 | 9 |
|
16 | 10 |
|
17 | 11 | def compare_dicts(dict1, dict2): |
@@ -208,38 +202,21 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected): |
208 | 202 | assert dicts_equal(diffraction_object1.__dict__, diffraction_object2.__dict__) == expected |
209 | 203 |
|
210 | 204 |
|
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])]) |
237 | 210 |
|
238 | 211 |
|
239 | 212 | def test_on_xtype_bad(): |
240 | 213 | test = DiffractionObject() |
241 | 214 | 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 | + ), |
243 | 220 | ): |
244 | 221 | test.on_xtype("invalid") |
245 | 222 |
|
|
0 commit comments