11import re
2+ import uuid
23from pathlib import Path
4+ from uuid import UUID
35
46import numpy as np
57import pytest
@@ -335,8 +337,8 @@ def test_dump(tmp_path, mocker):
335337
336338@pytest .mark .parametrize ("inputs, expected" , tc_params )
337339def 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
@@ -369,6 +371,29 @@ def test_all_array_setter():
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_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+
372397def test_xarray_yarray_length_mismatch ():
373398 with pytest .raises (
374399 ValueError ,
@@ -384,7 +409,7 @@ def test_input_xtype_getter():
384409 assert do .input_xtype == "tth"
385410
386411
387- def test_input_xtype_setter ():
412+ def test_input_xtype_setter_error ():
388413 do = DiffractionObject (xtype = "tth" )
389414
390415 # Attempt to directly modify the property
0 commit comments