Skip to content

Remove yield based tests#1642

Merged
kain88-de merged 3 commits intoMDAnalysis:developfrom
utkbansal:coord-base
Sep 4, 2017
Merged

Remove yield based tests#1642
kain88-de merged 3 commits intoMDAnalysis:developfrom
utkbansal:coord-base

Conversation

@utkbansal
Copy link
Copy Markdown
Member

Fixes #

Changes made in this Pull Request:

PR Checklist

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

@@ -0,0 +1,4 @@
import itertools
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if we keep reusing the pattern of itertools.product() it's probably better to define it as a generator outside the class

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I changed this to a fixture some_ts in the other occurrences. Here this isn't possible.

@orbeckst
Copy link
Copy Markdown
Member

@utkbansal remove the WIP from the title when you want reviews.

@utkbansal
Copy link
Copy Markdown
Member Author

Update: Need help with the five remaining yield occurrences. All of them are in BaseTimestepTest.

@orbeckst
Copy link
Copy Markdown
Member

orbeckst commented Sep 1, 2017

Can you paste the link to the specific code pieces (from the GitHub source).

@kain88-de
Copy link
Copy Markdown
Member

kain88-de commented Sep 3, 2017

Patch to remove remaining yield tests

EDIT force pushed changes

@kain88-de kain88-de force-pushed the coord-base branch 3 times, most recently from 8430b28 to 8ce5204 Compare September 3, 2017 20:50
ts = self._from_coords(p, v, f)
@pytest.fixture(params=filter(any,
itertools.product([True, False], repeat=3)))
def some_ts(self, request):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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, '')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should inline _check_ts_equal

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So you mean write directly

assert ts1 == ts2
assert ts2 == ts1

We 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, msg

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I can only see it used once? Either way yeah, let's split it out into an assert function

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sure, lets use filter then. It's just confusing to see two ways for this, implies that maybe there's a difference

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

changed.


def test_copy_slice_no_yield(self, some_ts):
ts = some_ts
self._check_copy(self.name, ts)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd rather all these method calls became separate tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why? Just for style reasons?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if one of the _check calls alters ts?

getattr(ts, 'forces')

def _empty_ts(self):
def check_ts(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this get detected by pytest? Shouldn't it start with test_

@richardjgowers richardjgowers self-assigned this Sep 4, 2017
@kain88-de kain88-de force-pushed the coord-base branch 2 times, most recently from a5906fa to 14ba61f Compare September 4, 2017 09:19
@kain88-de kain88-de changed the title [WIP]Remove yield based tests Remove yield based tests Sep 4, 2017
use fixture for timestep instead of parametrize
standalone function to replace _check_ts_equal
@kain88-de kain88-de merged commit b786cd3 into MDAnalysis:develop Sep 4, 2017
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.

4 participants