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

Fix coverage drop in coordinates module #1441

Merged
merged 19 commits into from Jul 12, 2017

Conversation

utkbansal
Copy link
Member

Fixes #1433

Changes made in this Pull Request:

PR Checklist

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

@utkbansal utkbansal changed the title Fix coverage drop in coordinates module [WIP]Fix coverage drop in coordinates module Jun 27, 2017
@utkbansal
Copy link
Member Author

utkbansal commented Jun 27, 2017

With the last commit, I might have bloated the tests. I'll revisit that aspect later. I'm currently only focused on getting coverage back.

@richardjgowers
Copy link
Member

@utkbansal how do you mean bloated? Some unnecessary tests or just linecount?

@utkbansal
Copy link
Member Author

@richardjgowers In the terms of the number of lines. I should be able to make some fixtures global. Stuff like tempdir can be easily done. But I'll need to play around with scopes and see figure out the greatest scope I can use them in. But I think this work is better suited for Phase 2. Thoughst??

@richardjgowers
Copy link
Member

richardjgowers commented Jun 28, 2017 via email

@utkbansal
Copy link
Member Author

Woah! We actually crossed 90% in coverage!

@utkbansal
Copy link
Member Author

@kain88-de @richardjgowers A review at this point would be helpful. I'm mostly done porting the stuff. I now need to look for the tests that are missed out.

@utkbansal
Copy link
Member Author

I have restarted the build for the merge of 1414 - https://travis-ci.org/MDAnalysis/mdanalysis/builds/246515054

Want to see the drop in coverage caused by it. This PR + 1414 should ideally sum up to no drop in coverage.

with self.ref.writer(outfile, self.reader.n_atoms) as W:
for ts in self.reader:
def tmp_file(self, name, ref, tmpdir):
return tmpdir.name + name + '.' + ref.ext
Copy link
Member

Choose a reason for hiding this comment

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

this might need to be changed since tmpdir is a pytest internal fixture. @utkbansal do you know where tmpdirs are created here?

def reader(ref):
reader = ref.reader(ref.trajectory)
reader.add_auxiliary('lowf', ref.aux_lowf, dt=ref.aux_lowf_dt, initial_time=0, time_selector=None)
reader.add_auxiliary('highf', ref.aux_highf, dt=ref.aux_highf_dt, initial_time=0, time_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.

Can we find a solution that doesn't require us to repeat this for every child class of BaseReaderTests?

Copy link
Member

Choose a reason for hiding this comment

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

Can't this be defined in the base class?

def tmp_file(self, name, ref, tmpdir):
return tmpdir.name + name + '.' + ref.ext

def test_write_trajectory_timestep(self,ref, reader, tmpdir):
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused here. Is tmpdir here using the tmpdir-fixture of pytest? Because later you use tmpdir.name but the path.local variable that the tmpdir-fixture returns doesn't have a name attribute.

@staticmethod
@pytest.fixture()
def tmpdir():
return tempdir.TempDir()
Copy link
Member

Choose a reason for hiding this comment

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

Oh man overwriting the pytest tmpdir fixture isn't a good idea. rather call it tempdir to make it distinctively different. Also this fixture shouldn't be repeated for every class that inherits BaseTestWriter. Can't it be part of the base class?

Copy link
Member

Choose a reason for hiding this comment

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

I don't like that this is defined in the child class. This is common for all tests and should be defined in the base class. Similar to the universe fixtures above

Copy link
Member

Choose a reason for hiding this comment

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

Also the name is NOT OK. It overwrites a pytest fixture which can lead to confusion. See above comment for alternative name suggestions


@staticmethod
@pytest.fixture()
def u_no_resnames():
Copy link
Member

Choose a reason for hiding this comment

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

These Universe fixtures don't need to be defined in each format's tests, they're format agnostic. I would either, define them in the base class (BaseWriterTest?) or just call them in the test function. They're very light, so we're unlikely to have them has a large-scoped fixture.

@utkbansal
Copy link
Member Author

@richardjgowers @kain88-de Is there an easy way to compare two(or more coverage reports). Coveralls can do that but it doesn't work. I might have an idea why it doesn't work though, it would be great if we could fix it.

@kain88-de
Copy link
Member

@utkbansal any progress on this?

@utkbansal
Copy link
Member Author

utkbansal commented Jun 30, 2017 via email

@kain88-de kain88-de mentioned this pull request Jul 1, 2017
4 tasks
@utkbansal
Copy link
Member Author

utkbansal commented Jul 2, 2017

Missing test cases due to yield

  • test_dcd.py - Leaving this out because @kain88-de is already working on it.
  • test_reader_api.py
  • test_timestep_api.py

Other than tests in these files, all are executed.

@utkbansal
Copy link
Member Author

utkbansal commented Jul 2, 2017

@richardjgowers @kain88-de In test_timestep_api.py we have the following test class -

class TestBaseTimestep(BaseTimestepTest):
    @dec.skipif(parser_not_found('DCD'),
                'DCD parser not available. Are you using python 3?')
    def test_other_timestep(self):
        # use a subclass to base.Timestep to check it works
        ts1 = mda.coordinates.base.Timestep(10)
        ts1.positions = self._get_pos()

        # can't do TRR Timestep here as it always has vels and forces
        # so isn't actually equal to a position only timestep
        for otherTS in [mda.coordinates.DCD.Timestep,
                        mda.coordinates.TRJ.Timestep,
                        mda.coordinates.DMS.Timestep,
                        mda.coordinates.GRO.Timestep,
                        mda.coordinates.TRZ.Timestep,
                        ]:
            ts2 = otherTS(10)
            ts2.positions = self._get_pos()
            yield (self._check_ts_equal, ts1, ts2,
                   "Failed on {0}".format(otherTS))

If we change it to something like the following, the test will be executed.

class TestBaseTimestep(BaseTimestepTest):
    @dec.skipif(parser_not_found('DCD'),
                'DCD parser not available. Are you using python 3?')
    def test_other_timestep(self):
        # use a subclass to base.Timestep to check it works
        ts1 = mda.coordinates.base.Timestep(10)
        ts1.positions = self._get_pos()

        # can't do TRR Timestep here as it always has vels and forces
        # so isn't actually equal to a position only timestep
        for otherTS in [mda.coordinates.DCD.Timestep,
                        mda.coordinates.TRJ.Timestep,
                        mda.coordinates.DMS.Timestep,
                        mda.coordinates.GRO.Timestep,
                        mda.coordinates.TRZ.Timestep,
                        ]:
            ts2 = otherTS(10)
            ts2.positions = self._get_pos()


            ##### THIS IS THE CHANGE #######
            self._check_ts_equal( ts1, ts2,
                   "Failed on {0}".format(otherTS))

This is a band-aid fix for now. But I want to do this for now because the right way will casue a lot of changes - BaseTimestepTest inherits from TestCase, I need to get rid of TestCase and use fixtures. But then I will also have to modify all the other subclasses to use fixtures too.

def reader(ref):
reader = ref.reader(ref.trajectory)
reader.add_auxiliary('lowf', ref.aux_lowf, dt=ref.aux_lowf_dt, initial_time=0, time_selector=None)
reader.add_auxiliary('highf', ref.aux_highf, dt=ref.aux_highf_dt, initial_time=0, time_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.

Can't this be defined in the base class?

@staticmethod
@pytest.fixture()
def tmpdir():
return tempdir.TempDir()
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that this is defined in the child class. This is common for all tests and should be defined in the base class. Similar to the universe fixtures above

@staticmethod
@pytest.fixture()
def tmpdir():
return tempdir.TempDir()
Copy link
Member

Choose a reason for hiding this comment

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

Also the name is NOT OK. It overwrites a pytest fixture which can lead to confusion. See above comment for alternative name suggestions

@richardjgowers
Copy link
Member

@utkbansal with the band-aid above, why does that yield not work? Also, why can't we quickly put in the parametrize over classes?

@utkbansal
Copy link
Member Author

utkbansal commented Jul 2, 2017

@richardjgowers yield doesn't work if you have setUp in the class (see #1443 (comment)) and parameterize doesn't work if we inherit from TestCase (see #1443 (comment)).

To fix this properly I will have to get rid of TestCase inheritance (in BaseTimestepTest ) and then I wil have to update all the sublasses of BaseTimestepTest to use fixtures.
This can be, IMHO, done in the next phase.

@kain88-de
Copy link
Member

@utkbansal this is one of the last classes and the coordinates tests are already set to pytest. You might as well go full on at least for the BaseTimestepTest. I don't mind if this takes a bit longer. You can also start working on porting the analysis tests.

@utkbansal
Copy link
Member Author

@kain88-de Okay, I'll fix it completely then. I'm also starting analysis - it's the only module left.

@utkbansal
Copy link
Member Author

@richardjgowers @kain88-de I overestimated the amount of work needed to fix this. Apologies.

@utkbansal
Copy link
Member Author

@richardjgowers @kain88-de Should be better now.

@utkbansal utkbansal changed the title [WIP]Fix coverage drop in coordinates module Fix coverage drop in coordinates module Jul 2, 2017

def test_getitem(self):
assert_equal(self.ts[1], self.refpos[1])
# def setUp(self):
Copy link
Member

Choose a reason for hiding this comment

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

delete this


assert_raises(TypeError, sl)

def _check_getitem(self, sl):
res = [ts.frame for ts in self.reader[sl]]
@pytest.mark.parametrize('sl', [
Copy link
Member

Choose a reason for hiding this comment

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

why can't this use a double parametrize?

Copy link
Member Author

Choose a reason for hiding this comment

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

We should be able to do that.

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'm not really sure how I can do this.

Copy link
Member

Choose a reason for hiding this comment

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

@pytest.mark.parametrize('slice_cls', [list, np.array])
@pytest.mark.parametrize('sl', [])
def test_thing(self, slice_cls, sl):
    sl = slice_cls(sl)
    etc

Copy link
Member Author

@utkbansal utkbansal Jul 3, 2017

Choose a reason for hiding this comment

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

We want to turn res = [ts.frame for ts in reader[sl]] into a fixture, right? I am unable to access the reader fixture in the parametrize call.

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 think this has to do with static checking, If I define the fixture in the subclass itself, then I'm able to access it in the parameterize call.

@utkbansal
Copy link
Member Author

This PR is complete now, I think.

@kain88-de
Copy link
Member

@utkbansal you haven't updated the DCD tests. As I said DCD can now be updated as well since we merged the new DCD reader

@utkbansal
Copy link
Member Author

I think something is wrong with the precision in the DCD test. Can someone check?

@kain88-de
Copy link
Member

@utkbansal did you have a look at the difference in these tests between your branch and develop?

@orbeckst
Copy link
Member

I don't think that these failing tests should be using assert_equal when comparing floating point numbers. This should have been assert_almost_equal.

@@ -801,13 +801,13 @@ def test_time_with_offset(self):

assert_equal(ts.time, reftime + ref_offset)

def test_dt(self):
def test_dt(self, ref):
Copy link
Member

Choose a reason for hiding this comment

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

looks like it doesn't know what ref is. Also you forgot a test_dt in the other test class. Did you run those tests on your local laptop?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oddly enough the tests still fail. But if I directly change the files in where MD is installed (site-packages) then the same change works. Is there another build step I'm missing?!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed it.

@utkbansal
Copy link
Member Author

@kain88-de DCD works now.

@kain88-de kain88-de dismissed richardjgowers’s stale review July 12, 2017 05:25

Comments have been addressed

@kain88-de kain88-de merged commit 97526a5 into MDAnalysis:develop Jul 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants