-
Notifications
You must be signed in to change notification settings - Fork 21
Add gettable id
property to DiffractionObject
#216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b97db39
5d87cdc
cd53586
6169620
1916d97
0dd95e8
4bd441f
3a52b2f
6e51eb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
**Added:** | ||
|
||
* Gettable `id` property to `DiffractionObject` | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import re | ||
import uuid | ||
from pathlib import Path | ||
from uuid import UUID | ||
|
||
import numpy as np | ||
import pytest | ||
|
@@ -335,8 +337,8 @@ def test_dump(tmp_path, mocker): | |
|
||
@pytest.mark.parametrize("inputs, expected", tc_params) | ||
def test_constructor(inputs, expected): | ||
actual_do = DiffractionObject(**inputs) | ||
diff = DeepDiff(actual_do.__dict__, expected, ignore_order=True, significant_digits=13) | ||
actual = DiffractionObject(**inputs).__dict__ | ||
diff = DeepDiff(actual, expected, ignore_order=True, significant_digits=13, exclude_paths="root['_id']") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for testing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is that ok? not sure if there is a better way for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the past I have mocked that attribute. This here seems less work. If we have tests that test the id setting and getting, we can safely ignore it in other tests that are testing other things, such as this one, think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted - yes is setter/getter test funcs provided below. |
||
assert diff == {} | ||
|
||
|
||
|
@@ -369,6 +371,29 @@ def test_all_array_setter(): | |
actual_do.all_arrays = np.empty((4, 4)) | ||
|
||
|
||
def test_id_getter(): | ||
do = DiffractionObject() | ||
assert hasattr(do, "id") | ||
assert isinstance(do.id, UUID) | ||
assert len(str(do.id)) == 36 | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_id_getter_with_mock(mocker): | ||
mocker.patch.object(DiffractionObject, "id", new_callable=lambda: UUID("d67b19c6-3016-439f-81f7-cf20a04bee87")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Hence we use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, nicely done. I didn't know about that. |
||
do = DiffractionObject() | ||
assert do.id == UUID("d67b19c6-3016-439f-81f7-cf20a04bee87") | ||
|
||
|
||
def test_id_setter_error(): | ||
do = DiffractionObject() | ||
|
||
with pytest.raises( | ||
AttributeError, | ||
match="Direct modification of attribute 'id' is not allowed. Please use 'input_data' to modify 'id'.", | ||
): | ||
do.id = uuid.uuid4() | ||
|
||
|
||
def test_xarray_yarray_length_mismatch(): | ||
with pytest.raises( | ||
ValueError, | ||
|
@@ -384,7 +409,7 @@ def test_input_xtype_getter(): | |
assert do.input_xtype == "tth" | ||
|
||
|
||
def test_input_xtype_setter(): | ||
def test_input_xtype_setter_error(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just enhancing the function name for clarify |
||
do = DiffractionObject(xtype="tth") | ||
|
||
# Attempt to directly modify the property | ||
|
Uh oh!
There was an error while loading. Please reload this page.