[python-dtcwt] 13/38: use tox for running tests

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Mar 8 11:39:18 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository python-dtcwt.

commit a1b8c6c353034eb4d6810bee079639a637310720
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date:   Tue Aug 4 14:25:45 2015 +0100

    use tox for running tests
    
    Modify the travis configuration to use tox and py.test for running the test
    suite. Modify those tests which need it to move away from using nose.
---
 .travis.yml                   | 23 +++++++++--------------
 pytest.ini                    |  3 +++
 tests/opencl-requirements.txt |  4 ++++
 tests/requirements.txt        |  3 +++
 tests/testagainstmatlab.py    |  4 +---
 tests/testcoeffs.py           | 18 +++++++++---------
 tests/testcoldfilt.py         | 14 +++++++-------
 tests/testcolifilt.py         | 14 +++++++-------
 tests/testifm1.py             |  5 +----
 tests/testifm2.py             |  5 -----
 tests/testopenclcoldfilt.py   | 14 +++++++-------
 tests/testopenclcolifilt.py   | 14 +++++++-------
 tests/testopenclxfm2.py       | 10 +++-------
 tests/testswitchbackends.py   | 13 ++++++-------
 tests/testxfm1.py             | 14 +++-----------
 tests/testxfm2.py             |  9 +++------
 tests/testxfm3.py             |  2 --
 tests/util.py                 | 20 +++++++-------------
 tox.ini                       | 12 ++++++++++++
 19 files changed, 92 insertions(+), 109 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 35ecd6c..7ca197c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,23 +3,18 @@ cache:
     - apt
 before_install:
     - sudo apt-get update -qq
-    - sudo apt-get install fglrx opencl-headers
-python:
-    - "2.7"
-    - "3.3"
+    - sudo apt-get install -y fglrx opencl-headers
+    - sudo apt-get install -y python-numpy python3-numpy
 env:
-    - PIP_SPECIFIER=.[docs]
-    - PIP_SPECIFIER=.[opencl,docs]
+    - TOX_ENV=py34
+    - TOX_ENV=py27
+    - TOX_ENV=py34-opencl
+    - TOX_ENV=py27-opencl
 install:
-    - pip install --upgrade pip setuptools  # Upgrade pip and setuptools to get ones with `wheel` support
-    - pip install --no-use-wheel pytools # Work around broken pytools wheel on Py3
-    - pip install --no-use-wheel coveralls # For updating coverage info
-    - pip install --find-links http://wheels2.astropy.org/ --use-wheel numpy matplotlib ipython
-    - pip install -e $PIP_SPECIFIER
+    - pip install --upgrade pip
+    - pip install tox coveralls
 script:
-    - python setup.py nosetests
-    - python scripts/benchmark_opencl.py
-    - python setup.py build_sphinx
+    - tox -e $TOX_ENV
 after_success:
     - coveralls
 
diff --git a/pytest.ini b/pytest.ini
new file mode 100644
index 0000000..2c42164
--- /dev/null
+++ b/pytest.ini
@@ -0,0 +1,3 @@
+[pytest]
+python_files = test*
+
diff --git a/tests/opencl-requirements.txt b/tests/opencl-requirements.txt
new file mode 100644
index 0000000..98263b9
--- /dev/null
+++ b/tests/opencl-requirements.txt
@@ -0,0 +1,4 @@
+# OpenCL specific requirements
+mako
+pyopencl
+
diff --git a/tests/requirements.txt b/tests/requirements.txt
new file mode 100644
index 0000000..8c299f3
--- /dev/null
+++ b/tests/requirements.txt
@@ -0,0 +1,3 @@
+# Testing-specific packages
+pytest
+coverage
diff --git a/tests/testagainstmatlab.py b/tests/testagainstmatlab.py
index fd73a84..aa93077 100644
--- a/tests/testagainstmatlab.py
+++ b/tests/testagainstmatlab.py
@@ -1,6 +1,4 @@
 import os
-from nose.tools import raises
-from nose.plugins.attrib import attr
 
 import numpy as np
 
@@ -60,7 +58,7 @@ def setup():
 
     global verif
     verif = np.load(os.path.join(os.path.dirname(__file__), 'verification.npz'))
-    
+
 def test_lena_loaded():
     assert lena.shape == (512, 512)
     assert lena.min() >= 0
diff --git a/tests/testcoeffs.py b/tests/testcoeffs.py
index 186be3b..323b147 100644
--- a/tests/testcoeffs.py
+++ b/tests/testcoeffs.py
@@ -1,6 +1,6 @@
 from dtcwt.coeffs import biort, qshift
 
-from nose.tools import raises
+from pytest import raises
 
 def test_antonini():
     h0o, g0o, h1o, g1o = biort('antonini')
@@ -60,20 +60,20 @@ def test_qshift_d():
     for v in coeffs:
         assert v.shape[0] == 18
 
- at raises(IOError)
 def test_non_exist_biort():
-    biort('this-does-not-exist')
+    with raises(IOError):
+        biort('this-does-not-exist')
 
- at raises(IOError)
 def test_non_exist_qshift():
-    qshift('this-does-not-exist')
+    with raises(IOError):
+        qshift('this-does-not-exist')
 
- at raises(ValueError)
 def test_wrong_type_a():
-    biort('qshift_06')
+    with raises(ValueError):
+        biort('qshift_06')
 
- at raises(ValueError)
 def test_wrong_type_b():
-    qshift('antonini')
+    with raises(ValueError):
+        qshift('antonini')
 
 # vim:sw=4:sts=4:et
diff --git a/tests/testcoldfilt.py b/tests/testcoldfilt.py
index 3f5dd2d..b9bfe1f 100644
--- a/tests/testcoldfilt.py
+++ b/tests/testcoldfilt.py
@@ -3,7 +3,7 @@ import os
 import numpy as np
 from dtcwt.numpy.lowlevel import coldfilt
 
-from nose.tools import raises
+from pytest import raises
 
 import tests.datasets as datasets
 
@@ -17,17 +17,17 @@ def test_lena_loaded():
     assert lena.max() <= 1
     assert lena.dtype == np.float32
 
- at raises(ValueError)
 def test_odd_filter():
-    coldfilt(lena, (-1,2,-1), (-1,2,1))
+    with raises(ValueError):
+        coldfilt(lena, (-1,2,-1), (-1,2,1))
 
- at raises(ValueError)
 def test_different_size():
-    coldfilt(lena, (-0.5,-1,2,1,0.5), (-1,2,-1))
+    with raises(ValueError):
+        coldfilt(lena, (-0.5,-1,2,1,0.5), (-1,2,-1))
 
- at raises(ValueError)
 def test_bad_input_size():
-    coldfilt(lena[:511,:], (-1,1), (1,-1))
+    with raises(ValueError):
+        coldfilt(lena[:511,:], (-1,1), (1,-1))
 
 def test_good_input_size():
     coldfilt(lena[:,:511], (-1,1), (1,-1))
diff --git a/tests/testcolifilt.py b/tests/testcolifilt.py
index 7c0262e..a05accb 100644
--- a/tests/testcolifilt.py
+++ b/tests/testcolifilt.py
@@ -3,7 +3,7 @@ import os
 import numpy as np
 from dtcwt.numpy.lowlevel import colifilt
 
-from nose.tools import raises
+from pytest import raises
 
 import tests.datasets as datasets
 
@@ -17,21 +17,21 @@ def test_lena_loaded():
     assert lena.max() <= 1
     assert lena.dtype == np.float32
 
- at raises(ValueError)
 def test_odd_filter():
-    colifilt(lena, (-1,2,-1), (-1,2,1))
+    with raises(ValueError):
+        colifilt(lena, (-1,2,-1), (-1,2,1))
 
- at raises(ValueError)
 def test_different_size_h():
-    colifilt(lena, (-1,2,1), (-0.5,-1,2,-1,0.5))
+    with raises(ValueError):
+        colifilt(lena, (-1,2,1), (-0.5,-1,2,-1,0.5))
 
 def test_zero_input():
     Y = colifilt(np.zeros_like(lena), (-1,1), (1,-1))
     assert np.all(Y[:0] == 0)
 
- at raises(ValueError)
 def test_bad_input_size():
-    colifilt(lena[:511,:], (-1,1), (1,-1))
+    with raises(ValueError):
+        colifilt(lena[:511,:], (-1,1), (1,-1))
 
 def test_good_input_size():
     colifilt(lena[:,:511], (-1,1), (1,-1))
diff --git a/tests/testifm1.py b/tests/testifm1.py
index 0e10d1d..a4c525e 100644
--- a/tests/testifm1.py
+++ b/tests/testifm1.py
@@ -1,13 +1,11 @@
 import os
-from nose.tools import raises
-from nose.plugins.attrib import attr
+from pytest import raises
 
 import numpy as np
 from dtcwt.compat import dtwavexfm, dtwaveifm
 
 TOLERANCE = 1e-12
 
- at attr('transform')
 def test_reconstruct():
     # Reconstruction up to tolerance
     vec = np.random.rand(630)
@@ -15,7 +13,6 @@ def test_reconstruct():
     vec_recon = dtwaveifm(Yl, Yh)
     assert np.all(np.abs(vec_recon - vec) < TOLERANCE)
 
- at attr('transform')
 def test_reconstruct_2d():
     # Reconstruction up to tolerance
     vec = np.random.rand(630, 20)
diff --git a/tests/testifm2.py b/tests/testifm2.py
index 7232fc5..2e3ca5c 100644
--- a/tests/testifm2.py
+++ b/tests/testifm2.py
@@ -1,6 +1,4 @@
 import os
-from nose.tools import raises
-from nose.plugins.attrib import attr
 
 import numpy as np
 from dtcwt.compat import dtwavexfm2, dtwaveifm2
@@ -20,21 +18,18 @@ def test_lena_loaded():
     assert lena.max() <= 1
     assert lena.dtype == np.float64
 
- at attr('transform')
 def test_reconstruct():
     # Reconstruction up to tolerance
     Yl, Yh = dtwavexfm2(lena)
     lena_recon = dtwaveifm2(Yl, Yh)
     assert np.all(np.abs(lena_recon - lena) < TOLERANCE)
 
- at attr('transform')
 def test_reconstruct_crop():
     # Reconstruction up to tolerance
     Yl_crop, Yh_crop = dtwavexfm2(lena_crop)
     lena_recon = dtwaveifm2(Yl_crop, Yh_crop)[:lena_crop.shape[0], :lena_crop.shape[1]]
     assert np.all(np.abs(lena_recon - lena_crop) < TOLERANCE)
 
- at attr('transform')
 def test_reconstruct_custom_filter():
     # Reconstruction up to tolerance
     Yl, Yh = dtwavexfm2(lena, 4, biort('legall'), qshift('qshift_06'))
diff --git a/tests/testopenclcoldfilt.py b/tests/testopenclcoldfilt.py
index f303f98..6b8603a 100644
--- a/tests/testopenclcoldfilt.py
+++ b/tests/testopenclcoldfilt.py
@@ -5,7 +5,7 @@ from dtcwt.numpy.lowlevel import coldfilt as coldfilt_gold
 from dtcwt.opencl.lowlevel import coldfilt, NoCLPresentError
 from dtcwt.coeffs import biort, qshift
 
-from nose.tools import raises
+from pytest import raises
 
 from .util import assert_almost_equal, skip_if_no_cl
 import tests.datasets as datasets
@@ -20,20 +20,20 @@ def test_lena_loaded():
     assert lena.max() <= 1
     assert lena.dtype == np.float32
 
- at raises(ValueError)
 @skip_if_no_cl
 def test_odd_filter():
-    coldfilt(lena, (-1,2,-1), (-1,2,1))
+    with raises(ValueError):
+        coldfilt(lena, (-1,2,-1), (-1,2,1))
 
- at raises(ValueError)
 @skip_if_no_cl
 def test_different_size():
-    coldfilt(lena, (-0.5,-1,2,1,0.5), (-1,2,-1))
+    with raises(ValueError):
+        coldfilt(lena, (-0.5,-1,2,1,0.5), (-1,2,-1))
 
- at raises(ValueError)
 @skip_if_no_cl
 def test_bad_input_size():
-    coldfilt(lena[:511,:], (-1,1), (1,-1))
+    with raises(ValueError):
+        coldfilt(lena[:511,:], (-1,1), (1,-1))
 
 @skip_if_no_cl
 def test_real_wavelet():
diff --git a/tests/testopenclcolifilt.py b/tests/testopenclcolifilt.py
index 0abf8c9..7c0ab74 100644
--- a/tests/testopenclcolifilt.py
+++ b/tests/testopenclcolifilt.py
@@ -5,7 +5,7 @@ from dtcwt.opencl.lowlevel import colifilt
 from dtcwt.numpy.lowlevel import colifilt as colifilt_gold
 from dtcwt.coeffs import biort, qshift
 
-from nose.tools import raises
+from pytest import raises
 
 from .util import assert_almost_equal, skip_if_no_cl
 import tests.datasets as datasets
@@ -21,14 +21,14 @@ def test_lena_loaded():
     assert lena.dtype == np.float32
 
 @skip_if_no_cl
- at raises(ValueError)
 def test_odd_filter():
-    colifilt(lena, (-1,2,-1), (-1,2,1))
+    with raises(ValueError):
+        colifilt(lena, (-1,2,-1), (-1,2,1))
 
 @skip_if_no_cl
- at raises(ValueError)
 def test_different_size_h():
-    colifilt(lena, (-1,2,1), (-0.5,-1,2,-1,0.5))
+    with raises(ValueError):
+        colifilt(lena, (-1,2,1), (-0.5,-1,2,-1,0.5))
 
 @skip_if_no_cl
 def test_zero_input():
@@ -36,9 +36,9 @@ def test_zero_input():
     assert np.all(Y[:0] == 0)
 
 @skip_if_no_cl
- at raises(ValueError)
 def test_bad_input_size():
-    colifilt(lena[:511,:], (-1,1), (1,-1))
+    with raises(ValueError):
+        colifilt(lena[:511,:], (-1,1), (1,-1))
 
 @skip_if_no_cl
 def test_good_input_size():
diff --git a/tests/testopenclxfm2.py b/tests/testopenclxfm2.py
index 58263b1..43a4c28 100644
--- a/tests/testopenclxfm2.py
+++ b/tests/testopenclxfm2.py
@@ -1,6 +1,5 @@
 import os
-from nose.tools import raises
-from nose.plugins.attrib import attr
+from pytest import raises
 
 import numpy as np
 from dtcwt.coeffs import biort, qshift
@@ -31,12 +30,10 @@ def _compare_transforms(A, B):
         assert_almost_equal(x, y, tolerance=GOLD_TOLERANCE)
 
 @skip_if_no_cl
- at attr('transform')
 def test_simple():
     _compare_transforms(dtwavexfm2_np(lena), dtwavexfm2_cl(lena))
 
 @skip_if_no_cl
- at attr('transform')
 def test_specific_wavelet():
     a = dtwavexfm2_np(lena, biort=biort('antonini'), qshift=qshift('qshift_06'))
     b = dtwavexfm2_cl(lena, biort=biort('antonini'), qshift=qshift('qshift_06'))
@@ -49,9 +46,9 @@ def test_1d():
     _compare_transforms(a, b)
 
 @skip_if_no_cl
- at raises(ValueError)
 def test_3d():
-    Yl, Yh = dtwavexfm2_cl(np.dstack((lena, lena)))
+    with raises(ValueError):
+        Yl, Yh = dtwavexfm2_cl(np.dstack((lena, lena)))
 
 @skip_if_no_cl
 def test_simple_w_scale():
@@ -87,7 +84,6 @@ def test_0_levels():
     _compare_transforms(a, b)
 
 @skip_if_no_cl
- at attr('transform')
 def test_modified():
     a = dtwavexfm2_np(lena, biort=biort('near_sym_b_bp'), qshift=qshift('qshift_b_bp'))
     b = dtwavexfm2_cl(lena, biort=biort('near_sym_b_bp'), qshift=qshift('qshift_b_bp'))
diff --git a/tests/testswitchbackends.py b/tests/testswitchbackends.py
index 72c558f..8886ef0 100644
--- a/tests/testswitchbackends.py
+++ b/tests/testswitchbackends.py
@@ -3,7 +3,7 @@ import dtcwt.numpy as npbackend
 import dtcwt.opencl as clbackend
 
 from unittest import TestCase
-from nose.tools import raises, assert_raises
+from pytest import raises
 from .util import skip_if_no_cl
 
 class TestSwitchBackends(TestCase):
@@ -55,13 +55,13 @@ class TestSwitchBackends(TestCase):
         assert dtcwt.Pyramid is npbackend.Pyramid
         assert dtcwt.backend_name == 'numpy'
 
-    @raises(ValueError)
     def test_switch_to_invalid(self):
-        dtcwt.push_backend('does-not-exist')
+        with raises(ValueError):
+            dtcwt.push_backend('does-not-exist')
 
-    @raises(IndexError)
     def test_no_pop_default_backend(self):
-        dtcwt.pop_backend()
+        with raises(IndexError):
+            dtcwt.pop_backend()
 
 def test_backend_with_guard():
     """Test that manipulating the stack with preserve_backend_stack() will
@@ -83,12 +83,11 @@ def test_backend_with_guard_and_exception():
     dtcwt.push_backend('numpy')
     assert len(dtcwt._BACKEND_STACK) == 2
     assert dtcwt.backend_name == 'numpy'
-    def tst():
+    with raises(RuntimeError):
         with dtcwt.preserve_backend_stack():
             dtcwt.push_backend('opencl')
             assert dtcwt.backend_name == 'opencl'
             assert len(dtcwt._BACKEND_STACK) == 3
             raise RuntimeError('test error')
-    assert_raises(RuntimeError, tst)
     assert dtcwt.backend_name == 'numpy'
     assert len(dtcwt._BACKEND_STACK) == 2
diff --git a/tests/testxfm1.py b/tests/testxfm1.py
index 0832186..3efb51a 100644
--- a/tests/testxfm1.py
+++ b/tests/testxfm1.py
@@ -1,6 +1,5 @@
 import os
-from nose.tools import raises
-from nose.plugins.attrib import attr
+from pytest import raises
 
 import numpy as np
 from dtcwt.compat import dtwavexfm, dtwaveifm
@@ -8,55 +7,48 @@ from dtcwt.coeffs import biort, qshift
 
 TOLERANCE = 1e-12
 
- at attr('transform')
 def test_simple():
     vec = np.random.rand(630)
     Yl, Yh = dtwavexfm(vec, 3)
     assert len(Yh) == 3
 
- at attr('transform')
 def test_simple_with_no_levels():
     vec = np.random.rand(630)
     Yl, Yh = dtwavexfm(vec, 0)
     assert len(Yh) == 0
 
- at attr('transform')
 def test_simple_with_scale():
     vec = np.random.rand(630)
     Yl, Yh, Yscale = dtwavexfm(vec, 3, include_scale=True)
     assert len(Yh) == 3
     assert len(Yscale) == 3
 
- at attr('transform')
 def test_simple_with_scale_and_no_levels():
     vec = np.random.rand(630)
     Yl, Yh, Yscale = dtwavexfm(vec, 0, include_scale=True)
     assert len(Yh) == 0
     assert len(Yscale) == 0
 
- at attr('transform')
 def test_perfect_recon():
     vec = np.random.rand(630)
     Yl, Yh = dtwavexfm(vec)
     vec_recon = dtwaveifm(Yl, Yh)
     assert np.max(np.abs(vec_recon - vec)) < TOLERANCE
 
- at attr('transform')
 def test_simple_custom_filter():
     vec = np.random.rand(630)
     Yl, Yh = dtwavexfm(vec, 4, biort('legall'), qshift('qshift_06'))
     vec_recon = dtwaveifm(Yl, Yh, biort('legall'), qshift('qshift_06'))
     assert np.max(np.abs(vec_recon - vec)) < TOLERANCE
 
- at attr('transform')
 def test_single_level():
     vec = np.random.rand(630)
     Yl, Yh = dtwavexfm(vec, 1)
 
- at raises(ValueError)
 def test_non_multiple_of_two():
     vec = np.random.rand(631)
-    Yl, Yh = dtwavexfm(vec, 1)
+    with raises(ValueError):
+        Yl, Yh = dtwavexfm(vec, 1)
 
 def test_2d():
     Yl, Yh = dtwavexfm(np.random.rand(10,10))
diff --git a/tests/testxfm2.py b/tests/testxfm2.py
index b51918d..317f95a 100644
--- a/tests/testxfm2.py
+++ b/tests/testxfm2.py
@@ -1,6 +1,5 @@
 import os
-from nose.tools import raises
-from nose.plugins.attrib import attr
+from pytest import raises
 
 import numpy as np
 from dtcwt.compat import dtwavexfm2, dtwaveifm2
@@ -19,20 +18,18 @@ def test_lena_loaded():
     assert lena.max() <= 1
     assert lena.dtype == np.float32
 
- at attr('transform')
 def test_simple():
     Yl, Yh = dtwavexfm2(lena)
 
- at attr('transform')
 def test_specific_wavelet():
     Yl, Yh = dtwavexfm2(lena, biort=biort('antonini'), qshift=qshift('qshift_06'))
 
 def test_1d():
     Yl, Yh = dtwavexfm2(lena[0,:])
 
- at raises(ValueError)
 def test_3d():
-    Yl, Yh = dtwavexfm2(np.dstack((lena, lena)))
+    with raises(ValueError):
+        Yl, Yh = dtwavexfm2(np.dstack((lena, lena)))
 
 def test_simple_w_scale():
     Yl, Yh, Yscale = dtwavexfm2(lena, include_scale=True)
diff --git a/tests/testxfm3.py b/tests/testxfm3.py
index 850736b..e8d0b2e 100644
--- a/tests/testxfm3.py
+++ b/tests/testxfm3.py
@@ -1,6 +1,4 @@
 import os
-from nose.tools import raises
-from nose.plugins.attrib import attr
 
 import numpy as np
 from dtcwt.compat import dtwavexfm3, dtwaveifm3
diff --git a/tests/util.py b/tests/util.py
index 2456fe9..14bb01f 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -1,8 +1,8 @@
 import functools
 import numpy as np
+import pytest
 
-from nose import SkipTest
-from dtcwt.opencl.lowlevel import NoCLPresentError
+from dtcwt.opencl.lowlevel import _HAVE_CL as HAVE_CL
 
 from six.moves import xrange
 
@@ -44,7 +44,7 @@ def centre_indices(ndim=2,apron=8):
 def summarise_mat(M, apron=8):
     """HACK to provide a 'summary' matrix consisting of the corners of the
     matrix and summed versions of the sub matrices.
-    
+
     N.B. Keep this in sync with matlab/verif_m_to_npz.py.
 
     """
@@ -62,13 +62,7 @@ def summarise_cube(M, apron=4):
     """
     return np.dstack(
         [summarise_mat(M[:,:,i,...], apron) for i in xrange(M.shape[-2])]
-    )    
-
-def skip_if_no_cl(f):
-    @functools.wraps(f)
-    def wrapper(*args, **kwargs):
-        try:
-            return f(*args, **kwargs)
-        except NoCLPresentError:
-            raise SkipTest('Skipping due to no CL library being present')
-    return wrapper
+    )
+
+skip_if_no_cl = pytest.mark.skipif(not HAVE_CL, reason="OpenCL not present")
+
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..98ac935
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,12 @@
+[tox]
+envlist=py{27,34}{,-opencl}
+
+[testenv]
+deps=
+    -rtests/requirements.txt
+commands=
+    # We can't list these in deps since pyopencl moans if numpy is not
+    # fully installed at pip-install time.
+    py{27,34}-opencl: pip install -rtests/opencl-requirements.txt
+    py.test {posargs}
+sitepackages=True

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-dtcwt.git



More information about the debian-science-commits mailing list