Skip to content

Commit 4bd441f

Browse files
committed
Add mocker for testing id property
1 parent 0dd95e8 commit 4bd441f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/test_diffraction_objects.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,18 @@ def test_id_getter():
378378
assert len(str(do.id)) == 36
379379

380380

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+
381387
def test_id_setter_error():
382388
do = DiffractionObject()
383-
# Attempt to directly modify the property
389+
384390
with pytest.raises(
385391
AttributeError,
386-
match="Direct modification of attribute 'id' is not allowed. Please use 'input_data' to modify 'id'.",
392+
match="Direct modification of attribute 'id' is not allowed. " "Please use 'input_data' to modify 'id'.",
387393
):
388394
do.id = uuid.uuid4()
389395

0 commit comments

Comments
 (0)