Skip to content

Commit fba80e2

Browse files
utkbansalrichardjgowers
authored andcommitted
Port lib/test_util.py to pytest (#1413)
1 parent e24da32 commit fba80e2

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

.travis.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ env:
2323
- PYTHON_VERSION=2.7
2424
- COVERALLS=false
2525
- NOSE_FLAGS="--processes=2 --process-timeout=400 --no-open-files --with-timer --timer-top-n 50"
26-
- NOSE_TEST_LIST1="analysis auxiliary coordinates core formats topology utils"
27-
- NOSE_TEST_LIST2="lib"
28-
- NOSE_COVERAGE1="coverage1"
29-
- NOSE_COVERAGE2="coverage2"
30-
- MAIN_CMD="python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST1} ${NOSE_FLAGS}; python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST2} ${NOSE_FLAGS}"
26+
- NOSE_TEST_LIST="analysis auxiliary coordinates core formats topology utils"
27+
- PYTEST_FLAGS="--disable-pytest-warnings"
28+
- PYTEST_LIST="testsuite/MDAnalysisTests/lib"
29+
- NOSE_COVERAGE_FILE="nose_coverage"
30+
- PYTEST_COVERAGE_FILE="pytest_coverage"
31+
- MAIN_CMD="pytest ${PYTEST_LIST} ${PYTEST_FLAGS}; python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST} ${NOSE_FLAGS}"
3132
- SETUP_CMD=""
3233
- BUILD_CMD="pip install -v package/ && pip install testsuite/"
33-
- CONDA_DEPENDENCIES="mmtf-python nose=1.3.7 mock six biopython networkx cython joblib nose-timer"
34-
- CONDA_ALL_DEPENDENCIES="mmtf-python nose=1.3.7 mock six biopython networkx cython joblib nose-timer matplotlib netcdf4 scikit-learn scipy seaborn coveralls clustalw=2.1"
34+
- CONDA_DEPENDENCIES="mmtf-python nose=1.3.7 mock six biopython networkx cython joblib nose-timer pytest=3.1.2 pytest-cov=2.5.1"
35+
- CONDA_ALL_DEPENDENCIES="mmtf-python nose=1.3.7 mock six biopython networkx cython joblib nose-timer matplotlib netcdf4 scikit-learn scipy seaborn coveralls clustalw=2.1 pytest=3.1.2 pytest-cov=2.5.1"
3536
# Install griddataformats from PIP so that scipy is only installed in the full build (#1147)
3637
- PIP_DEPENDENCIES='griddataformats'
3738
- CONDA_CHANNELS='biobuilds conda-forge'
@@ -47,7 +48,7 @@ matrix:
4748
env: NAME='minimal'
4849
PYTHON_VERSION=2.7
4950
MEMLEAK='--with-memleak'
50-
MAIN_CMD='python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST1} ${NOSE_FLAGS} ${MEMLEAK}; python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST2} ${NOSE_FLAGS} ${MEMLEAK}'
51+
MAIN_CMD='pytest ${PYTEST_LIST} ${PYTEST_FLAGS}; python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST} ${NOSE_FLAGS} ${MEMLEAK}'
5152

5253
- os: linux
5354
env: NAME="Doc"
@@ -66,8 +67,9 @@ matrix:
6667

6768
- os: linux
6869
env: NAME='full'
69-
COVERAGE='--with-coverage --cover-package MDAnalysis'
70-
MAIN_CMD='export COVERAGE_FILE=$NOSE_COVERAGE1; python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST1} ${NOSE_FLAGS} ${COVERAGE}; export COVERAGE_FILE=$NOSE_COVERAGE2; python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST2} ${NOSE_FLAGS} ${COVERAGE}'
70+
NOSE_COVERAGE='--with-coverage --cover-package MDAnalysis'
71+
PYTEST_COVERAGE='--cov=MDAnalysis'
72+
MAIN_CMD='export COVERAGE_FILE=$PYTEST_COVERAGE_FILE; pytest ${PYTEST_LIST} ${PYTEST_FLAGS} ${PYTEST_COVERAGE}; export COVERAGE_FILE=$NOSE_COVERAGE_FILE; python ./testsuite/MDAnalysisTests/mda_nosetests ${NOSE_TEST_LIST} ${NOSE_FLAGS} ${NOSE_COVERAGE}'
7173
CONDA_DEPENDENCIES=${CONDA_ALL_DEPENDENCIES}
7274
COVERALLS='true'
7375

@@ -108,7 +110,7 @@ script:
108110
after_success:
109111
- |
110112
if [[ $COVERALLS == 'true' ]]; then \
111-
coverage combine $NOSE_COVERAGE1 $NOSE_COVERAGE2; \
113+
coverage combine $NOSE_COVERAGE_FILE $PYTEST_COVERAGE_FILE; \
112114
coveralls; \
113115
fi
114116
# can't use test here since this leads to travis fails even though the build passes

testsuite/MDAnalysisTests/lib/test_util.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#
2222
from __future__ import absolute_import, division
2323

24+
from unittest import TestCase
25+
2426
from six.moves import range, StringIO
2527
import six
2628

@@ -124,7 +126,7 @@ def test_strings(self):
124126
assert_equal(util.iterable(u"unicode string"), False)
125127

126128

127-
class TestFilename(object):
129+
class TestFilename(TestCase):
128130
def setUp(self):
129131
self.root = "foo"
130132
self.filename = "foo.psf"
@@ -161,7 +163,7 @@ def testNamedStream(self):
161163
assert_equal(ns.name, self.filename2)
162164

163165

164-
class TestGeometryFunctions(object):
166+
class TestGeometryFunctions(TestCase):
165167
def setUp(self):
166168
self.e1 = np.array([1., 0, 0])
167169
self.e2 = np.array([0, 1., 0])
@@ -230,7 +232,7 @@ def testDihedral(self):
230232
cd = bc + self.e3
231233
assert_almost_equal(mdamath.dihedral(ab, bc, cd), -np.pi / 2)
232234

233-
class TestMakeWhole(object):
235+
class TestMakeWhole(TestCase):
234236
"""Set up a simple system:
235237
236238
+-----------+
@@ -442,7 +444,7 @@ def _fill_cache(self, name, value):
442444
self._cache[name] = value
443445

444446

445-
class TestCachedDecorator(object):
447+
class TestCachedDecorator(TestCase):
446448
def setUp(self):
447449
self.obj = Class_with_Caches()
448450

@@ -895,7 +897,7 @@ def test_blocks_of_VE(self):
895897
assert_raises(ValueError, util.blocks_of, arr, 2, 1)
896898

897899

898-
class TestNamespace(object):
900+
class TestNamespace(TestCase):
899901
def setUp(self):
900902
self.ns = util.Namespace()
901903

0 commit comments

Comments
 (0)