Skip to content

Commit 70aae14

Browse files
authored
Modernize assertions in test_distances.py (part of #3743) (#5158)
- modernize numpy testing assertions (#3743) in `analysis/test_distances.py`
1 parent b62e2f7 commit 70aae14

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

testsuite/MDAnalysisTests/analysis/test_distances.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
2222
#
2323
import pytest
24-
import scipy
2524
import scipy.spatial
2625

2726
import MDAnalysis
@@ -30,12 +29,10 @@
3029
import MDAnalysis.analysis.distances
3130

3231
from numpy.testing import (
33-
assert_equal,
3432
assert_array_equal,
35-
assert_almost_equal,
36-
assert_array_almost_equal,
3733
assert_allclose,
3834
)
35+
3936
import numpy as np
4037

4138

@@ -99,7 +96,7 @@ def test_np(self, coord, shape, res_no_pbc):
9996
assert contacts.shape == shape, "wrong shape (should be {0})".format(
10097
shape
10198
)
102-
assert_equal(contacts, res_no_pbc)
99+
assert_array_equal(contacts, res_no_pbc)
103100

104101
def test_sparse(self, coord, shape, res_no_pbc):
105102
contacts = MDAnalysis.analysis.distances.contact_matrix(
@@ -108,7 +105,7 @@ def test_sparse(self, coord, shape, res_no_pbc):
108105
assert contacts.shape == shape, "wrong shape (should be {0})".format(
109106
shape
110107
)
111-
assert_equal(contacts.toarray(), res_no_pbc)
108+
assert_array_equal(contacts.toarray(), res_no_pbc)
112109

113110
def test_box_numpy(self, coord, box, shape, res_pbc):
114111
contacts = MDAnalysis.analysis.distances.contact_matrix(
@@ -117,7 +114,7 @@ def test_box_numpy(self, coord, box, shape, res_pbc):
117114
assert contacts.shape == shape, "wrong shape (should be {0})".format(
118115
shape
119116
)
120-
assert_equal(contacts, res_pbc)
117+
assert_array_equal(contacts, res_pbc)
121118

122119
def test_box_sparse(self, coord, box, shape, res_pbc):
123120
contacts = MDAnalysis.analysis.distances.contact_matrix(
@@ -126,7 +123,7 @@ def test_box_sparse(self, coord, box, shape, res_pbc):
126123
assert contacts.shape == shape, "wrong shape (should be {0})".format(
127124
shape
128125
)
129-
assert_equal(contacts.toarray(), res_pbc)
126+
assert_array_equal(contacts.toarray(), res_pbc)
130127

131128

132129
class TestDist(object):
@@ -187,7 +184,7 @@ def test_pairwise_dist_offset_effect(self, ag, ag2, expected):
187184
def test_offset_calculation(self, ag, ag2):
188185
"""Test that offsets fed to dist() are correctly calculated."""
189186
actual = MDAnalysis.analysis.distances.dist(ag, ag2, offset=33)[:2]
190-
assert_equal(
187+
assert_array_equal(
191188
actual, np.array([ag.atoms.resids + 33, ag2.atoms.resids + 33])
192189
)
193190

@@ -242,7 +239,7 @@ def test_between_simple_case_indices_only(self, group, ag, ag2, expected):
242239
actual = MDAnalysis.analysis.distances.between(
243240
group, ag, ag2, self.distance
244241
).indices
245-
assert_equal(actual, expected)
242+
assert_array_equal(actual, expected)
246243

247244
@pytest.mark.parametrize("dists", [5.9, 0.0])
248245
def test_between_return_type(self, dists, group, ag, ag2):

0 commit comments

Comments
 (0)