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

Use a fixture for npz files in test_bat #2981

Merged
merged 3 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Fixes
Universe (PR #2893)
* ensure that unistd.h is included on macOS when compiling ENCORE's spe.c
(Issue #2934)
* Fix tests for analysis.bat that could fail when run in parallel and that
Copy link
Member

Choose a reason for hiding this comment

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

I guess technically it should be newest first, but I've seen plenty of cases where we've not followed this so it's a bit late to be pedantic now 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops... I have been doing it wrong for a while 😅

would create a test artifact (Issue #2979, PR #2981)

Enhancements
* Refactored analysis.helanal into analysis.helix_analysis
Expand Down
19 changes: 12 additions & 7 deletions testsuite/MDAnalysisTests/analysis/test_bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def bat(self, selected_residues):
R.run()
return R.bat

@pytest.fixture
def bat_npz(self, tmpdir, selected_residues):
filename = str(tmpdir / 'test_bat_IO.npy')
R = BAT(selected_residues)
R.run()
R.save(filename)
return filename

def test_bat_root_selection(self, selected_residues):
R = BAT(selected_residues)
assert_equal(R._root.indices, [8, 2, 1],
Expand Down Expand Up @@ -79,11 +87,8 @@ def test_bat_reconstruction(self, selected_residues, bat):
err_msg="error: Reconstructed Cartesian coordinates " + \
"don't match original")

def test_bat_IO(self, selected_residues, bat):
R = BAT(selected_residues)
R.run()
R.save('test_bat_IO.npy')
R2 = BAT(selected_residues, filename='test_bat_IO.npy')
def test_bat_IO(self, bat_npz, selected_residues, bat):
R2 = BAT(selected_residues, filename=bat_npz)
test_bat = R2.bat
assert_almost_equal(
bat,
Expand All @@ -107,8 +112,8 @@ def test_bat_disconnected_atom_group(self):
with pytest.raises(ValueError):
R = BAT(selected_residues)

def test_bat_incorrect_dims(self):
def test_bat_incorrect_dims(self, bat_npz):
u = mda.Universe(PSF, DCD)
selected_residues = u.select_atoms("resid 1-3")
with pytest.raises(ValueError):
R = BAT(selected_residues, filename='test_bat_IO.npy')
R = BAT(selected_residues, filename=bat_npz)