From b329d192acf78f1dfac121c9d940f644fc7b1b9c Mon Sep 17 00:00:00 2001 From: Pranay Tukaram Pelapkar Date: Wed, 26 Nov 2025 16:44:22 +0530 Subject: [PATCH] Modernize assertions in test_distances.py (part of #3743) --- .../MDAnalysisTests/analysis/test_distances.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/testsuite/MDAnalysisTests/analysis/test_distances.py b/testsuite/MDAnalysisTests/analysis/test_distances.py index 90fe8d75e8e..60c362d5cd6 100644 --- a/testsuite/MDAnalysisTests/analysis/test_distances.py +++ b/testsuite/MDAnalysisTests/analysis/test_distances.py @@ -21,7 +21,6 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # import pytest -import scipy import scipy.spatial import MDAnalysis @@ -30,12 +29,10 @@ import MDAnalysis.analysis.distances from numpy.testing import ( - assert_equal, assert_array_equal, - assert_almost_equal, - assert_array_almost_equal, assert_allclose, ) + import numpy as np @@ -99,7 +96,7 @@ def test_np(self, coord, shape, res_no_pbc): assert contacts.shape == shape, "wrong shape (should be {0})".format( shape ) - assert_equal(contacts, res_no_pbc) + assert_array_equal(contacts, res_no_pbc) def test_sparse(self, coord, shape, res_no_pbc): contacts = MDAnalysis.analysis.distances.contact_matrix( @@ -108,7 +105,7 @@ def test_sparse(self, coord, shape, res_no_pbc): assert contacts.shape == shape, "wrong shape (should be {0})".format( shape ) - assert_equal(contacts.toarray(), res_no_pbc) + assert_array_equal(contacts.toarray(), res_no_pbc) def test_box_numpy(self, coord, box, shape, res_pbc): contacts = MDAnalysis.analysis.distances.contact_matrix( @@ -117,7 +114,7 @@ def test_box_numpy(self, coord, box, shape, res_pbc): assert contacts.shape == shape, "wrong shape (should be {0})".format( shape ) - assert_equal(contacts, res_pbc) + assert_array_equal(contacts, res_pbc) def test_box_sparse(self, coord, box, shape, res_pbc): contacts = MDAnalysis.analysis.distances.contact_matrix( @@ -126,7 +123,7 @@ def test_box_sparse(self, coord, box, shape, res_pbc): assert contacts.shape == shape, "wrong shape (should be {0})".format( shape ) - assert_equal(contacts.toarray(), res_pbc) + assert_array_equal(contacts.toarray(), res_pbc) class TestDist(object): @@ -187,7 +184,7 @@ def test_pairwise_dist_offset_effect(self, ag, ag2, expected): def test_offset_calculation(self, ag, ag2): """Test that offsets fed to dist() are correctly calculated.""" actual = MDAnalysis.analysis.distances.dist(ag, ag2, offset=33)[:2] - assert_equal( + assert_array_equal( actual, np.array([ag.atoms.resids + 33, ag2.atoms.resids + 33]) ) @@ -242,7 +239,7 @@ def test_between_simple_case_indices_only(self, group, ag, ag2, expected): actual = MDAnalysis.analysis.distances.between( group, ag, ag2, self.distance ).indices - assert_equal(actual, expected) + assert_array_equal(actual, expected) @pytest.mark.parametrize("dists", [5.9, 0.0]) def test_between_return_type(self, dists, group, ag, ag2):