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

fix error message for XDR readers #4231

Merged
merged 9 commits into from
Aug 11, 2023
Merged

fix error message for XDR readers #4231

merged 9 commits into from
Aug 11, 2023

Conversation

orbeckst
Copy link
Member

@orbeckst orbeckst commented Aug 10, 2023

Fixes #

Changes made in this Pull Request:

  • error message for not being able to write lockfile did not insert the filename into message: fixed by using proper f string
  • changed all .format to modern f string in XDR.py
  • add explicit test for offsets_filename()
  • add additional pytest.warns() to tests to catch warnings (reduces warnings output and checks that all expected warnings are raised with proper messages)

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

Developers certificate of origin


📚 Documentation preview 📚: https://mdanalysis--4231.org.readthedocs.build/en/4231/

- error message for not being able to write lockfile did not insert the filename into
  message: fixed by using proper f string
- changed all .format to modern f string in XDR.py
- add explicit test for offsets_filename()
- add additional pytest.warns() to tests to catch warnings (reduces warnings output and
  checks that all expected warnings are raised with proper messages)
@orbeckst
Copy link
Member Author

FYI, this is what the (small) error looks like in practice

>>> u = mda.Universe("md-01.tpr", "md-01.part0001.xtc")
~/miniconda3/envs/mda25/lib/python3.10/site-packages/MDAnalysis/coordinates/XDR.py:203: UserWarning: Cannot write lock/offset file in same location as {self.filename}. Using slow offset calculation.
  warnings.warn(f"Cannot write lock/offset file in same location as "
~/miniconda3/envs/mda25/lib/python3.10/site-packages/MDAnalysis/coordinates/XDR.py:259: UserWarning: Couldn't save offsets because: [Errno 13] Permission denied: '.md-01.part0001.xtc_offsets.npz'
  warnings.warn("Couldn't save offsets because: {}".format(e))

Note how {self.filename} is not replaced.

@github-actions
Copy link

github-actions bot commented Aug 10, 2023

Linter Bot Results:

Hi @orbeckst! Thanks for making this PR. We linted your code and found the following:

Some issues were found with the formatting of your code.

Code Location Outcome
main package ⚠️ Possible failure
testsuite ⚠️ Possible failure

Please have a look at the darker-main-code and darker-test-code steps here for more details: https://github.com/MDAnalysis/mdanalysis/actions/runs/5828228895/job/15805580193


Please note: The black linter is purely informational, you can safely ignore these outcomes if there are no flake8 failures!

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

Couple of small things, otherwise lgtm

@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (d33cc3a) 93.62% compared to head (593aa9f) 93.62%.
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4231   +/-   ##
========================================
  Coverage    93.62%   93.62%           
========================================
  Files          193      193           
  Lines        25295    25304    +9     
  Branches      4063     4064    +1     
========================================
+ Hits         23683    23692    +9     
  Misses        1096     1096           
  Partials       516      516           
Files Changed Coverage Δ
package/MDAnalysis/coordinates/XDR.py 97.72% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

orbeckst and others added 2 commits August 10, 2023 11:17
Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

cheers, lgtm!


def test_nonexistent_offsets_file(self, traj):
def test_corrupted_offsets_file(self, traj):
Copy link
Member Author

Choose a reason for hiding this comment

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

btw, this shadowed the preceeding test; renaming increased our tests

assert len(record) >= len(warning_messages)
found_messages = [str(r.message) for r in record]
# find at least 2 occurences (>= instead of == for robustness)
assert sum([ref in msg for msg in found_messages
Copy link
Member Author

Choose a reason for hiding this comment

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

I looked through the other tests in the file and found the following approach that looks a bit cleaner where we stack pytest.warns:

       with (pytest.warns(UserWarning, match="Couldn't save offsets") and
              pytest.warns(UserWarning, match="Cannot write")):
            self._reader(filename)

I'll rewrite to use that idiom.

- reduces warnings in test_xdr down to 2 (both related to del)
- test for empty selection and missing elements warnings
- rewriting more old-school parameter interpolation to f strings
@orbeckst
Copy link
Member Author

Thanks for the quick review @IAlibay . I apologize, I tacked on a few little things that I couldn't let go when I looked at the code again.

@orbeckst
Copy link
Member Author

One of the runners timed out so I restarted it.

@orbeckst
Copy link
Member Author

@RMeli or @IAlibay could one of you please volunteer to captain the PR and eventually merge it? I can do it if you prefer but it's better style (in my opinion) to not be the one merging your own PR (unless it's urgent....).

I think it's good for the project when there's visibly someone in charge of a PR.

@IAlibay
Copy link
Member

IAlibay commented Aug 11, 2023

lgtm!

@IAlibay IAlibay merged commit 6e80c28 into develop Aug 11, 2023
24 checks passed
@IAlibay IAlibay deleted the fix-xdr-errormessages branch August 11, 2023 17:09
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.

3 participants