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
Port analysis module to pytest #1450
Changes from 18 commits
f0a8204
3b4841b
60cb030
c773c0f
ed4c80a
c1e7cf2
2deec4e
c9f2038
a7f050e
f3946f3
80c4cba
0b5aced
e025e63
1f0d2f9
123139f
17a9a47
ebc342e
fd129d6
5f6de0e
f51f49a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,9 @@ env: | |
- PYTHON_VERSION=2.7 | ||
- COVERALLS=false | ||
- NOSE_FLAGS="--processes=2 --process-timeout=400 --no-open-files --with-timer --timer-top-n 50" | ||
- NOSE_TEST_LIST="analysis" | ||
- NOSE_TEST_LIST="" | ||
- PYTEST_FLAGS="--disable-pytest-warnings -n 2" | ||
- PYTEST_LIST="testsuite/MDAnalysisTests/lib testsuite/MDAnalysisTests/formats testsuite/MDAnalysisTests/coordinates testsuite/MDAnalysisTests/utils testsuite/MDAnalysisTests/topology testsuite/MDAnalysisTests/auxiliary testsuite/MDAnalysisTests/core" | ||
- PYTEST_LIST="testsuite/MDAnalysisTests/lib testsuite/MDAnalysisTests/formats testsuite/MDAnalysisTests/coordinates testsuite/MDAnalysisTests/utils testsuite/MDAnalysisTests/topology testsuite/MDAnalysisTests/auxiliary testsuite/MDAnalysisTests/core testsuite/MDAnalysisTests/analysis" | ||
- NOSE_COVERAGE_FILE="nose_coverage" | ||
- PYTEST_COVERAGE_FILE="pytest_coverage" | ||
- MAIN_CMD="pytest ${PYTEST_LIST} ${PYTEST_FLAGS}; python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST} ${NOSE_FLAGS}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @orbeckst. With |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,8 @@ | |
warnings.simplefilter('always') | ||
|
||
|
||
class TestRotationMatrix(object): | ||
def __init__(self): | ||
class TestRotationMatrix(TestCase): | ||
def setUp(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @utkbansal I assume the goal of this PR is to make it run under pytest and then you will do a second round adapting it to pytest style? Is this correct? (Would be fine with me.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that idea is correct |
||
self.a = np.array([[0.1, 0.2, 0.3], | ||
[1.1, 1.1, 1.1]]) | ||
self.b = np.array([[0.1, 0.1, 0.1], | ||
|
@@ -297,7 +297,7 @@ def test_alignto_partial_universe(): | |
|
||
|
||
|
||
class TestAlignmentProcessing(object): | ||
class TestAlignmentProcessing(TestCase): | ||
def setUp(self): | ||
self.seq = FASTA | ||
self.tempdir = tempdir.TempDir() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import sys | ||
import warnings | ||
|
||
import pytest | ||
from numpy.testing import (TestCase, dec, assert_equal, assert_almost_equal, | ||
assert_warns) | ||
|
||
|
@@ -826,20 +827,22 @@ def test_get_distance_matrix(self): | |
dm = confdistmatrix.get_distance_matrix(u) | ||
|
||
class TestEncoreImportWarnings(object): | ||
def setUp(self): | ||
# clear cache of encore module | ||
@block_import('sklearn') | ||
def _check_sklearn_import_warns(self, package, recwarn): | ||
for mod in list(sys.modules): # list as we're changing as we iterate | ||
if 'encore' in mod: | ||
sys.modules.pop(mod, None) | ||
|
||
@block_import('sklearn') | ||
def _check_sklearn_import_warns(self, package): | ||
warnings.simplefilter('always') | ||
assert_warns(ImportWarning, importlib.import_module, package) | ||
# assert_warns(ImportWarning, importlib.import_module, package) | ||
importlib.import_module(package) | ||
assert recwarn.pop(ImportWarning) | ||
|
||
def test_import_warnings(self): | ||
def test_import_warnings(self, recwarn): | ||
for mod in list(sys.modules): # list as we're changing as we iterate | ||
if 'encore' in mod: | ||
sys.modules.pop(mod, None) | ||
for pkg in ( | ||
'MDAnalysis.analysis.encore.dimensionality_reduction.DimensionalityReductionMethod', | ||
'MDAnalysis.analysis.encore.clustering.ClusteringMethod', | ||
): | ||
yield self._check_sklearn_import_warns, pkg | ||
self._check_sklearn_import_warns(pkg, recwarn) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes the behaviour of the test. Instead of having 2 tests that can fail individually, there is only one test that has two consecutive asserts. It is fine for now, but please add a comment as it may be forgotten when you will move to proper pytest idioms. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment is still missing here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment is bellow. I missed it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
# | ||
from __future__ import print_function, absolute_import | ||
|
||
from unittest import TestCase | ||
|
||
import MDAnalysis | ||
import MDAnalysis.analysis.hbonds | ||
from MDAnalysis import SelectionError, SelectionWarning | ||
|
@@ -46,7 +48,7 @@ def guess_types(names): | |
return Atomtypes(np.array([guess_atom_type(name) for name in names], dtype=object)) | ||
|
||
|
||
class TestHydrogenBondAnalysis(object): | ||
class TestHydrogenBondAnalysis(TestCase): | ||
def setUp(self): | ||
self.universe = u = MDAnalysis.Universe(PDB_helix) | ||
self.kwargs = { | ||
|
@@ -239,7 +241,7 @@ def run_HBA_dynamic_selections(*args): | |
self._tearDown() | ||
|
||
|
||
class TestHydrogenBondAnalysisTIP3P(object): | ||
class TestHydrogenBondAnalysisTIP3P(TestCase): | ||
@dec.skipif(parser_not_found('DCD'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove DCD skipif There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. separate PR, as @kain88-de says |
||
'DCD parser not available. Are you using python 3?') | ||
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.
also remove
nose
frompackage/setup.py
andtestsuite/setup.py
— yay, major step forward in your project: getting rid ofnose
.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.
And remove
testsuite/mda_nosetests.py
.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.
@mnmelo @jbarnoud @kain88-de @richardjgowers : should the nose-specific plugins also be removed at this time? We have to recreate the plugins for pytest or replace with native pytest plugins anyway,
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.
@orbeckst these changes should be in a separate PR. The plugins can pretty much all go. There is the openfile plugin but otherwise pytest comes with better alternatives