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

Add tests for exception raise in PSA (closes #4036) #4037

Merged
merged 8 commits into from
Mar 9, 2023

Conversation

xhgchen
Copy link
Member

@xhgchen xhgchen commented Feb 22, 2023

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello there first time contributor! Welcome to the MDAnalysis community! We ask that all contributors abide by our Code of Conduct and that first time contributors introduce themselves on the developer mailing list so we can get to know you. You can learn more about participating here. Please also add yourself to package/AUTHORS as part of this PR.

@codecov
Copy link

codecov bot commented Feb 22, 2023

Codecov Report

Patch coverage has no change and project coverage change: +0.02 🎉

Comparison is base (55a5abd) 93.54% compared to head (8b10e29) 93.56%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4037      +/-   ##
===========================================
+ Coverage    93.54%   93.56%   +0.02%     
===========================================
  Files          191      191              
  Lines        25065    25065              
  Branches      4042     4042              
===========================================
+ Hits         23446    23452       +6     
+ Misses        1099     1093       -6     
  Partials       520      520              
Impacted Files Coverage Δ
package/MDAnalysis/analysis/psa.py 85.38% <0.00%> (+1.16%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@xhgchen xhgchen force-pushed the psa-get-num-atoms-tests branch from e75a102 to 18d63d4 Compare February 22, 2023 01:29
run Path.to_path()"""
match_exp = "No path data"
with pytest.raises(ValueError, match=match_exp):
universe1 = mda.Universe(PSF, DCD)
Copy link
Member

Choose a reason for hiding this comment

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

If you are going to use these Universes more than once probably best to make them a fixture

Copy link
Member Author

@xhgchen xhgchen Feb 22, 2023

Choose a reason for hiding this comment

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

Done! Thanks for the feedback! I also reorganized my tests to go under class TestPSAExceptions and added 2 new tests for psa.get_num_paths and psa.get_paths as I realized those functions needed similar testing. That should cover all the "no path data" type exceptions in the module.

@xhgchen xhgchen requested a review from hmacdope February 23, 2023 00:08
class TestPSAExceptions(object):
'''Tests for exceptions that should be raised
or caught by code in the psa module.'''

@pytest.fixture()
Copy link
Member

Choose a reason for hiding this comment

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

You can probably collapse these tests into one test where you call each method sequentially, would save a bit of space.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great, I was actually wondering whether that was appropriate too but I was hesitant as I read someone mention on Stack Overflow that they preferred testing them individually. I left the fixture there because I think it may be applicable for future tests, but please let me know if it would be better to remove it.

@xhgchen xhgchen requested a review from hmacdope February 26, 2023 22:07
# Cases where user did not run PSAnalysis.generate_paths()
with pytest.raises(ValueError, match=match_exp):
psa.get_num_atoms()

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a quick comment for last two cases?

Copy link
Member Author

@xhgchen xhgchen Mar 1, 2023

Choose a reason for hiding this comment

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

For sure! I finished adding new comments and also tried to make the comments more clear. Changes should be final now, but please let me know if there is anything else that can be done. I messed up the commit history while trying to rebase and resolve conflicts but I managed to fix it with a hard reset. Definitely learned a lot while troubleshooting that!

Edit: Codecov is acting strangely with the checks; did something happen?

@xhgchen xhgchen force-pushed the psa-get-num-atoms-tests branch from cbeffab to 7c3de5b Compare March 1, 2023 05:33
@xhgchen xhgchen requested a review from hmacdope March 1, 2023 05:55
@hmacdope
Copy link
Member

hmacdope commented Mar 1, 2023

@xhgchen the CI is being flaky, I will re-run it.

@xhgchen xhgchen force-pushed the psa-get-num-atoms-tests branch from 7c3de5b to 50fbe86 Compare March 2, 2023 02:44
@xhgchen
Copy link
Member Author

xhgchen commented Mar 2, 2023

@hmacdope I pushed just now to resolve conflicts but did not make any other changes. Hopefully the checks run better this time!

@xhgchen xhgchen force-pushed the psa-get-num-atoms-tests branch from 50fbe86 to 8d9a012 Compare March 2, 2023 17:17
Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Thanks @xhgchen looks great.
Would another @MDAnalysis/coredevs or @MDAnalysis/gsoc-mentors be able to take a quick look?

Copy link
Member

@ojeda-e ojeda-e left a comment

Choose a reason for hiding this comment

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

Thanks @xhgchen!
The CI for the darker_lint is failing (See here). Just a quick update to the format and it's ready to go.

Pinning @hmacdope in case this is not the reason why the CI was failing before.

@IAlibay
Copy link
Member

IAlibay commented Mar 4, 2023

Thanks @xhgchen!
The CI for the darker_lint is failing (See here). Just a quick update to the format and it's ready to go.

Pinning @hmacdope in case this is not the reason why the CI was failing before.

Just as an FYI on this - non flake8 failure of the darker lint are fine, they should only be considered informative.

@IAlibay
Copy link
Member

IAlibay commented Mar 4, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@xhgchen
Copy link
Member Author

xhgchen commented Mar 4, 2023

Thank you all for taking the time to review this! I did check the darker lint failure multiple times but I left it alone after fixing the style issues in my first few commits as it did not seem to involve my code. If I was mistaken and there is anything specific I can fix, I would be happy to make those changes!

@hmacdope
Copy link
Member

hmacdope commented Mar 4, 2023

Yeah style things optional. :)

@hmacdope hmacdope requested a review from ojeda-e March 5, 2023 02:24
xhgchen added 7 commits March 5, 2023 10:51
* Towards MDAnalysis#597
* Checks that get_num_atoms in PSAnalysis and Path raises a ValueError
  and displays "No path data"
* Make universe1 = mda.Universe(PSF, DCD) a fixture
* Add similar tests to raise ValueErrors for get_num_paths
and get_paths
* Reorganize tests under class TestPSAExceptions
@xhgchen xhgchen force-pushed the psa-get-num-atoms-tests branch from 8d9a012 to 8b10e29 Compare March 5, 2023 17:56
@xhgchen
Copy link
Member Author

xhgchen commented Mar 5, 2023

Just resolving a CHANGELOG conflict :)

@orbeckst
Copy link
Member

orbeckst commented Mar 9, 2023

Can we merge the PR, @hmacdope ?

@hmacdope
Copy link
Member

hmacdope commented Mar 9, 2023

yep all good!

@hmacdope hmacdope merged commit ac96a65 into MDAnalysis:develop Mar 9, 2023
@xhgchen xhgchen deleted the psa-get-num-atoms-tests branch March 10, 2023 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tests for get_num_atoms exception raise in PSA (per issue #597)
5 participants