Repository navigation
[MRG+1] Pytest parametrization part2 - cluster, datasets and decomposition modules - #11142
Conversation
lesteve
left a comment
There was a problem hiding this comment.
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!
| _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.
Bonus points if you remove capitalization here and everywhere else since they are not globals anymore.
| delete=False) | ||
| sample_file.write(b("Hello World!\n")) | ||
| sample_file.close() | ||
| yield str(TEST_CATEGORY_DIR1) |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
right, I missed that, sorry ...
|
Thanks for the review @lesteve ! I responded to your comments above. |
|
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.