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
Conversation
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. |
@utkbansal how do you mean bloated? Some unnecessary tests or just linecount? |
@richardjgowers In the terms of the number of lines. I should be able to make some fixtures global. Stuff like |
Yeah don't worry about line counts for now
…On Wed, 28 Jun 2017, 7:41 a.m. Utkarsh Bansal, ***@***.***> wrote:
@richardjgowers <https://github.com/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??
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1441 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AI0jBzX2enarCYJh6BokSKboRk8vbd2Aks5sIfWZgaJpZM4OG8qd>
.
|
Woah! We actually crossed 90% in coverage! |
@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. |
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 |
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 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) |
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.
Can we find a solution that doesn't require us to repeat this for every child class of BaseReaderTests?
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.
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): |
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.
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() |
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.
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?
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.
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
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.
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(): |
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.
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.
@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. |
@utkbansal any progress on this? |
Not yet, It has the same yield problem which is causing the coverage to
drop. The problem is smaller in the core module, so I'm trying to fix that
first so that I'm more comfortable dealing with tricky cases here.
…On Fri, Jun 30, 2017 at 2:14 PM, Max Linke ***@***.***> wrote:
@utkbansal <https://github.com/utkbansal> any progress on this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1441 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AH9W-KiDX8BTW02w1bD25zriAA3NMDwCks5sJLVlgaJpZM4OG8qd>
.
|
Missing test cases due to
Other than tests in these files, all are executed. |
@richardjgowers @kain88-de In 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 - |
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) |
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.
Can't this be defined in the base class?
@staticmethod | ||
@pytest.fixture() | ||
def tmpdir(): | ||
return tempdir.TempDir() |
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.
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() |
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.
Also the name is NOT OK. It overwrites a pytest fixture which can lead to confusion. See above comment for alternative name suggestions
@utkbansal with the band-aid above, why does that |
@richardjgowers To fix this properly I will have to get rid of TestCase inheritance (in |
@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. |
@kain88-de Okay, I'll fix it completely then. I'm also starting |
@richardjgowers @kain88-de I overestimated the amount of work needed to fix this. Apologies. |
@richardjgowers @kain88-de Should be better now. |
|
||
def test_getitem(self): | ||
assert_equal(self.ts[1], self.refpos[1]) | ||
# def setUp(self): |
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.
delete this
|
||
assert_raises(TypeError, sl) | ||
|
||
def _check_getitem(self, sl): | ||
res = [ts.frame for ts in self.reader[sl]] | ||
@pytest.mark.parametrize('sl', [ |
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.
why can't this use a double parametrize?
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.
We should be able to do that.
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.
I'm not really sure how I can do this.
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.
@pytest.mark.parametrize('slice_cls', [list, np.array])
@pytest.mark.parametrize('sl', [])
def test_thing(self, slice_cls, sl):
sl = slice_cls(sl)
etc
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.
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.
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.
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.
This PR is complete now, I think. |
@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 |
I think something is wrong with the precision in the DCD test. Can someone check? |
@utkbansal did you have a look at the difference in these tests between your branch and develop? |
I don't think that these failing tests should be using |
@@ -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): |
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 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?
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.
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?!
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.
Fixed it.
@kain88-de DCD works now. |
Fixes #1433
Changes made in this Pull Request:
PR Checklist