Skip to content

Commit 5d87cdc

Browse files
committed
Modify tests functions to test gettable id property
1 parent b97db39 commit 5d87cdc

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

tests/test_diffraction_objects.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import re
2+
import uuid
23
from pathlib import Path
4+
from uuid import UUID
35

46
import numpy as np
57
import pytest
@@ -335,8 +337,8 @@ def test_dump(tmp_path, mocker):
335337

336338
@pytest.mark.parametrize("inputs, expected", tc_params)
337339
def test_constructor(inputs, expected):
338-
actual_do = DiffractionObject(**inputs)
339-
diff = DeepDiff(actual_do.__dict__, expected, ignore_order=True, significant_digits=13)
340+
actual = DiffractionObject(**inputs).__dict__
341+
diff = DeepDiff(actual, expected, ignore_order=True, significant_digits=13, exclude_paths="root['_id']")
340342
assert diff == {}
341343

342344

@@ -364,16 +366,33 @@ def test_all_array_setter():
364366
with pytest.raises(
365367
AttributeError,
366368
match="Direct modification of attribute 'all_arrays' is not allowed. "
367-
"Please use 'insert_scattering_quantity' to modify 'all_arrays'.",
369+
"Please use 'input_data' to modify 'all_arrays'.",
368370
):
369371
actual_do.all_arrays = np.empty((4, 4))
370372

371373

374+
def test_id_getter():
375+
do = DiffractionObject()
376+
assert hasattr(do, "id")
377+
assert isinstance(do.id, UUID)
378+
assert len(str(do.id)) == 36
379+
380+
381+
def test_id_setter():
382+
do = DiffractionObject()
383+
# Attempt to directly modify the property
384+
with pytest.raises(
385+
AttributeError,
386+
match="Direct modification of attribute 'id' is not allowed. Please use 'input_data' to modify 'id'.",
387+
):
388+
do.id = uuid.uuid4()
389+
390+
372391
def test_xarray_yarray_length_mismatch():
373392
with pytest.raises(
374393
ValueError,
375394
match="'xarray' and 'yarray' must have the same length. "
376-
"Please re-initialize 'DiffractionObject' or re-run the method 'insert_scattering_quantity' "
395+
"Please re-initialize 'DiffractionObject' or re-run the method 'input_data' "
377396
"with 'xarray' and 'yarray' of identical length",
378397
):
379398
DiffractionObject(xarray=np.array([1.0, 2.0]), yarray=np.array([0.0, 0.0, 0.0]))
@@ -391,7 +410,7 @@ def test_input_xtype_setter():
391410
with pytest.raises(
392411
AttributeError,
393412
match="Direct modification of attribute 'input_xtype' is not allowed. "
394-
"Please use 'insert_scattering_quantity' to modify 'input_xtype'.",
413+
"Please use 'input_data' to modify 'input_xtype'.",
395414
):
396415
do.input_xtype = "q"
397416

0 commit comments

Comments
 (0)