-
Notifications
You must be signed in to change notification settings - Fork 51
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
Use fixture for the test #278
Conversation
Codecov Report
@@ Coverage Diff @@
## master #278 +/- ##
=======================================
Coverage 98.69% 98.69%
=======================================
Files 26 26
Lines 1761 1763 +2
Branches 379 380 +1
=======================================
+ Hits 1738 1740 +2
Misses 3 3
Partials 20 20
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
What's the advantage of putting all fixtures into conftest?
Are we re-using fixtures across multiple test files?
Yes, almost all of the tests start from a pandas dataframe and they come from a parsing action, which is now dealt at fixture level. |
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.
Looks ok in principle, we can move the fixtures to conftest. The important change is using the request.getfixture().
I want to have a closer look after PR #254 is merged — there's a lot of noise in this PR.
Please resolve conflicts & then I'll have a final look. Thanks! |
fdf9e1c
to
06c1de0
Compare
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.
Looks ok. I have a few optional comments but no show-stoppers. Thank you for making some of the tests more efficient by re-using the new global fixtures.
In some cases, it might be a bit confusing when global fixtures with generic names such u_nk
and dHdl
are used. Previously it was clearer when these fixtures where local to the class or module and one could directly see their code. I'd either keep them local or make their names more explicit.
As a sidenote, it was difficult and time-consuming to review the PR with all the black code formatting changes. It would have been better if you had waited with the reformatting with PR #280.
Please squash-merge when you're happy with it.
src/alchemlyb/tests/test_units.py
Outdated
@pytest.fixture(scope='class') | ||
def dhdl(): | ||
dataset = load_benzene() | ||
dhdl = extract_dHdl(dataset['data']['Coulomb'][0], 310) | ||
return dhdl | ||
|
||
@staticmethod | ||
@pytest.fixture(scope='class') | ||
def u_nk(): | ||
dataset = load_benzene() | ||
u_nk = extract_u_nk(dataset['data']['Coulomb'][0], 310) | ||
return u_nk | ||
|
||
@pytest.mark.parametrize('func,fixture_in', | ||
[(dhdl2series, 'dhdl'), | ||
(u_nk2series, 'u_nk'), | ||
(decorrelate_u_nk, 'u_nk'), | ||
(decorrelate_dhdl, 'dhdl'), | ||
(slicing, 'dhdl'), | ||
(statistical_inefficiency, 'dhdl'), | ||
(equilibrium_detection, 'dhdl')]) |
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.
Putting these into conftest.py seems a bit messy because they are named so generically that it's not clear when you'd want to use them. With the code close by, it's a little bit clearer. Maybe if they were called gmx_dHdl
and gmx_u_nk
?
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 these are all mess made by black.
|
||
filenames = load_idws()['data']['forward'] | ||
filenames = load_idws()["data"]["forward"] |
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.
Maybe make load_idws a fixture, too, for consistency?
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, this is another black thing. Now I fixed the diff, you could see that these are all outdated.
"""Test that dHdl has the correct form when extracted from files. | ||
|
||
""" | ||
"""Test that dHdl has the correct form when extracted from files.""" | ||
dataset = load_benzene() |
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 test file has a lot of instances of dataset = load_something()
that could eventually be turned into fixtures. It makes no big difference for performance, I think, but it would make our approach more uniform.
@pytest.fixture
def gmx_benzene_data():
return gmx.load_benzene()
def test_dHdl(gmx_benzene_data):
...
However, no need to do it in this PR, just for the future.
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.
So the logic is that the conftest
will do and will only do the parsing, additional operations like concat
will be done at the local level. I have added the description to the top of conftest.
Please resolve conflicts (after PR #280) |
996d508
to
e950af2
Compare
Sorry about all the black fuss. I thought blackfy this PR would make the diff it more clear but it seems that it has been made noisier.
So the logic is that at
Sorry for the confusion, I guess I made a mess of the black thing but the diff should be clear now. |
Oh, I didn't pick up on any local renaming. That's a reasonable approach. |
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, now that I can see how you use the global fixtures, it makes sense and leads to cleaner tests. Well done.
I am going to merge it and if there's anything else we can do it in a later PR. |
Bonus: a net loss of almost 100 lines of code 👍 |
Fix #206 Merge after #254
This PR makes all the parsing for the tests done at the fixture level.
I have not touched the parsing part as the test itself is to check the parsing.
I have also not touched the ABFE part as I want to refactor the test a bit in another PR, where I might remove or change some of the tests. This PR didn't change the tests only had them load data from the fixture