Remove yield based tests#1642
Conversation
| @@ -0,0 +1,4 @@ | |||
| import itertools | |||
There was a problem hiding this comment.
I think this file should not be in the commit.
| return ts | ||
|
|
||
| def _check_from_coordinates(self, p, v, f): | ||
| @pytest.mark.parametrize('p, v, f', |
There was a problem hiding this comment.
if we keep reusing the pattern of itertools.product() it's probably better to define it as a generator outside the class
There was a problem hiding this comment.
I changed this to a fixture some_ts in the other occurrences. Here this isn't possible.
|
@utkbansal remove the WIP from the title when you want reviews. |
|
Update: Need help with the five remaining |
|
Can you paste the link to the specific code pieces (from the GitHub source). |
|
Patch to remove remaining yield tests EDIT force pushed changes |
8430b28 to
8ce5204
Compare
8ce5204 to
e6c420b
Compare
| ts = self._from_coords(p, v, f) | ||
| @pytest.fixture(params=filter(any, | ||
| itertools.product([True, False], repeat=3))) | ||
| def some_ts(self, request): |
There was a problem hiding this comment.
I don't have a better name for this fixture. Also this can only be a function scope fixture.
| ts1.forces = self.reffor.copy() | ||
| ts2.forces = self.reffor.copy() | ||
|
|
||
| self._check_ts_equal(ts1, ts2, '') |
There was a problem hiding this comment.
Should inline _check_ts_equal
There was a problem hiding this comment.
So you mean write directly
assert ts1 == ts2
assert ts2 == ts1We use the function in two separate places and it does a nice assert that the equal is commutative. Maybe better we make it a stand alone function (not a class method) named assert_ts_equal
def assert_ts_equal(ts1, ts2, msg=''):
assert ts1 == ts2, msg
assert ts2 == ts1, msgThere was a problem hiding this comment.
I can only see it used once? Either way yeah, let's split it out into an assert function
There was a problem hiding this comment.
https://github.com/MDAnalysis/mdanalysis/search?q=_check_ts_equal&type=Code&utf8=%E2%9C%93
The other usage is in a different file. That makes it hard to see. I admit.
|
|
||
| def _check_bad_slice(self, p, v, f): | ||
| ts = self._from_coords(p, v, f) | ||
| @pytest.fixture(params=filter(any, |
There was a problem hiding this comment.
does this filter do the same as the other itertools.product call above? If so can we use just one way of doing this (don't care which)
There was a problem hiding this comment.
filter(any, itertools.product([True, False], repeat=3))is equivalent to
[pvf for pvf in itertools.product([True, False], repeat=3) if any(pvf)]I personally like the filter call here because it is the clearest to read with the indentations due to being a decorator argument. But the problem is that we can't use tuple unpacking like in the list-comprehension above. I found the tuple unpacking more readable in the above example so I left it.
So yeah they are slightly differently written but personally this gives the best readability in each case. I can unify it though if you like. What would you prefer the filter or list-comprehension?
There was a problem hiding this comment.
Sure, lets use filter then. It's just confusing to see two ways for this, implies that maybe there's a difference
|
|
||
| def test_copy_slice_no_yield(self, some_ts): | ||
| ts = some_ts | ||
| self._check_copy(self.name, ts) |
There was a problem hiding this comment.
I'd rather all these method calls became separate tests
There was a problem hiding this comment.
What if one of the _check calls alters ts?
| getattr(ts, 'forces') | ||
|
|
||
| def _empty_ts(self): | ||
| def check_ts(self): |
There was a problem hiding this comment.
Does this get detected by pytest? Shouldn't it start with test_
a5906fa to
14ba61f
Compare
use fixture for timestep instead of parametrize
standalone function to replace _check_ts_equal
6663762 to
bf6df36
Compare
Fixes #
Changes made in this Pull Request:
PR Checklist