-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG+1] Pytest parametrization part2 - cluster, datasets and decomposition modules #11142
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
[MRG+1] Pytest parametrization part2 - cluster, datasets and decomposition modules #11142
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.
This looks nice, just a few minor comments. For other reviewers, you can disable whitespace differences in the diff, this makes this PR a lot easier to review!
sklearn/datasets/tests/test_base.py
Outdated
_remove_dir(TEST_CATEGORY_DIR1) | ||
@pytest.fixture | ||
def test_category_dir_2(load_files_root): | ||
TEST_CATEGORY_DIR2 = tempfile.mkdtemp(dir=load_files_root) |
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.
Bonus points if you remove capitalization here and everywhere else since they are not globals anymore.
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.
Good point, done.
sklearn/datasets/tests/test_base.py
Outdated
sample_file = tempfile.NamedTemporaryFile(dir=TEST_CATEGORY_DIR1, | ||
delete=False) | ||
sample_file.write(b("Hello World!\n")) | ||
sample_file.close() | ||
yield str(TEST_CATEGORY_DIR1) |
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.
I have a slight preference for .strpath
which I find more explicit. It's probably the case in many other places too.
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.
Yeah, but the returned object is a py.path.local
see tmdir defintion. Its readme recommends using pathlib instead, and is staged for removal in 4.0 pytest-dev/pytest#1260. All of this to say that I wouldn't expect contributors to know that it has the .strpath
method, and assuming that it can convert to string path correctly is the weakest assumption I can make.
Also that's the recommended approach for converting pathlib objects to str (https://www.python.org/dev/peps/pep-0428/#representing), so when the migration happen in pytest4 the code won't need to be changed.
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.
Fine with me, I was not aware of this.
@pytest.mark.parametrize('sparsity', [0, 0.1, .5, 0.99, 1]) | ||
@pytest.mark.parametrize('n_samples', [13, 101]) | ||
@pytest.mark.parametrize('n_features', [2, 7, 41]) | ||
def test_load_with_offsets(sparsity, n_samples, n_features): |
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.
nitpick: it would be nice to split test in two, since one part of the test does not depend of the parameters.
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.
Hmm, I can't see it. sparsity
is used to make the X
matrix that is then written to the f
BytesOI
object that is used pretty much everywhere in the test. Am I missing something?
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.
right, I missed that, sorry ...
Thanks for the review @lesteve ! I responded to your comments above. |
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
pytest parametrization of unit tests in
sklearn.datasets
,sklearn.cluster
,sklearn.decomposition
.Part 2 of #11074, please see the parent PR for additional information.