Pytest Style: test_modelling.py#1468
Conversation
orbeckst
left a comment
There was a problem hiding this comment.
lgtm ... but perhaps @jbarnoud or @kain88-de should have a quick look, too.
| @@ -266,9 +264,9 @@ def test_merge_with_topology_from_different_universes(self): | |||
| assert_(not hasattr(u3.atoms, 'dihedrals') or len(u3.atoms.bonds) == 0) | |||
| assert_(not hasattr(u3.atoms, 'impropers') or len(u3.atoms.bonds) == 0) | |||
There was a problem hiding this comment.
these asserts should be replaced
There was a problem hiding this comment.
all of them in the whole file.
| a = AtomGroup([], u) | ||
| b = AtomGroup([], u) | ||
|
|
||
| assert_raises(ValueError, Merge, a, b) |
There was a problem hiding this comment.
please use with pytest.raises
| @@ -215,30 +213,30 @@ def test_empty_ValueError(self): | |||
| def test_nonsense_TypeError(self): | |||
| assert_raises(TypeError, Merge, ['1', 2]) | |||
|
|
||
| def test_merge_same_universe(self): | ||
| u1, _, _ = self.universes | ||
| def test_merge_same_universe(self, universes): |
There was a problem hiding this comment.
only use u1 as a fixture here
| return [u1, u2, u3] | ||
|
|
||
| def test_merge(self, universes, tmpdir): | ||
| u1, u2, u3 = universes |
There was a problem hiding this comment.
please use the fixtures explicit instead of the universes collection
|
|
||
| @staticmethod | ||
| @pytest.fixture() | ||
| def u1(): |
There was a problem hiding this comment.
Since we're at it, could you rename u1, u2, and u3 to u_protein, u_ligand, and u_water, respectively. The current names are not informative, and there is no way anybody will remember which of u2 and u3 has the ligand.
|
|
||
| def test_residue_references(self): | ||
| u1, u2, u3 = self.universes | ||
| def test_residue_references(self, universes): |
There was a problem hiding this comment.
This test does not use u3. Pass u1 and u2 explicitly.
|
|
||
| def test_segment_references(self): | ||
| u1, u2, u3 = self.universes | ||
| def test_segment_references(self, universes): |
There was a problem hiding this comment.
Same as above. Pass u1 and u2 only.
| del self.u2 | ||
| @staticmethod | ||
| @pytest.fixture() | ||
| def u2(): |
There was a problem hiding this comment.
This is the same as TestCaping.u2. You can move TestCaping.u1, TestCaping.u2, and TestCaping.u3 in the module scope instead of the scope of the scope of the TestCaping class. Then you can use the same fixture thoughout the file and we know they correspind to the same things. Do not forget the renaming I asked above, though.
| def test_merge_with_topology_from_different_universes(self): | ||
| u3 = MDAnalysis.Merge(self.u.atoms[:110], self.u2.atoms) | ||
| def test_merge_with_topology_from_different_universes(self, u, u2): | ||
| u3 = MDAnalysis.Merge(u.atoms[:110], u2.atoms) |
There was a problem hiding this comment.
If u1 and u2 are moved and renamed, this cannot remain u3. Maybe u_merge?
There was a problem hiding this comment.
I think I haven't understood what you said here. Can you confirm the change I've done is the one you wanted.
There was a problem hiding this comment.
This variable was named u3 because the function was already using self.u and self.u2. Beside the fact that u3 is a terrible name for a variable in general, there is no u2 any more as one could expect from the name u3.
This variable cannot keep be called u3. I suggest renaming it u_merge. u2 in the test above and the test bellow could be renamed u_merge as well. This name makes it clear that they point to the universe produced by the merge.
|
|
||
| @staticmethod | ||
| @pytest.fixture() | ||
| def universes(u1, u2, u3): |
There was a problem hiding this comment.
As @kain88-de suggests, you should use the individual fixtures explicitly. You can remove this one.
| from MDAnalysisTests import parser_not_found, tempdir | ||
|
|
||
| from numpy.testing import (TestCase, dec, assert_equal, assert_raises, assert_, | ||
| from numpy.testing import (assert_equal, assert_raises, assert_, |
There was a problem hiding this comment.
Did you remove all assert_raises and assert_ from this file. Then they shouldn't be imported anymore
|
There is still #1468 (comment) to address, then it should be good to go. |
|
@jbarnoud Is it okay now? |
Fixes #
Changes made in this Pull Request:
PR Checklist