From 1340878979119533b7d5831f141c9e356847fcd8 Mon Sep 17 00:00:00 2001 From: Xu Hong Chen <110699064+xhgchen@users.noreply.github.com> Date: Tue, 21 Feb 2023 16:55:25 -0700 Subject: [PATCH] Add tests for exception raise in PSA (per issue #597) * Towards #597 * Checks that get_num_atoms in PSAnalysis and Path raises a ValueError and displays "No path data" --- .../MDAnalysisTests/analysis/test_psa.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/testsuite/MDAnalysisTests/analysis/test_psa.py b/testsuite/MDAnalysisTests/analysis/test_psa.py index 0fa526ba505..7abef571d9a 100644 --- a/testsuite/MDAnalysisTests/analysis/test_psa.py +++ b/testsuite/MDAnalysisTests/analysis/test_psa.py @@ -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 @@ -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()