1
1
import re
2
+ import uuid
2
3
from pathlib import Path
4
+ from uuid import UUID
3
5
4
6
import numpy as np
5
7
import pytest
@@ -335,8 +337,8 @@ def test_dump(tmp_path, mocker):
335
337
336
338
@pytest .mark .parametrize ("inputs, expected" , tc_params )
337
339
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']" )
340
342
assert diff == {}
341
343
342
344
@@ -369,6 +371,29 @@ def test_all_array_setter():
369
371
actual_do .all_arrays = np .empty ((4 , 4 ))
370
372
371
373
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_getter_with_mock (mocker ):
382
+ mocker .patch .object (DiffractionObject , "id" , new_callable = lambda : UUID ("d67b19c6-3016-439f-81f7-cf20a04bee87" ))
383
+ do = DiffractionObject ()
384
+ assert do .id == UUID ("d67b19c6-3016-439f-81f7-cf20a04bee87" )
385
+
386
+
387
+ def test_id_setter_error ():
388
+ do = DiffractionObject ()
389
+
390
+ with pytest .raises (
391
+ AttributeError ,
392
+ match = "Direct modification of attribute 'id' is not allowed. Please use 'input_data' to modify 'id'." ,
393
+ ):
394
+ do .id = uuid .uuid4 ()
395
+
396
+
372
397
def test_xarray_yarray_length_mismatch ():
373
398
with pytest .raises (
374
399
ValueError ,
@@ -384,7 +409,7 @@ def test_input_xtype_getter():
384
409
assert do .input_xtype == "tth"
385
410
386
411
387
- def test_input_xtype_setter ():
412
+ def test_input_xtype_setter_error ():
388
413
do = DiffractionObject (xtype = "tth" )
389
414
390
415
# Attempt to directly modify the property
0 commit comments