Skip to content

Commit c119b1f

Browse files
committed
Add tests for getter and setter
1 parent ee190b9 commit c119b1f

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

tests/test_diffraction_objects.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,15 @@ def test_on_xtype():
211211
assert np.allclose(test.on_xtype("d"), [np.array([12.13818, 6.28319]), np.array([1, 2])])
212212

213213

214-
def test_on_xtype_bad():
215-
test = DiffractionObject()
214+
def test_init_invalid_xtype():
216215
with pytest.raises(
217216
ValueError,
218217
match=re.escape(
219-
f"I don't know how to handle the xtype, 'invalid'. Please rerun specifying an "
218+
f"I don't know how to handle the xtype, 'invalid_type'. Please rerun specifying an "
220219
f"xtype from {*XQUANTITIES, }"
221220
),
222221
):
223-
test.on_xtype("invalid")
222+
DiffractionObject(xtype="invalid_type")
224223

225224

226225
params_index = [
@@ -287,7 +286,7 @@ def test_dump(tmp_path, mocker):
287286
{
288287
"_all_arrays": np.empty(shape=(0, 4)), # instantiate empty
289288
"metadata": {},
290-
"input_xtype": "",
289+
"_xtype": "",
291290
"name": "",
292291
"scat_quantity": None,
293292
"qmin": np.float64(np.inf),
@@ -304,7 +303,7 @@ def test_dump(tmp_path, mocker):
304303
{
305304
"_all_arrays": np.empty(shape=(0, 4)),
306305
"metadata": {"thing": "1", "another": "2"},
307-
"input_xtype": "",
306+
"_xtype": "",
308307
"name": "test",
309308
"scat_quantity": "x-ray",
310309
"qmin": np.float64(np.inf),
@@ -332,7 +331,7 @@ def test_dump(tmp_path, mocker):
332331
]
333332
),
334333
"metadata": {},
335-
"input_xtype": "tth",
334+
"_xtype": "tth",
336335
"name": "",
337336
"scat_quantity": None,
338337
"qmin": np.float64(0.0),
@@ -361,7 +360,7 @@ def test_dump(tmp_path, mocker):
361360
]
362361
),
363362
"metadata": {},
364-
"input_xtype": "d",
363+
"_xtype": "d",
365364
"name": "",
366365
"scat_quantity": "x-ray",
367366
"qmin": np.float64(0.0),
@@ -407,6 +406,23 @@ def test_all_array_setter():
407406
with pytest.raises(
408407
AttributeError,
409408
match="Direct modification of attribute 'all_arrays' is not allowed."
410-
"Please use 'insert_scattering_quantity' to modify `all_arrays`.",
409+
"Please use 'insert_scattering_quantity' to modify 'all_arrays'.",
411410
):
412411
actual_do.all_arrays = np.empty((4, 4))
412+
413+
414+
def test_xtype_getter():
415+
do = DiffractionObject(xtype="tth")
416+
assert do.xtype == "tth"
417+
418+
419+
def test_xtype_setter():
420+
do = DiffractionObject(xtype="tth")
421+
422+
# Attempt to directly modify the property
423+
with pytest.raises(
424+
AttributeError,
425+
match="Direct modification of attribute 'xtype' is not allowed."
426+
"Please use 'insert_scattering_quantity' to modify 'xtype'.",
427+
):
428+
do.xtype = "q"

0 commit comments

Comments
 (0)