Skip to content

Commit

Permalink
Add tests for exception raise in PSA (per issue MDAnalysis#597)
Browse files Browse the repository at this point in the history
* Towards MDAnalysis#597
* Checks that get_num_atoms in PSAnalysis and Path raises a ValueError
  and displays "No path data"
  • Loading branch information
xhgchen committed Mar 1, 2023
1 parent de6d0a8 commit 1340878
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions testsuite/MDAnalysisTests/analysis/test_psa.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@ def test_distances_from_hausdorff_pairs_frames(self, psa):
assert_almost_equal(hausd_pairs_dists2,
dists[self.iu1],
decimal=6, err_msg=err_msg)

def test_get_num_atoms_no_path_data(self, tmpdir):
"""Test that ValueError is raised when no path data i.e. user did not
run generate_paths() in class PSAnalysis"""
match_exp = "No path data"
with pytest.raises(ValueError, match=match_exp):
universe1 = mda.Universe(PSF, DCD)
universe2 = mda.Universe(PSF, DCD2)
universe_rev = mda.Universe(PSF, DCD)

psa = PSA.PSAnalysis([universe1, universe2, universe_rev],
path_select='name CA',
targetdir=str(tmpdir))
psa.get_num_atoms()


class TestPSAExceptions(object):
'''Tests for exceptions that should be raised
Expand Down Expand Up @@ -500,3 +515,15 @@ def test_discrete_Frechet_concentric_circles(self, path_1, path_2):
expected = 4.5
actual = PSA.discrete_frechet(path_1, path_2)
assert_almost_equal(actual, expected)


def test_get_num_atoms_path_no_path_data():
"""Test that ValueError is raised when no path data i.e. user did not
run generate_paths() in class Path"""
match_exp = "No path data"
with pytest.raises(ValueError, match=match_exp):
universe1 = mda.Universe(PSF, DCD)
universe_rev = mda.Universe(PSF, DCD)

path = PSA.Path(universe1, universe_rev)
path.get_num_atoms()

0 comments on commit 1340878

Please sign in to comment.