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

Port auxiliary module to pytest #1439

Merged
merged 7 commits into from Jun 28, 2017

Conversation

utkbansal
Copy link
Member

Fixes #

Changes made in this Pull Request:

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@utkbansal
Copy link
Member Author

@kain88-de @richardjgowers Have a look at this.

@richardjgowers
Copy link
Member

@utkbansal it looks like you might have to turn BaseAuxReference into a fixture. Then the tests in BaseAuxReader should all be parametrised to use it, rather than referring to it through self.

I wouldn't blindly put everything from BaseAuxReference into the fixture though, there's a lot of junk in there that could get moved out, for example iter_list isn't actually reference data, and that could exist only in the test methods which use it.

@utkbansal
Copy link
Member Author

I'm guessing, the error is arising because setUp can't take arguments?!

@utkbansal
Copy link
Member Author

utkbansal commented Jun 27, 2017

@richardjgowers Okay, I'll try that.

Interesting to note that the minimal build exits once the pytest suite fails and it doesn't try to run the nose test suite. This is against our assumptions!

@@ -34,14 +37,17 @@ def test_get_bad_auxreader_format_raises_ValueError():
# should raise a ValueError when no AuxReaders with match the specified format
mda.auxiliary.core.get_auxreader_for(format='bad-format')

class BaseAuxReference(object):
class BaseAuxReference(TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this contains reference data. No need to declare it as a test class

@@ -33,8 +33,11 @@
from MDAnalysisTests.auxiliary.base import (BaseAuxReaderTest, BaseAuxReference)

class XVGReference(BaseAuxReference):
def __init__(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are normal classes.

@utkbansal
Copy link
Member Author

@kain88-de @richardjgowers I have made some progress. I still have 3 test cases failing. I'm looking into that. A quick review would be helpful. basically what I want to know is - if this the direction we want to proceed in?

@utkbansal
Copy link
Member Author

Got those errors, apparently having the scope set to module causes some problem. Maybe some methods are updating some attributes?

@richardjgowers
Copy link
Member

Don't worry about scope yet, that's an optimisation

@utkbansal
Copy link
Member Author

This should fix the drop in coverage. I still have to do some cleanup stuff.

@kain88-de
Copy link
Member

@utkbansal. There is a possible minimal fix in #1440. You can just take the code. No need for commit attribution. Choose better names though! Simply doing the init/setup in a different named method fixes everything. As long as coverage doesn't drop this is OK for now but should be fixed with a better solution long term.

@utkbansal
Copy link
Member Author

@kain88-de @richardjgowers All green and no drop in coverage! Have cleaned this up. Please review.

@utkbansal utkbansal changed the title [WIP]Port auxiliary module to pytest Port auxiliary module to pytest Jun 27, 2017
Copy link
Member

@richardjgowers richardjgowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

def test_changing_n_col_raises_ValueError(self):
@staticmethod
@pytest.fixture()
def ref():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when I define a global fixture ref in the same file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried making both of them global. 3 tests failed. So I switched back.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I now create a global fixture the tests will break?

def reader(ref):
return ref.reader(ref.testdata, initial_time=ref.initial_time,
dt=ref.dt, auxname=ref.name,
time_selector=None, data_selector=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

@utkbansal
Copy link
Member Author

@richardjgowers Should be ready to be merged now.

@utkbansal
Copy link
Member Author

utkbansal commented Jun 27, 2017

Can someone explain why test_xvg_bz2 function has the same name as another function just above it!? https://github.com/utkbansal/mdanalysis/blob/27a9cb2ed3a0ad34b19671c28522c6a4c7c4a365/testsuite/MDAnalysisTests/auxiliary/test_xvg.py#L132

Looks like a bug.

@utkbansal utkbansal changed the title Port auxiliary module to pytest [WIP]Port auxiliary module to pytest Jun 27, 2017
@kain88-de
Copy link
Member

Can someone explain why test_xvg_bz2 function has the same name as another function just above it!?

Looks like a mistake. You can rename the functions.


def test_xvg_bz2():
reader = mda.auxiliary.XVG.XVGReader(XVG_BZ2)
assert_array_equal(reader.read_all_times(), np.array([0., 50., 100.]))


def test_xvg_bz2():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you rename the function so that the test is run as well the PR is good to go.

@utkbansal utkbansal changed the title [WIP]Port auxiliary module to pytest Port auxiliary module to pytest Jun 28, 2017
@utkbansal
Copy link
Member Author

@richardjgowers @kain88-de Can be merged now!

@richardjgowers richardjgowers merged commit be8db1c into MDAnalysis:develop Jun 28, 2017
@richardjgowers
Copy link
Member

Another one down!

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.

None yet

3 participants