Skip to content

Commit

Permalink
Modernize the testing components
Browse files Browse the repository at this point in the history
The main switch is from nose to pytest for the test framework. In
addition the pep8 library is replaced with pycodestyle.
  • Loading branch information
ajdawson committed Oct 12, 2017
1 parent 1668267 commit ea0cdb5
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 261 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ dist
*.tmp*
.coverage
MANIFEST
.cache/
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sudo: false

env:
global:
- PACKAGES_STANDARD="setuptools numpy nose pep8 coverage"
- PACKAGES_STANDARD="setuptools numpy pytest pycodestyle"
matrix:
- NAME="Python 2.7 (standard)"
PYTHON_VERSION=2.7
Expand Down Expand Up @@ -59,7 +59,7 @@ script:
# installed package rather than the source:
- mkdir ../test_directory
- cd ../test_directory
- nosetests eofs --verbosity=2 --with-coverage --cover-package=eofs
- pytest -vrsx --pyargs eofs

notifications:
email: false
12 changes: 6 additions & 6 deletions doc/devguide/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The package comes with a comprehensive set of tests to make sure it is working c
The tests can be run against an installed version of `eofs` or against the current source tree.
Testing against the source tree is handy during development when quick iteration is required, but for most other cases testing against the installed version is more suitable.

Running the test suite requires nose_ and pep8_ to be installed.
Running the test suite requires pytest_ and pycodestyle_ to be installed.
The test suite will function as long as the minimum dependencies for the package are installed, but some tests will be skipped if they require optional dependencies that are not present.
To run the full test suite you need to have the optional dependencies `cdms2` (from UV-CDAT_), iris_, and xarray_ installed.

Expand All @@ -14,7 +14,7 @@ Testing against the current source tree

Testing the current source is straightforward, from the source directory run::

nosetests -sv
pytest

This will perform verbose testing of the current source tree and print a summary at the end.

Expand All @@ -27,16 +27,16 @@ First you need to install `eofs` into your current Python environment::
cd eofs/
python setup.py install

Then create a directory somewhere else without any Python code in it and run ``nosetests`` from there giving the package name ``eofs`` as a positional argument::
Then create a directory somewhere else without any Python code in it and run ``pytest`` from there::

mkdir $HOME/eofs-test-dir && cd $HOME/eofs-test-dir
nosetests -sv eofs
pytest --pyargs eofs

This will run the tests on the version of `eofs` you just installed.

.. _nose: https://nose.readthedocs.org/en/latest/
.. _pytest: https://docs.pytest.org/en/latest/

.. _pep8: https://pypi.python.org/pypi/pep8
.. _pycodestyle: https://pypi.python.org/pypi/pycodestyle

.. _UV-CDAT: http://uv-cdat.llnl.gov

Expand Down
14 changes: 8 additions & 6 deletions lib/eofs/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
# along with eofs. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function) # noqa

from nose.tools import assert_almost_equal, assert_true, assert_equal
import numpy as np
from numpy.testing.utils import assert_array_almost_equal
import numpy.ma as ma


np.seterr(all='ignore')
Expand Down Expand Up @@ -51,15 +50,18 @@ def assert_array_almost_equal(self, a, b):
comparison is made.
"""
assert_array_almost_equal(self._tomasked(a), self._tomasked(b))
assert ma.allclose(self._tomasked(a), self._tomasked(b))

def assert_almost_equal(self, a, b):
"""Assertion that two values compare almost equal."""
assert_almost_equal(self._tomasked(a), self._tomasked(b))
assert ma.allclose(self._tomasked(a), self._tomasked(b))

def assert_true(self, cond):
"""Assertion that a condition is True."""
assert_true(cond)
assert cond

def assert_equal(self, a, b, message=None):
assert_equal(a, b, message)
if message is not None:
assert a == b, message
else:
assert a == b
4 changes: 2 additions & 2 deletions lib/eofs/tests/test_coding_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import os

import pep8
import pycodestyle

import eofs
from eofs.tests import EofsTest
Expand All @@ -27,7 +27,7 @@
class TestCodingStandards(EofsTest):

def test_pep8(self):
pep8style = pep8.StyleGuide(quiet=False)
pep8style = pycodestyle.StyleGuide(quiet=False)
base_paths = [os.path.dirname(eofs.__file__)]
result = pep8style.check_files(base_paths)
self.assert_equal(result.total_errors, 0, "Found PEP8 style issues.")
Loading

0 comments on commit ea0cdb5

Please sign in to comment.