Port core module to pytest#1443
Conversation
|
I hope this fixes it. |
|
I'm pretty sure there is something odd going on with |
|
@richardjgowers @kain88-de I think we have an issue here.
Source: https://docs.pytest.org/en/latest/nose.html#unsupported-idioms-known-issues |
|
Oh crap, Try running this But neither of the two methods are executed! They just show up as pass. I can confirm this because I've tried adding print statements/using the debugger, but its not executed. The only solution is to get rid of yeild based tests and use |
|
What's wrong with the following conversion to parameterize? I am getting an error |
|
Oh man, more mess. 😭
Edit |
|
@utkbansal we're moving away from |
|
@richardjgowers Yeah, I'm worried that this will take some additional time and will mess up with my timeline. Though I have to do this work anyway, but the time taken on Phase 1 gets extended. |
|
@utkbansal you might want to work on analysis then before you complete this. But yeah you have to do the work anyway. And since this is one of the last tests still on nose it isn't that bad. |
|
Also a quick hack would be def test_string_selections_py(self):
stuff = (('name NameABA or name NameACA or name NameADA', 'name NameABA NameACA NameADA'),
('type TypeE or type TypeD or type TypeB', 'type TypeE TypeD TypeB'),
('resname RsC or resname RsY', 'resname RsC RsY'),
('name NameAB* or name NameACC', 'name NameAB* NameACC'),
('(name NameABC or name NameABB) and (resname RsD or resname RsF)',
'name NameABC NameABB and resname RsD RsF'),
('segid SegA or segid SegC', 'segid SegA SegC'))
for ref, sel in stuff:
self._check_sels(ref, sel)I don't recommend it though because this has to be converted to proper pytests anyway. |
|
Update: |
|
@utkbansal use |
|
@utkbansal this should work. https://docs.pytest.org/en/latest/skipping.html#id1 |
| ('prop mass < 4.0 hello', universe), # unused token | ||
| ('prop mass > 10. and group this', universe), # missing group | ||
| ('prop mass > 10. and fullgroup this', universe), # missing fullgroup | ||
| ], indirect=['universe']) |
There was a problem hiding this comment.
what does the indirect= do? Is that documented somewhere?
|
See:
https://docs.pytest.org/en/latest/example/parametrize.html#apply-indirect-on-particular-arguments
…On Fri, Jun 30, 2017 at 3:03 PM, Max Linke ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In testsuite/MDAnalysisTests/core/test_atomselections.py
<#1443 (comment)>
:
> + ('resnum 7a7', universe), # rangeselection arg parsing
+ ('resid 1-', universe),
+ ('prop chicken == tasty', universe),
+ ('prop chicken <= 7.4', universe),
+ ('prop mass ^^ 12.0', universe),
+ ('same this as resid 1', universe), # same selection
+ ('same resid resname mass 5.0', universe), # same / expect
+ ('name H and', universe), # check all tokens used
+ ('naem H', universe), # unkonwn (misplet) opertaor
+ ('resid and name C', universe), # rangesel not finding vals
+ ('resnum ', universe),
+ ('bynum or protein', universe),
+ ('prop mass < 4.0 hello', universe), # unused token
+ ('prop mass > 10. and group this', universe), # missing group
+ ('prop mass > 10. and fullgroup this', universe), # missing fullgroup
+ ], indirect=['universe'])
what does the indirect= do? Is that documented somewhere?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1443 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AH9W-MVI3hel6o0uyh_Q0HgKl_qw8A9zks5sJMDcgaJpZM4OH_5a>
.
|
| ]: | ||
| yield self.selection_fail, selstr | ||
|
|
||
| @pytest.mark.parametrize('selstr, universe', [ |
There was a problem hiding this comment.
why is universe being parametrized here?
There was a problem hiding this comment.
Because the function doesn't get it directly from the fixture. Have a look at the link I posted above.
There was a problem hiding this comment.
Right, but why can't we just use the Universe fixture above? ie just
@parametrize('selstr', [etc etc])
def test(self, selstr, universe):There was a problem hiding this comment.
I tried that, it didn't work. I don't have a reason to why it didn't work. I'll try to look it up.
There was a problem hiding this comment.
The suggestion of @richardjgowers work for me locally
|
|
||
| def selection_fail(self, selstr): | ||
| assert_raises(SelectionError, self.u.select_atoms, | ||
| def selection_fail(self, selstr, universe): |
There was a problem hiding this comment.
now we're not using yield (and having to provide a function to call for each test), we can collapse these functions into the test function itself
| sel.format(typ=seltype)) | ||
|
|
||
| class TestICodeSelection(object): | ||
| @pytest.mark.parametrize('ref, sel, universe',[ |
There was a problem hiding this comment.
same as above, why is Universe in the parametrize?
|
The drop in coverage should be fixed now, hopefully. |
|
@richardjgowers @kain88-de I've got the coverage back to normal. Could you please review. Then I can do all the cleanup in one go. |
|
|
||
| def _check_around(self, meth, periodic): | ||
| sel = Parser.parse('around 5.0 resid 1', self.u.atoms) | ||
| @pytest.mark.parametrize('u, meth, periodic', [ |
There was a problem hiding this comment.
If you change the u fixture above to a staticmethod, you don't have to parametrize around it here.
ie
@staticmethod
@pytest.fixture
def u():
@pytest.mark.parametrize('meth, periodic', [])
def test_around(self, u, meth, periodic):will work
There was a problem hiding this comment.
Oh yes, when I was trying I had a dec.skipif and that doesn't work well with static methods. That's why I got different results.
richardjgowers
left a comment
There was a problem hiding this comment.
needs the indirects removing first
| ('improper', u) | ||
| ], indirect=['u']) | ||
| def test_VEs(self, btype, u): | ||
| self._check_VE(btype, u) |
There was a problem hiding this comment.
can you directly include the _check_VE function here.
| # 'prop mass > 10. and group this', # missing group | ||
| # 'prop mass > 10. and fullgroup this', # missing fullgroup | ||
| # ]: | ||
| # yield self.selection_fail, selstr |
There was a problem hiding this comment.
this should be removed before the final merge
| ]: | ||
| yield self.selection_fail, selstr | ||
|
|
||
| @pytest.mark.parametrize('selstr, universe', [ |
There was a problem hiding this comment.
The suggestion of @richardjgowers work for me locally
|
|
||
| def tearDown(self): | ||
| del self.u | ||
| @pytest.mark.skipif(parser_not_found('DCD'),'DCD parser not available. Are you using python 3?') |
There was a problem hiding this comment.
Can you double check that marking fixtures like this works? Ie does this mark then get transferred onto tests which use this fixture?
There was a problem hiding this comment.
On my local system, I only have the minimal dependencies, all the test methods are skipped.
There was a problem hiding this comment.
You run on python3? These tests will always run on Python 2
There was a problem hiding this comment.
That's odd. I'm python 2.
There was a problem hiding this comment.
dcd is available on python 2 as a parser. Those tests should run for you. But since we soon have a python3 DCD parser I'm not to worried if the tests are skipped but they should be run on phython2.
There was a problem hiding this comment.
This should work on Python 2
| @staticmethod | ||
| @pytest.fixture() | ||
| def u(self): | ||
| # TODO: This is dummy. Needs review! |
There was a problem hiding this comment.
Is this still Todo, or is it Todone?
There was a problem hiding this comment.
Now that we don't need to pass universe to the parametrize call, we can get rid of this completely.
|
@richardjgowers @kain88-de What else needs to be done? |
|
|
||
| def tearDown(self): | ||
| del self.u | ||
| @pytest.mark.skipif(parser_not_found('DCD'),'DCD parser not available. Are you using python 3?') |
| ('{typ} 1-5 or {typ} 7:10 or {typ} 12', '{typ} 1-5 7:10 12'), | ||
| ('{typ} 1 or {typ} 3 or {typ} 5:10', '{typ} 1 3 5:10'), | ||
| ]) | ||
| def test_range_selections(self, seltype, ref, sel, universe): |
There was a problem hiding this comment.
how many tests are generated for this? Does it equal the number of tests the old double loop used in nose?
There was a problem hiding this comment.
18 test cases are generated as expected.
|
@richardjgowers you should have a final look for the core module. |
|
Yep looks good |
Fixes #
Changes made in this Pull Request:
PR Checklist