Skip to content

Commit d945df1

Browse files
author
William de Vazelhes
committed
FIX: fix test that was not tested because didn't start with test_...
1 parent 99b0322 commit d945df1

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

metric_learn/_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ def _check_sdp_from_eigen(w, tol=None):
347347
"""
348348
if tol is None:
349349
tol = w.max() * len(w) * np.finfo(w.dtype).eps
350-
assert tol >= 0, ValueError("tol should be positive.")
350+
if tol < 0:
351+
raise ValueError("tol should be positive.")
351352
if any(w < - tol):
352353
raise ValueError("Matrix is not positive semidefinite (PSD).")
353354

test/test_utils.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,19 +1054,16 @@ def test__validate_vector():
10541054
validate_vector(x)
10551055

10561056

1057-
def _check_sdp_from_eigen_positive_err_messages():
1057+
def test_check_sdp_from_eigen_positive_err_messages():
10581058
"""Tests that if _check_sdp_from_eigen is given a negative tol it returns
1059-
an error, and if positive it does not"""
1060-
w = np.random.RandomState(42).randn(10)
1059+
an error, and if positive (or None) it does not"""
1060+
w = np.abs(np.random.RandomState(42).randn(10)) + 1
10611061
with pytest.raises(ValueError) as raised_error:
10621062
_check_sdp_from_eigen(w, -5.)
10631063
assert str(raised_error.value) == "tol should be positive."
10641064
with pytest.raises(ValueError) as raised_error:
10651065
_check_sdp_from_eigen(w, -1e-10)
10661066
assert str(raised_error.value) == "tol should be positive."
1067-
with pytest.raises(ValueError) as raised_error:
1068-
_check_sdp_from_eigen(w, 1.)
1069-
assert len(raised_error.value) == 0
1070-
with pytest.raises(ValueError) as raised_error:
1071-
_check_sdp_from_eigen(w, 0.)
1072-
assert str(raised_error.value) == 0
1067+
_check_sdp_from_eigen(w, 1.)
1068+
_check_sdp_from_eigen(w, 0.)
1069+
_check_sdp_from_eigen(w, None)

0 commit comments

Comments
 (0)