-
Notifications
You must be signed in to change notification settings - Fork 21
Remove unused test util functions for comparing two dicts, use __eq__ to compare DiffractionObjects
#214
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
Remove unused test util functions for comparing two dicts, use __eq__ to compare DiffractionObjects
#214
Changes from all commits
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 |
|---|---|---|
|
|
@@ -8,43 +8,6 @@ | |
|
|
||
| from diffpy.utils.diffraction_objects import XQUANTITIES, DiffractionObject | ||
|
|
||
|
|
||
| def compare_dicts(dict1, dict2): | ||
| assert dict1.keys() == dict2.keys(), "Keys mismatch" | ||
| for key in dict1: | ||
| val1, val2 = dict1[key], dict2[key] | ||
| if isinstance(val1, np.ndarray) and isinstance(val2, np.ndarray): | ||
| assert np.allclose(val1, val2), f"Arrays for key '{key}' differ" | ||
| elif isinstance(val1, np.float64) and isinstance(val2, np.float64): | ||
| assert np.isclose(val1, val2), f"Float64 values for key '{key}' differ" | ||
| else: | ||
| assert val1 == val2, f"Values for key '{key}' differ: {val1} != {val2}" | ||
|
|
||
|
|
||
| def dicts_equal(dict1, dict2): | ||
| equal = True | ||
| print("") | ||
| print(dict1) | ||
| print(dict2) | ||
| if not dict1.keys() == dict2.keys(): | ||
| equal = False | ||
| for key in dict1: | ||
| val1, val2 = dict1[key], dict2[key] | ||
| if isinstance(val1, np.ndarray) and isinstance(val2, np.ndarray): | ||
| if not np.allclose(val1, val2): | ||
| equal = False | ||
| elif isinstance(val1, list) and isinstance(val2, list): | ||
| if not val1.all() == val2.all(): | ||
| equal = False | ||
| elif isinstance(val1, np.float64) and isinstance(val2, np.float64): | ||
| if not np.isclose(val1, val2): | ||
| equal = False | ||
| else: | ||
| if not val1 == val2: | ||
| equal = False | ||
| return equal | ||
|
|
||
|
|
||
| params = [ | ||
| ( # Default | ||
| {}, | ||
|
|
@@ -193,14 +156,9 @@ def dicts_equal(dict1, dict2): | |
|
|
||
| @pytest.mark.parametrize("inputs1, inputs2, expected", params) | ||
| def test_diffraction_objects_equality(inputs1, inputs2, expected): | ||
| diffraction_object1 = DiffractionObject(**inputs1) | ||
| diffraction_object2 = DiffractionObject(**inputs2) | ||
| # diffraction_object1_attributes = [key for key in diffraction_object1.__dict__ if not key.startswith("_")] | ||
| # for i, attribute in enumerate(diffraction_object1_attributes): | ||
| # setattr(diffraction_object1, attribute, inputs1[i]) | ||
| # setattr(diffraction_object2, attribute, inputs2[i]) | ||
| print(dicts_equal(diffraction_object1.__dict__, diffraction_object2.__dict__), expected) | ||
| assert dicts_equal(diffraction_object1.__dict__, diffraction_object2.__dict__) == expected | ||
|
Contributor
Author
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 we will be introducing an unique
Contributor
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. @bobleesj yes, this is much cleaner. A sure sign that our code and API is improving, don't you think?
Contributor
Author
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. absolutely |
||
| do_1 = DiffractionObject(**inputs1) | ||
| do_2 = DiffractionObject(**inputs2) | ||
| assert (do_1 == do_2) == expected | ||
|
|
||
|
|
||
| def test_on_xtype(): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions are no longer used in our test code - We. may use the
DeepDifflibrary instead to compare two dicts as implemented in our previous PR: