|
6 | 6 | from deepdiff import DeepDiff |
7 | 7 | from freezegun import freeze_time |
8 | 8 |
|
9 | | -from diffpy.utils.diffraction_objects import DiffractionObject |
10 | | -from diffpy.utils.transforms import wavelength_warning_emsg |
| 9 | +from diffpy.utils.diffraction_objects import XQUANTITIES, DiffractionObject |
11 | 10 |
|
12 | 11 |
|
13 | 12 | def compare_dicts(dict1, dict2): |
@@ -204,13 +203,24 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected): |
204 | 203 | assert dicts_equal(diffraction_object1.__dict__, diffraction_object2.__dict__) == expected |
205 | 204 |
|
206 | 205 |
|
207 | | -def _test_valid_diffraction_objects(actual_diffraction_object, function, expected_array): |
208 | | - if actual_diffraction_object.wavelength is None: |
209 | | - with pytest.warns(UserWarning) as warn_record: |
210 | | - getattr(actual_diffraction_object, function)() |
211 | | - assert str(warn_record[0].message) == wavelength_warning_emsg |
212 | | - actual_array = getattr(actual_diffraction_object, function)() |
213 | | - return np.allclose(actual_array, expected_array) |
| 206 | +def test_on_xtype(): |
| 207 | + test = DiffractionObject(wavelength=2 * np.pi, xarray=np.array([30, 60]), yarray=np.array([1, 2]), xtype="tth") |
| 208 | + assert np.allclose(test.on_xtype("tth"), [np.array([30, 60]), np.array([1, 2])]) |
| 209 | + assert np.allclose(test.on_xtype("2theta"), [np.array([30, 60]), np.array([1, 2])]) |
| 210 | + assert np.allclose(test.on_xtype("q"), [np.array([0.51764, 1]), np.array([1, 2])]) |
| 211 | + assert np.allclose(test.on_xtype("d"), [np.array([12.13818, 6.28319]), np.array([1, 2])]) |
| 212 | + |
| 213 | + |
| 214 | +def test_on_xtype_bad(): |
| 215 | + test = DiffractionObject() |
| 216 | + with pytest.raises( |
| 217 | + ValueError, |
| 218 | + match=re.escape( |
| 219 | + f"I don't know how to handle the xtype, 'invalid'. Please rerun specifying an " |
| 220 | + f"xtype from {*XQUANTITIES, }" |
| 221 | + ), |
| 222 | + ): |
| 223 | + test.on_xtype("invalid") |
214 | 224 |
|
215 | 225 |
|
216 | 226 | params_index = [ |
|
0 commit comments