Skip to content

Conversation

@yucongalicechen
Copy link
Contributor

issue #186: test function for on_xtype

@codecov
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.27%. Comparing base (ed9fb03) to head (7eb0c0d).
Report is 35 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #192      +/-   ##
==========================================
- Coverage   96.53%   96.27%   -0.27%     
==========================================
  Files           8        8              
  Lines         289      322      +33     
==========================================
+ Hits          279      310      +31     
- Misses         10       12       +2     
Files with missing lines Coverage Δ
tests/test_diffraction_objects.py 87.77% <100.00%> (+1.21%) ⬆️

... and 1 file with indirect coverage changes

@yucongalicechen yucongalicechen marked this pull request as draft December 3, 2024 19:25
@sbillinge
Copy link
Contributor

I am a little unclear what this is doing. Could you maybe hit down some words to explain the high level view?

@yucongalicechen
Copy link
Contributor Author

I am a little unclear what this is doing. Could you maybe hit down some words to explain the high level view?

I think this is for checking if on_xtype function returns the correct 2D array (e.g., tth array, q array, etc.)

@yucongalicechen yucongalicechen marked this pull request as ready for review December 3, 2024 19:34
@sbillinge
Copy link
Contributor

I am a little unclear what this is doing. Could you maybe hit down some words to explain the high level view?

I think this is for checking if on_xtype function returns the correct 2D array (e.g., tth array, q array, etc.)

Is this a new function? One that can be used instead of self.on_tth? We want that function, but then we want a test that tests that it returns the right thing.

@yucongalicechen
Copy link
Contributor Author

I am a little unclear what this is doing. Could you maybe hit down some words to explain the high level view?

I think this is for checking if on_xtype function returns the correct 2D array (e.g., tth array, q array, etc.)

Is this a new function? One that can be used instead of self.on_tth? We want that function, but then we want a test that tests that it returns the right thing.

It's an old function. This PR is to check that it returns the right array and raise an error if it's an invalid xtype. It doesn't replace on_tth but simply calls on_tth if xtype is tth.

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls see inline comment

@pytest.mark.parametrize("inputs, expected", params_on_xtype)
def test_on_xtype(inputs, expected):
test = DiffractionObject()
test.on_tth = np.array([inputs[1], inputs[0]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really how DO's should be used. The tth, q and d arrays are somehow all different versions of the same array so we shouldn't be able to set them independently like this. If we can now this is not desirable behavior, so we probably don't want a test that does this. We should probably create a set property operator that generates all the arrays whenever a single one is specified in this way. But for sure, we don't want a test with this undesirable behavior....

@yucongalicechen
Copy link
Contributor Author

@sbillinge ready for review!

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see inline.. We can discuss, but this should behave the same as DO.on_q() etc., and I think they should maybe return list of 1D arrays.


from diffpy.utils.tools import get_package_info
from diffpy.utils.transforms import d_to_q, d_to_tth, q_to_d, q_to_tth, tth_to_d, tth_to_q

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to return a list of two 1D arrays

return (
f"WARNING: I don't know how to handle the xtype, '{xtype}'. Please rerun specifying an "
f"xtype from {*XQUANTITIES, }"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one small tweak inline

with pytest.raises(
ValueError,
match=re.escape(
f"WARNING: I don't know how to handle the xtype, 'invalid'. Please rerun specifying an "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think are now raising an exception, right? So this isn't a warning. Just remove WARNING: Python will handle the rest.

@sbillinge sbillinge merged commit 443fe36 into diffpy:main Dec 7, 2024
4 of 5 checks passed
@yucongalicechen yucongalicechen deleted the xtype-test branch December 7, 2024 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants