Skip to content
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

Merged
merged 25 commits into from
Dec 6, 2022
Merged

Conversation

xiki-tempula
Copy link
Collaborator

@xiki-tempula xiki-tempula commented Dec 4, 2022

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

@codecov
Copy link

codecov bot commented Dec 4, 2022

Codecov Report

Merging #278 (2809915) into master (0095be2) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           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           
Impacted Files Coverage Δ
src/alchemlyb/__init__.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@xiki-tempula xiki-tempula requested a review from orbeckst December 4, 2022 22:03
Copy link
Member

@orbeckst orbeckst left a 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?

environment.yml Outdated Show resolved Hide resolved
src/alchemlyb/tests/conftest.py Show resolved Hide resolved
src/alchemlyb/tests/test_fep_estimators.py Show resolved Hide resolved
@xiki-tempula
Copy link
Collaborator Author

@orbeckst

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.

@xiki-tempula xiki-tempula mentioned this pull request Dec 5, 2022
Copy link
Member

@orbeckst orbeckst left a 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.

@orbeckst
Copy link
Member

orbeckst commented Dec 6, 2022

Please resolve conflicts & then I'll have a final look. Thanks!

Copy link
Member

@orbeckst orbeckst left a 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/conftest.py Show resolved Hide resolved
src/alchemlyb/tests/conftest.py Show resolved Hide resolved
Comment on lines 132 to 152
@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')])
Copy link
Member

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?

Copy link
Collaborator Author

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"]
Copy link
Member

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?

Copy link
Collaborator Author

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()
Copy link
Member

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.

Copy link
Collaborator Author

@xiki-tempula xiki-tempula Dec 6, 2022

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.

@orbeckst
Copy link
Member

orbeckst commented Dec 6, 2022

Please resolve conflicts (after PR #280)

@xiki-tempula
Copy link
Collaborator Author

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.

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.

So the logic is that at conftest the fixture are all named in a descriptive format like gmx_water_particle_without_energy_dHdl, then locally, the fixture can be named as u_nk and dHdl to make the individual tests more clear.

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.

Sorry for the confusion, I guess I made a mess of the black thing but the diff should be clear now.

@orbeckst
Copy link
Member

orbeckst commented Dec 6, 2022

So the logic is that at conftest the fixture are all named in a descriptive format like gmx_water_particle_without_energy_dHdl, then locally, the fixture can be named as u_nk and dHdl to make the individual tests more clear.

Oh, I didn't pick up on any local renaming. That's a reasonable approach.

Copy link
Member

@orbeckst orbeckst left a 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.

@orbeckst orbeckst self-assigned this Dec 6, 2022
@orbeckst
Copy link
Member

orbeckst commented Dec 6, 2022

I am going to merge it and if there's anything else we can do it in a later PR.

@orbeckst orbeckst merged commit fc04c01 into alchemistry:master Dec 6, 2022
@orbeckst
Copy link
Member

orbeckst commented Dec 6, 2022

Bonus: a net loss of almost 100 lines of code 👍

@xiki-tempula xiki-tempula deleted the feat_fixture branch December 6, 2022 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TST] avoid evaluating data loader functions in parametrized tests at set-up time
2 participants