Skip to content
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

1) Capture no wavelength UserWarning for test_q_to_thh method 2) discuss passing variables to @pytest.mark.parametrize #225

Merged
merged 9 commits into from
Dec 14, 2024

Conversation

bobleesj
Copy link
Contributor

@bobleesj bobleesj commented Dec 13, 2024

Here, the goal is to discuss how to write good tests using @pytest.mark.parametrize and also test warning messages.

Copy link

Warning! No news item is found for this PR. If this is a user-facing change/feature/fix,
please add a news item by copying the format from news/TEMPLATE.rst.

Copy link

codecov bot commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (84b402f) to head (69aa7c7).
Report is 17 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main      #225      +/-   ##
===========================================
+ Coverage   99.70%   100.00%   +0.29%     
===========================================
  Files           8         8              
  Lines         340       343       +3     
===========================================
+ Hits          339       343       +4     
+ Misses          1         0       -1     
Files with missing lines Coverage Δ
tests/test_diffraction_objects.py 100.00% <100.00%> (ø)
tests/test_transforms.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

def test_q_to_tth(wavelength, q, expected_tth):

if wavelength is None:
with pytest.warns(UserWarning, match="INFO: no wavelength has been specified"):
Copy link
Contributor Author

@bobleesj bobleesj Dec 13, 2024

Choose a reason for hiding this comment

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

Second, here, it feels counter productive to write all the warning msgs:

UserWarning: INFO: no wavelength has been specified. You can continue to use the DiffractionObject but some of its powerful features will not be available. To specify a wavelength, set diffraction_object.wavelength = [number], where diffraction_object is the variable name of you Diffraction Object, and number is the wavelength in angstroms.

assuming we have a specific test func for this warning msg.

Please suggest if this is okay @sbillinge

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the user warning written out because the test defines the behavior. So the workflow is to write the test and review it until we like it. Then write the code. Here, it slipped by but we don't want "INFO" here. It is either a WARNING or an INFO, it can't be both. Also, I think when we are describing code it is better to write the code than describe it in words, so say ".... To speciffy a wavelength, if my_object = DiffractionObject(xarray, yarray, "tth") then you can type my_object.wavelength = 1.54` if the wavelength is 1.54 angstroms." Something like that.

If test the same message in more than one test we can assign it to a variable. But it is better if it is closer to the test and we are not importing it orsomething.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done.

@bobleesj bobleesj marked this pull request as ready for review December 13, 2024 17:32
@bobleesj
Copy link
Contributor Author

@sbillinge ready for review - cc'ing @yucongalicechen for our discussions moving forward.

This was referenced Dec 13, 2024
Copy link
Contributor Author

@bobleesj bobleesj left a comment

Choose a reason for hiding this comment

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

@sbillinge ready for review - there are still warnings but prob it would be best to create a couple of PRs by theme.

@bobleesj bobleesj changed the title Capture no wavelength UserWarning for test_q_to_thh method 1) Capture no wavelength UserWarning for test_q_to_thh method 2) discuss passing variables to @pytest.mark.parametrize Dec 14, 2024
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.

These improvements are excellent! Thanks @bobleesj ! I left a couple of small tweaks and comments on your suggestions to make it even better. I think done of these lessons can carry over to better group standards in general so it is not wasted effort to get this right 👍

"No wavelength has been specified. You can continue to use the DiffractionObject, but "
"some of its powerful features will not be available. "
"To specify a wavelength, if you have do = DiffractionObject(xarray, yarray, 'tth'), "
"you may set do.wavelength = 1.54 with the unit in angstroms."
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is clearer to say than 1.54 here, it add "for a wavelength of 1.54 angstroms". Which would someone like Fillipo find clearer?

"No wavelength has been specified. You can continue to use the DiffractionObject, but "
"some of its powerful features will not be available. "
"To specify a wavelength, if you have do = DiffractionObject(xarray, yarray, 'tth'), "
"you may set do.wavelength = 1.54 with the unit in angstroms."
Copy link
Contributor

Choose a reason for hiding this comment

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

Please see the small tweak above

@bobleesj
Copy link
Contributor Author

These improvements are excellent! Thanks @bobleesj ! I left a couple of small tweaks and comments on your suggestions to make it even better. I think done of these lessons can carry over to better group standards in general so it is not wasted effort to get this right 👍

Yes, I am recording these lessons. I will sync with the GitLab page: https://gitlab.thebillingegroup.com/resources/group-wiki/-/wikis/Lessons-learned-in-Billinge-Group

Copy link
Contributor Author

@bobleesj bobleesj left a comment

Choose a reason for hiding this comment

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

@sbillinge ready for review - the only modification was done on wavelength_warning_emsg as shown in the latest commit.

Also created an issue #229 for refactoring test_on_xtype

@sbillinge sbillinge merged commit 9fa7ce7 into diffpy:main Dec 14, 2024
4 of 5 checks passed
@bobleesj bobleesj deleted the warnings branch December 14, 2024 17:21
@bobleesj bobleesj mentioned this pull request Dec 14, 2024
9 tasks
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