[MRG] Refactor test_func_inspect.py as per pytest design.#450
[MRG] Refactor test_func_inspect.py as per pytest design.#450lesteve merged 12 commits intojoblib:masterfrom
Conversation
|
@lesteve It is WIP but since the diff is small, it might be easier for review, feel free to review it whenever you wish. 😄 |
95e6adf to
2e86b6b
Compare
joblib/test/test_func_inspect.py
Outdated
| yield assert_equal, filter_args(i, [], (2, )), {'x': 2} | ||
| yield assert_equal, filter_args(f2, [], (), dict(x=1)), {'x': 1} | ||
| @parametrize(['funcname', 'args', 'filtered_args'], | ||
| [('f', [[], (1, )], {'x': 1, 'y': 0}), |
There was a problem hiding this comment.
Why not use functions in parametrize?
@parametrize(['func', 'args', 'filtered_args'],
[(f, [[], (1, )], {'x': 1, 'y': 0}),
...I guess the only good reason to use a fixture for funcs is actually the cached function f2, because it depends on tmpdir, right?
There was a problem hiding this comment.
Yes, because f2 depends on tmpdir. So would it be great if f2 is enclosed in a fixture while other functions just stay there in global scope ?
4dfa484 to
4b36e89
Compare
|
I am rolling back to old |
| @mem.cache | ||
| def g(x): | ||
| return x | ||
| pass |
There was a problem hiding this comment.
I interchanged names g and f2 just because f2 was the odd one out. Maybe it got missed out.
There was a problem hiding this comment.
Nope, this one is correct. Earlier it was:
def f2(x):
pass
@mem.cache
def g(x):
return xJust the names g and f2 were interchanged because f2 was the odd one out (decorated).
There was a problem hiding this comment.
I see. In general the less you change that is not directly related to the PR the easier it is to review. When you notice unrelated shortcomings/problems while working on a PR, it is a good habit to change them in separate PRs.
Since you are changing it anyway, can you use a better name than f2 then to make it clearer than it is a cached function? Maybe something like cached_func?
There was a problem hiding this comment.
Since you are changing it anyway, can you use a better name than f2 then to make it clearer than it is a cached function? Maybe something like cached_func?
I think this is the last thing remaining and then this will be good to merge.
There was a problem hiding this comment.
When you notice unrelated shortcomings/problems while working on a PR, it is a good habit to change them in separate PRs.
I agree with this fact.
Okay, I'll make it cached_func.
joblib/test/test_func_inspect.py
Outdated
| from joblib.memory import Memory | ||
| from joblib.test.common import with_numpy | ||
| from joblib.testing import assert_equal, assert_raises_regex, assert_raises | ||
| from joblib.testing import (fixture, parametrize, pytest_assert_raises) |
There was a problem hiding this comment.
You don't need the parentheses if the imports fit on one line
joblib/test/test_func_inspect.py
Outdated
| {'x': 1, 'y': 0, '*': [], '**': {}}), | ||
| (h, [[], (1, 2, 3, 4)], | ||
| {'x': 1, 'y': 2, '*': [3, 4], '**': {}}), | ||
| (h, [[], (1, 25), dict(ee=2)], |
There was a problem hiding this comment.
For consistency you may as well use {'ee': 2}. To be honest I am not sure why dict is used maybe some people find it more explicit.
If you do that do it everywhere in this file.
joblib/test/test_func_inspect.py
Outdated
| @fixture(scope='module') | ||
| def f2(tmpdir_factory): | ||
| """ | ||
| This fixture returns a dict of functions which are used as test cases |
|
|
||
|
|
||
| def test_func_name_on_inner_func(f2): | ||
| # Check that we are not confused by decoration |
There was a problem hiding this comment.
I don't understand why the "not confused" test was on g before and is on f2 now.
There was a problem hiding this comment.
g was decorated with @mem.cache earlier, and it was the only one function. All other functions - f, f2, h, i, j, k were normal ones. That seemed a bit off to me to I went ahead and made this change.
There was a problem hiding this comment.
I added this note in main PR description.
|
@lesteve All work done here I guess. New PR on the way once this is merged.. |
| def f2(tmpdir_factory): | ||
| # Create a Memory object to test decorated functions. | ||
| # We should be careful not to call the decorated functions, so that | ||
| # cache directories are not created in the temp dir. |
There was a problem hiding this comment.
I have to say I don't really understand this comment but it was there before ...
There was a problem hiding this comment.
Agreed. I did not alter it because it was there...
There was a problem hiding this comment.
I think I got it eventually: we should only use f2 for testing its signature. If you call it you will pollute the temporary cache directory. The fact that it is a fixture makes it even more complicated to understand the comment I think ...
I may clean this up a bit after this PR is merged.
joblib/test/test_func_inspect.py
Outdated
| ]) | ||
| def test_filter_args_error_msg(exception, regex, func, args): | ||
| """ | ||
| Make sure that filter_args returns decent error messages, for the sake |
There was a problem hiding this comment.
Was this docstring too long? It it was try to follow PEP0258. Short description one the first line and then a blank line and then long description.
There was a problem hiding this comment.
Oh okay I did not remember this PEP. I usually write them throughout the project in this manner so I wrote them here in this way unconsciously.. I'll rectify them in a jiffy.
There was a problem hiding this comment.
For the record, in general we try to follow the Numpy style for docstrings: see https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt.
There was a problem hiding this comment.
Okay, thanks for informing the style guidelines. Will be helpful ! (pins this link to browser ).
I modified the docstring..
| def test_format_signature(): | ||
| @parametrize(['func', 'args', 'kwargs', 'sgn_expected'], | ||
| [(g, [list(range(5))], {}, 'g([0, 1, 2, 3, 4])'), | ||
| (k, [1, 2, (3, 4)], {'y': True}, 'k(1, 2, (3, 4), y=True)')]) |
There was a problem hiding this comment.
Your changes are fine, but remember what I said above about not changing unrelated things if there is not a strong motivation behind it.
There was a problem hiding this comment.
It was just to keep things within 80 characters. I would remember about the fact, keeping in mind that there might be some piece of code which would be written a long time ago due to some reason. 😄
|
LGTM, merging, thanks a lot! |
|
Okay I'm leaving a long comment on the issue thread, please refer to it 😄 Here: #411 (comment) |
Third Phase PR on #411 (Succeeding PR #446)
This PR deals with refactor of tests in test_func_inspect.py to adopt the pytest flavor.
Prior to this PR, each method had several
yieldbased statements where the test cases comprised of a set of functions with args and kwargs as well. I have proposed afixturewhich returns a dictionary of functions to makeparametrizationeasier.with_numpydecorator is now apytest.skipifmarker [Commented for now, will be uncommented after test_hashing.py is pytestified. Because this skipif marker does not work well withyieldbased tests.]The function names
gandf2have been interchanged. Earliergwas decorated with@mem.cacheearlier, and it was the only one function. All other functions -f,f2,h,i,j,kwere normal undecorated ones. This name interchanging is simply a cosmetic change.