-
Notifications
You must be signed in to change notification settings - Fork 830
fix error message for XDR readers #4231
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dc10474
fix error message for XDR readers
orbeckst 4f18afb
more robust checking of multiple warnings
orbeckst 9b0c1c9
Apply suggestions from code review
orbeckst 997e15c
simplified testing for multiple warnings
orbeckst fd4fe34
Merge branch 'fix-xdr-errormessages' of github.com:MDAnalysis/mdanaly…
orbeckst 4f8be63
more explicit warnings testing
orbeckst f995b31
only use f-strings where used
orbeckst 874d9ba
ignore warnings not germane to the XDR tests
IAlibay 593aa9f
Merge branch 'fix-xdr-errormessages' of github.com:MDAnalysis/mdanaly…
orbeckst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import pytest | ||
| from unittest.mock import patch | ||
|
|
||
| import re | ||
| import os | ||
| import shutil | ||
| import subprocess | ||
|
|
@@ -47,6 +48,16 @@ | |
| from MDAnalysisTests.util import get_userid | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("filename,kwargs,reference", [ | ||
| ("foo.xtc", {}, ".foo.xtc_offsets.npz"), | ||
| ("foo.xtc", {"ending": "npz"}, ".foo.xtc_offsets.npz"), | ||
| ("bar.0001.trr", {"ending": "npzzzz"}, ".bar.0001.trr_offsets.npzzzz"), | ||
| ]) | ||
| def test_offsets_filename(filename, kwargs, reference): | ||
| fn = XDR.offsets_filename(filename, **kwargs) | ||
| assert fn == reference | ||
|
orbeckst marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class _XDRReader_Sub(object): | ||
| @pytest.fixture() | ||
| def atoms(self): | ||
|
|
@@ -212,7 +223,7 @@ def go_beyond_EOF(): | |
|
|
||
| with pytest.raises(StopIteration): | ||
| go_beyond_EOF() | ||
|
|
||
| def test_read_next_timestep_ts_no_positions(self, universe): | ||
| # primarily tests branching on ts.has_positions in _read_next_timestep | ||
| ts = universe.trajectory[0] | ||
|
|
@@ -544,6 +555,7 @@ class _GromacsWriterIssue117(object): | |
| def universe(self): | ||
| return mda.Universe(PRMncdf, NCDF) | ||
|
|
||
| @pytest.mark.filterwarnings("ignore: ATOMIC_NUMBER record not found") | ||
| def test_write_trajectory(self, universe, tmpdir): | ||
| """Test writing Gromacs trajectories from AMBER NCDF (Issue 117)""" | ||
| outfile = str(tmpdir.join('xdr-writer-issue117' + self.ext)) | ||
|
|
@@ -559,10 +571,9 @@ def test_write_trajectory(self, universe, tmpdir): | |
| written_ts._pos, | ||
| orig_ts._pos, | ||
| self.prec, | ||
| err_msg="coordinate mismatch " | ||
| "between original and written " | ||
| "trajectory at frame %d (orig) vs %d " | ||
| "(written)" % (orig_ts.frame, written_ts.frame)) | ||
| err_msg=("coordinate mismatch between original and written " | ||
| f"trajectory at frame {orig_ts.frame:d} (orig) vs " | ||
| f"{orig_ts.frame:d} (written)")) | ||
|
|
||
|
|
||
| class TestXTCWriterIssue117(_GromacsWriterIssue117): | ||
|
|
@@ -755,25 +766,34 @@ def test_nonexistent_offsets_file(self, traj): | |
| outfile_offsets = XDR.offsets_filename(traj) | ||
| with patch.object(np, "load") as np_load_mock: | ||
| np_load_mock.side_effect = IOError | ||
| saved_offsets = XDR.read_numpy_offsets(outfile_offsets) | ||
| assert_equal(saved_offsets, False) | ||
| with pytest.warns(UserWarning, match=re.escape( | ||
| f"Failed to load offsets file {outfile_offsets}")): | ||
| saved_offsets = XDR.read_numpy_offsets(outfile_offsets) | ||
| assert saved_offsets == False | ||
|
|
||
| def test_nonexistent_offsets_file(self, traj): | ||
| def test_corrupted_offsets_file(self, traj): | ||
|
Member
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. btw, this shadowed the preceeding test; renaming increased our tests |
||
| # assert that a corrupted file returns False during read-in | ||
| # Issue #3230 | ||
| outfile_offsets = XDR.offsets_filename(traj) | ||
| with patch.object(np, "load") as np_load_mock: | ||
| np_load_mock.side_effect = ValueError | ||
| saved_offsets = XDR.read_numpy_offsets(outfile_offsets) | ||
| assert_equal(saved_offsets, False) | ||
| with pytest.warns(UserWarning, match=re.escape( | ||
| f"Failed to load offsets file {outfile_offsets}")): | ||
| saved_offsets = XDR.read_numpy_offsets(outfile_offsets) | ||
| assert saved_offsets == False | ||
|
|
||
| def test_reload_offsets_if_offsets_readin_io_fails(self, trajectory): | ||
| # force the np.load call that is called in read_numpy_offsets | ||
| # during _load_offsets to give an IOError | ||
| # ensure that offsets are then read-in from the trajectory | ||
| with patch.object(np, "load") as np_load_mock: | ||
| np_load_mock.side_effect = IOError | ||
| trajectory._load_offsets() | ||
| with (pytest.warns(UserWarning, | ||
| match="Failed to load offsets file") and | ||
| pytest.warns(UserWarning, | ||
| match="reading offsets from trajectory instead")): | ||
| trajectory._load_offsets() | ||
|
|
||
| assert_almost_equal( | ||
| trajectory._xdr.offsets, | ||
| self.ref_offsets, | ||
|
|
@@ -866,7 +886,8 @@ def test_unsupported_format(self, traj): | |
| np.savez(fname, **saved_offsets) | ||
|
|
||
| # ok as long as this doesn't throw | ||
| reader = self._reader(traj) | ||
| with pytest.warns(UserWarning, match="Reload offsets from trajectory"): | ||
| reader = self._reader(traj) | ||
| reader[idx_frame] | ||
|
|
||
| @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.