-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
TST Changes assert to pytest style in tests/test_random_projection.py #19846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TST Changes assert to pytest style in tests/test_random_projection.py #19846
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR @LSturtew !
with pytest.raises(ValueError): | ||
johnson_lindenstrauss_min_dim(100, eps=1.1) | ||
johnson_lindenstrauss_min_dim(100, eps=0.0) | ||
johnson_lindenstrauss_min_dim(100, eps=-0.1) | ||
johnson_lindenstrauss_min_dim(0, eps=0.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would only check the first call because it would error first. The other calls to johnson_lindenstrauss_min_dim
would not run. Can adjust this test to use pytest.mark.parametrize
?:
@pytest.mark.parametrize("n_samples, eps", [
(100, 1.1),
(100, 0.0),
(100, -0.1),
(0, 0.5)
])
def test_invalid_jl_domain(n_samples, eps):
with pytest.raises(ValueError):
johnson_lindenstrauss_min_dim(n_samples, eps=eps)
with pytest.raises(ValueError): | ||
johnson_lindenstrauss_min_dim(3 * [100], eps=2 * [0.9]) | ||
johnson_lindenstrauss_min_dim(3 * [100], eps=2 * [0.9]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can use pytest.mark.parametrize
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates.
I made some suggestions that overrides my previous ones.
def check_input_size_random_matrix(random_matrix): | ||
assert_raises(ValueError, random_matrix, 0, 0) | ||
assert_raises(ValueError, random_matrix, -1, 1) | ||
assert_raises(ValueError, random_matrix, 1, -1) | ||
assert_raises(ValueError, random_matrix, 1, 0) | ||
assert_raises(ValueError, random_matrix, -1, 0) | ||
@pytest.mark.parametrize("random_matrix", all_random_matrix) | ||
@pytest.mark.parametrize("n_components, n_features",[(0,0),(-1,1),(1,-1),(1,0),(-1,0)]) | ||
def test_input_size_random_matrix(random_matrix,n_components,n_features): | ||
with pytest.raises(ValueError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I read this incorrectly and thought it was a test_*
function. I think using a for look like check_input_with_sparse_random_matrix
would be the more minimal change:
def check_input_size_random_matrix(random_matrix):
inputs = [(0,0), (-1,1), (1,-1), (1,0), (-1,0)]
for n_components, n_features in inputs:
with pytest.raises(ValueError):
random_matrix(n_components, n_features)
This way test_basic_property_of_random_matrix
does not need to change.
…urtew/scikit-learn into assert_raises_test_random_projection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just one minor comment
@pytest.mark.parametrize("n_samples, eps", [ | ||
(3 * [100], 2 * [0.9]), (3 * [100], 2 * [0.9]) | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the 2 sets of parameters are the same. We can remove the parametrization
Thanks @LSturtew ! |
Reference Issues/PRs
References #14216
What does this implement/fix? Explain your changes.
Changed the
assert_raises
,assert_message
,assert_warns
in tests/test_random_projection.py topytest.raises()
/pytest.warns()
.Any other comments?