From d8785459e645a4051ef557b10676ef8841d77db7 Mon Sep 17 00:00:00 2001 From: Jonas Adler Date: Wed, 27 Apr 2016 16:30:24 +0200 Subject: [PATCH] MAINT: changed several tests to use fixtures --- conftest.py | 21 +++ odl/util/testutils.py | 8 +- test/discr/lp_discr_test.py | 152 +++++------------- test/largescale/space/fn_base_slow_test.py | 68 +++++--- .../tomo/ray_transform_slow_test.py | 12 +- test/largescale/trafos/fourier_slow_test.py | 27 ++-- test/space/cu_ntuples_test.py | 54 +++---- test/space/ntuples_test.py | 55 +++++-- test/tomo/backends/astra_setup_test.py | 14 +- 9 files changed, 205 insertions(+), 206 deletions(-) diff --git a/conftest.py b/conftest.py index 8a8e295b26a..315d903a5f5 100644 --- a/conftest.py +++ b/conftest.py @@ -21,6 +21,8 @@ from future import standard_library standard_library.install_aliases() +import pytest +import odl from odl.space.cu_ntuples import CUDA_AVAILABLE from odl.trafos.wavelet import PYWAVELETS_AVAILABLE @@ -38,3 +40,22 @@ def pytest_addoption(parser): parser.addoption('--benchmark', action='store_true', help='Run benchmarks') + + +# reusable fixtures +ufunc_params = [ufunc for ufunc in odl.util.ufuncs.UFUNCS] +ufunc_ids = [' ufunc={} '.format(p[0]) for p in ufunc_params] + + +@pytest.fixture(scope="module", ids=ufunc_ids, params=ufunc_params) +def ufunc(request): + return request.param + + +reduction_params = [reduction for reduction in odl.util.ufuncs.REDUCTIONS] +reduction_ids = [' reduction={} '.format(p[0]) for p in reduction_params] + + +@pytest.fixture(scope="module", ids=reduction_ids, params=reduction_params) +def reduction(request): + return request.param diff --git a/odl/util/testutils.py b/odl/util/testutils.py index 402dbaef5bd..5e8892e3070 100644 --- a/odl/util/testutils.py +++ b/odl/util/testutils.py @@ -30,7 +30,7 @@ from time import time -__all__ = ('almost_equal', 'all_equal', 'all_almost_equal', +__all__ = ('almost_equal', 'all_equal', 'all_almost_equal', 'never_skip', 'skip_if_no_cuda', 'skip_if_no_pywavelets', 'skip_if_no_pyfftw', 'skip_if_no_largescale', 'Timer', 'timeit', 'ProgressBar', 'ProgressRange', @@ -185,6 +185,12 @@ def _pass(function): # Try catch in case user does not have pytest import pytest + # Used in lists where the elements should all be skipifs + never_skip = pytest.mark.skipif( + "False", + reason='Fill in, never skips' + ) + skip_if_no_cuda = pytest.mark.skipif( "not odl.CUDA_AVAILABLE", reason='CUDA not available' diff --git a/test/discr/lp_discr_test.py b/test/discr/lp_discr_test.py index f54cadaab60..e27cc0b8820 100644 --- a/test/discr/lp_discr_test.py +++ b/test/discr/lp_discr_test.py @@ -29,7 +29,7 @@ import odl from odl.discr.lp_discr import DiscreteLp from odl.util.testutils import (almost_equal, all_equal, all_almost_equal, - skip_if_no_cuda) + never_skip, skip_if_no_cuda) def _array(fn): @@ -66,14 +66,23 @@ def _vectors(fn, n=1): # Simply modify exp_params to modify the fixture exp_params = [2.0, 1.0, float('inf'), 0.5, 1.5] exp_ids = [' p = {} '.format(p) for p in exp_params] -exp_fixture = pytest.fixture(scope="module", ids=exp_ids, params=exp_params) -@exp_fixture +@pytest.fixture(scope="module", ids=exp_ids, params=exp_params) def exponent(request): return request.param +impl_params = [never_skip('numpy'), + skip_if_no_cuda('cuda')] +impl_ids = [' impl = {} '.format(p.args[1]) for p in impl_params] + + +@pytest.fixture(scope="module", ids=impl_ids, params=impl_params) +def impl(request): + return request.param + + def test_init(exponent): # Validate that the different init patterns work and do not crash. space = odl.FunctionSpace(odl.Interval(0, 1)) @@ -580,12 +589,24 @@ def test_astype(): assert cdiscr._real_space == rdiscr -def _impl_test_ufuncs(fn, name, n_args, n_out): +def test_ufunc(impl, ufunc): + space = odl.uniform_discr([0, 0], [1, 1], (2, 2), impl=impl) + name, n_args, n_out, _ = ufunc + if (np.issubsctype(space.dtype, np.floating) and + name in ['bitwise_and', + 'bitwise_or', + 'bitwise_xor', + 'invert', + 'left_shift', + 'right_shift']): + # Skip integer only methods if floating point type + return + # Get the ufunc from numpy as reference ufunc = getattr(np, name) # Create some data - data = _vectors(fn, n_args + n_out) + data = _vectors(space, n_args + n_out) in_arrays = data[:n_args] out_arrays = data[n_args:n_args + n_out] data_vector = data[n_args + n_out] @@ -604,10 +625,10 @@ def _impl_test_ufuncs(fn, name, n_args, n_out): # Test type of output if n_out == 1: - assert isinstance(odl_result, fn.element_type) + assert isinstance(odl_result, space.element_type) elif n_out > 1: for i in range(n_out): - assert isinstance(odl_result[i], fn.element_type) + assert isinstance(odl_result[i], space.element_type) # In place: np_result = ufunc(*(in_arrays + out_arrays)) @@ -630,29 +651,10 @@ def _impl_test_ufuncs(fn, name, n_args, n_out): # Test type of output if n_out == 1: - assert isinstance(odl_result, fn.element_type) + assert isinstance(odl_result, space.element_type) elif n_out > 1: for i in range(n_out): - assert isinstance(odl_result[i], fn.element_type) - - -impl_params = [('numpy',), skip_if_no_cuda(('cuda',))] - - -@pytest.mark.parametrize(('impl',), impl_params) -def test_ufuncs(impl): - space = odl.uniform_discr([0, 0], [1, 1], (2, 2), impl=impl) - for name, n_args, n_out, _ in odl.util.ufuncs.UFUNCS: - if (np.issubsctype(space.dtype, np.floating) and - name in ['bitwise_and', - 'bitwise_or', - 'bitwise_xor', - 'invert', - 'left_shift', - 'right_shift']): - # Skip integer only methods if floating point type - continue - _impl_test_ufuncs(space, name, n_args, n_out) + assert isinstance(odl_result[i], space.element_type) def test_real_imag(): @@ -707,25 +709,18 @@ def test_real_imag(): assert all_equal(x.real, [4, 5, 6, 7]) -def _impl_test_reduction(fn, name): +def test_reduction(impl, reduction): + space = odl.uniform_discr([0, 0], [1, 1], [2, 2], impl=impl) + + name, _ = reduction + ufunc = getattr(np, name) # Create some data - x_arr, x = _vectors(fn, 1) + x_arr, x = _vectors(space, 1) assert almost_equal(ufunc(x_arr), getattr(x.ufunc, name)()) -def test_reductions(): - spaces = [odl.uniform_discr([0, 0], [1, 1], [2, 2])] - - if odl.CUDA_AVAILABLE: - spaces += [odl.uniform_discr([0, 0], [1, 1], [2, 2], impl='cuda')] - - for fn in spaces: - for name, _ in odl.util.ufuncs.REDUCTIONS: - yield _impl_test_reduction, fn, name - - def test_norm_interval(exponent): # Test the function f(x) = x^2 on the interval (0, 1). Its # L^p-norm is (1 + 2*p)^(-1/p) for finite p and 1 for p=inf @@ -761,79 +756,18 @@ def test_norm_rectangle(exponent): assert almost_equal(discr_testfunc.norm(), true_norm, places=2) -def test_norm_rectangle_boundary(exponent): +def test_norm_rectangle_boundary(impl, exponent): # Check the constant function 1 in different situations regarding the # placement of the outermost grid points. - rect = odl.Rectangle([-1, -2], [1, 2]) - # Standard case - discr = odl.uniform_discr_fromspace(odl.FunctionSpace(rect), (4, 8), - exponent=exponent) if exponent == float('inf'): - assert discr.one().norm() == 1 - else: - assert almost_equal(discr.one().norm(), - (rect.volume) ** (1 / exponent)) - - # Nodes on the boundary (everywhere) - discr = odl.uniform_discr_fromspace( - odl.FunctionSpace(rect), (4, 8), exponent=exponent, - nodes_on_bdry=True) - - if exponent == float('inf'): - assert discr.one().norm() == 1 - else: - assert almost_equal(discr.one().norm(), - (rect.volume) ** (1 / exponent)) - - # Nodes on the boundary (selective) - discr = odl.uniform_discr_fromspace( - odl.FunctionSpace(rect), (4, 8), exponent=exponent, - nodes_on_bdry=((False, True), False)) - - if exponent == float('inf'): - assert discr.one().norm() == 1 - else: - assert almost_equal(discr.one().norm(), - (rect.volume) ** (1 / exponent)) - - discr = odl.uniform_discr_fromspace( - odl.FunctionSpace(rect), (4, 8), exponent=exponent, - nodes_on_bdry=(False, (True, False))) - - if exponent == float('inf'): - assert discr.one().norm() == 1 - else: - assert almost_equal(discr.one().norm(), - (rect.volume) ** (1 / exponent)) - - # Completely arbitrary boundary - grid = odl.RegularGrid([0, 0], [1, 1], (4, 4)) - part = odl.RectPartition(rect, grid) - weight = 1.0 if exponent == float('inf') else part.cell_volume - dspace = odl.Rn(part.size, exponent=exponent, weight=weight) - discr = DiscreteLp(odl.FunctionSpace(rect), part, dspace, - exponent=exponent) - - if exponent == float('inf'): - assert discr.one().norm() == 1 - else: - assert almost_equal(discr.one().norm(), - (rect.volume) ** (1 / exponent)) - + pytest.xfail('inf-norm not implemented in CUDA') -@skip_if_no_cuda -def test_norm_rectangle_boundary_cuda(exponent): - # Check the constant function 1 in different situations regarding the - # placement of the outermost grid points. rect = odl.Rectangle([-1, -2], [1, 2]) - if exponent == float('inf'): - pytest.xfail('inf-norm not implemented in CUDA') - # Standard case discr = odl.uniform_discr_fromspace(odl.FunctionSpace(rect), (4, 8), - exponent=exponent, impl='cuda') + impl=impl, exponent=exponent) if exponent == float('inf'): assert discr.one().norm() == 1 else: @@ -843,7 +777,7 @@ def test_norm_rectangle_boundary_cuda(exponent): # Nodes on the boundary (everywhere) discr = odl.uniform_discr_fromspace( odl.FunctionSpace(rect), (4, 8), exponent=exponent, - nodes_on_bdry=True, impl='cuda') + impl=impl, nodes_on_bdry=True) if exponent == float('inf'): assert discr.one().norm() == 1 @@ -854,7 +788,7 @@ def test_norm_rectangle_boundary_cuda(exponent): # Nodes on the boundary (selective) discr = odl.uniform_discr_fromspace( odl.FunctionSpace(rect), (4, 8), exponent=exponent, - nodes_on_bdry=((False, True), False), impl='cuda') + impl=impl, nodes_on_bdry=((False, True), False)) if exponent == float('inf'): assert discr.one().norm() == 1 @@ -864,7 +798,7 @@ def test_norm_rectangle_boundary_cuda(exponent): discr = odl.uniform_discr_fromspace( odl.FunctionSpace(rect), (4, 8), exponent=exponent, - nodes_on_bdry=(False, (True, False)), impl='cuda') + impl=impl, nodes_on_bdry=(False, (True, False))) if exponent == float('inf'): assert discr.one().norm() == 1 @@ -878,7 +812,7 @@ def test_norm_rectangle_boundary_cuda(exponent): weight = 1.0 if exponent == float('inf') else part.cell_volume dspace = odl.Rn(part.size, exponent=exponent, weight=weight) discr = DiscreteLp(odl.FunctionSpace(rect), part, dspace, - exponent=exponent, impl='cuda') + impl=impl, exponent=exponent) if exponent == float('inf'): assert discr.one().norm() == 1 diff --git a/test/largescale/space/fn_base_slow_test.py b/test/largescale/space/fn_base_slow_test.py index febb3554fb6..9eb0797e7c9 100644 --- a/test/largescale/space/fn_base_slow_test.py +++ b/test/largescale/space/fn_base_slow_test.py @@ -29,8 +29,8 @@ # ODL imports import odl -from odl.util.testutils import all_almost_equal, almost_equal - +from odl.util.testutils import (all_almost_equal, almost_equal, + never_skip, skip_if_no_cuda) pytestmark = odl.util.skip_if_no_largescale @@ -65,22 +65,38 @@ def _vectors(fn, n=1): # Pytest fixtures -spc_params = [odl.Rn(10 ** 5), - odl.uniform_discr(0, 1, 10 ** 5), - odl.uniform_discr([0, 0, 0], [1, 1, 1], [100, 100, 100])] +spc_params = [never_skip('rn numpy'), + never_skip('1d numpy'), + never_skip('3d numpy'), + skip_if_no_cuda('rn cuda'), + skip_if_no_cuda('1d cuda'), + skip_if_no_cuda('3d cuda')] + + +spc_ids = [' type={} impl={}' + ''.format(*p.args[1].split()) for p in spc_params] + -if odl.CUDA_AVAILABLE: - # Simply modify spc_params to modify the fixture - spc_params += [odl.CudaRn(10 ** 5), - odl.uniform_discr(0, 1, 10 ** 5, impl='cuda'), - odl.uniform_discr([0, 0, 0], [1, 1, 1], - [100, 100, 100], impl='cuda')] -spc_ids = [' {!r} '.format(spc) for spc in spc_params] +# bug in pytest (ignores pytestmark) forces us to do this this +largescale = " or not pytest.config.getoption('--largescale')" +spc_params = [pytest.mark.skipif(p.args[0] + largescale, p.args[1]) + for p in spc_params] @pytest.fixture(scope="module", ids=spc_ids, params=spc_params) def fn(request): - return request.param + spc, impl = request.param.split() + + if spc == 'rn': + if impl == 'numpy': + return odl.Rn(10 ** 5) + elif impl == 'cuda': + return odl.CudaRn(10 ** 5) + elif spc == '1d': + return odl.uniform_discr(0, 1, 10 ** 5, impl=impl) + elif spc == '3d': + return odl.uniform_discr([0, 0, 0], [1, 1, 1], + [100, 100, 100], impl=impl) def test_element(fn): @@ -134,31 +150,45 @@ def test_setitem(fn): assert x[index] == -index -@pytest.mark.xfail(reason='Expected to fail since inner scaling is not public') +def fn_weighting(fn): + """ Get the weighting of a fn space """ + + # TODO: use actual weighting + + if isinstance(fn, odl.DiscreteLp): + return fn.domain.volume / fn.size + else: + return 1.0 + + def test_inner(fn): + weighting = fn_weighting(fn) + xarr, yarr, x, y = _vectors(fn, 2) - correct_inner = np.vdot(xarr, yarr) + correct_inner = np.vdot(xarr, yarr) * weighting assert almost_equal(fn.inner(x, y), correct_inner, places=2) assert almost_equal(x.inner(y), correct_inner, places=2) -@pytest.mark.xfail(reason='Expected to fail since inner scaling is not public') def test_norm(fn): + weighting = np.sqrt(fn_weighting(fn)) + xarr, x = _vectors(fn) - correct_norm = np.linalg.norm(xarr) + correct_norm = np.linalg.norm(xarr) * weighting assert almost_equal(fn.norm(x), correct_norm, places=2) assert almost_equal(x.norm(), correct_norm, places=2) -@pytest.mark.xfail(reason='Expected to fail since inner scaling is not public') def test_dist(fn): + weighting = np.sqrt(fn_weighting(fn)) + xarr, yarr, x, y = _vectors(fn, 2) - correct_dist = np.linalg.norm(xarr - yarr) + correct_dist = np.linalg.norm(xarr - yarr) * weighting assert almost_equal(fn.dist(x, y), correct_dist, places=2) assert almost_equal(x.dist(y), correct_dist, places=2) diff --git a/test/largescale/tomo/ray_transform_slow_test.py b/test/largescale/tomo/ray_transform_slow_test.py index 6b5991f719b..3c3f18adb03 100644 --- a/test/largescale/tomo/ray_transform_slow_test.py +++ b/test/largescale/tomo/ray_transform_slow_test.py @@ -29,13 +29,10 @@ # Internal import odl import odl.tomo as tomo +from odl.util.testutils import skip_if_no_largescale from odl.tomo.util.testutils import (skip_if_no_astra, skip_if_no_astra_cuda, skip_if_no_scikit) - -pytestmark = odl.util.skip_if_no_largescale - - # Find the valid projectors projectors = [skip_if_no_astra('par2d astra_cpu uniform'), skip_if_no_astra('par2d astra_cpu nonuniform'), @@ -62,6 +59,12 @@ ''.format(*p.args[1].split()) for p in projectors] +# bug in pytest (ignores pytestmark) forces us to do this this +largescale = " or not pytest.config.getoption('--largescale')" +projectors = [pytest.mark.skipif(p.args[0] + largescale, p.args[1]) + for p in projectors] + + @pytest.fixture(scope="module", params=projectors, ids=projector_ids) def projector(request): @@ -163,6 +166,7 @@ def projector(request): raise ValueError('param not valid') +@skip_if_no_largescale def test_reconstruction(projector): """Test discrete Ray transform using ASTRA for reconstruction.""" diff --git a/test/largescale/trafos/fourier_slow_test.py b/test/largescale/trafos/fourier_slow_test.py index 5b8c17ee2ba..492041406b2 100644 --- a/test/largescale/trafos/fourier_slow_test.py +++ b/test/largescale/trafos/fourier_slow_test.py @@ -33,9 +33,8 @@ # ODL imports import odl -from odl.util.testutils import almost_equal +from odl.util.testutils import almost_equal, never_skip -never_skip = pytest.mark.skipif("False", reason='dummy skip') skip_if_no_pyfftw = pytest.mark.skipif("not odl.trafos.PYFFTW_AVAILABLE", reason='pyfftw not available') pytestmark = odl.util.skip_if_no_largescale @@ -69,24 +68,30 @@ def _vectors(discr, num=1): # Pytest fixtures -dom_params = [odl.uniform_discr(-2, 2, 10 ** 5), - odl.uniform_discr([-2, -2, -2], [2, 2, 2], [200, 200, 200]), - odl.uniform_discr(-2, 2, 10 ** 5, dtype='complex'), - odl.uniform_discr([-2, -2, -2], [2, 2, 2], [200, 200, 200], - dtype='complex')] - -dom_ids = [' {!r} '.format(dom) for dom in dom_params] - - impl_params = [never_skip('numpy'), skip_if_no_pyfftw('pyfftw')] impl_ids = [" impl = '{}'".format(p.args[1]) for p in impl_params] +# bug in pytest (ignores pytestmark) forces us to do this this +largescale = " or not pytest.config.getoption('--largescale')" +impl_params = [pytest.mark.skipif(p.args[0] + largescale, p.args[1]) + for p in impl_params] + + @pytest.fixture(scope="module", ids=impl_ids, params=impl_params) def impl(request): return request.param +dom_params = [odl.uniform_discr(-2, 2, 10 ** 5), + odl.uniform_discr([-2, -2, -2], [2, 2, 2], [200, 200, 200]), + odl.uniform_discr(-2, 2, 10 ** 5, dtype='complex'), + odl.uniform_discr([-2, -2, -2], [2, 2, 2], [200, 200, 200], + dtype='complex')] + +dom_ids = [' {!r} '.format(dom) for dom in dom_params] + + @pytest.fixture(scope="module", ids=dom_ids, params=dom_params) def domain(request): return request.param diff --git a/test/space/cu_ntuples_test.py b/test/space/cu_ntuples_test.py index 2a3581ed87f..36202693abc 100644 --- a/test/space/cu_ntuples_test.py +++ b/test/space/cu_ntuples_test.py @@ -82,19 +82,15 @@ def _pos_vector(fn): # Pytest fixtures -if odl.CUDA_AVAILABLE: - # Simply modify spc_params to modify the fixture - spc_params = [CudaRn(100)] -else: - spc_params = [] -spc_ids = [' {!r} '.format(spc) for spc in spc_params] -spc_fixture = pytest.fixture(scope="module", ids=spc_ids, - params=spc_params) +spc_params = ['100 float32'] +spc_ids = [' size={} dtype={} ' + ''.format(*p.split()) for p in spc_params] -@spc_fixture +@pytest.fixture(scope="module", ids=spc_ids, params=spc_params) def fn(request): - return request.param + size, dtype = request.param.split() + return odl.CudaRn(int(size), dtype=dtype) # Simply modify exp_params to modify the fixture @@ -1045,8 +1041,18 @@ def other_dist(x, y): CudaFnCustomDist(1) -@pytest.mark.skipif("not odl.CUDA_AVAILABLE") -def _impl_test_ufuncs(fn, name, n_args, n_out): +def test_ufuncs(fn, ufunc): + name, n_args, n_out, _ = ufunc + if (np.issubsctype(fn.dtype, np.floating) and + name in ['bitwise_and', + 'bitwise_or', + 'bitwise_xor', + 'invert', + 'left_shift', + 'right_shift']): + # Skip integer only methods if floating point type + return + # Get the ufunc from numpy as reference ufunc = getattr(np, name) @@ -1085,23 +1091,9 @@ def _impl_test_ufuncs(fn, name, n_args, n_out): assert odl_result[i] is out_vectors[i] -def test_ufuncs(): - # Cannot use fixture due to bug in pytest - for fn in spc_params: - for name, n_args, n_out, _ in odl.util.ufuncs.UFUNCS: - if (np.issubsctype(fn.dtype, np.floating) and - name in ['bitwise_and', - 'bitwise_or', - 'bitwise_xor', - 'invert', - 'left_shift', - 'right_shift']): - # Skip integer only methods if floating point type - continue - yield _impl_test_ufuncs, fn, name, n_args, n_out - +def test_reductions(fn, reduction): + name, _ = reduction -def _impl_test_reduction(fn, name): ufunc = getattr(np, name) # Create some data @@ -1110,11 +1102,5 @@ def _impl_test_reduction(fn, name): assert almost_equal(ufunc(x_arr), getattr(x.ufunc, name)()) -def test_reductions(): - for fn in spc_params: - for name, _ in odl.util.ufuncs.REDUCTIONS: - yield _impl_test_reduction, fn, name - - if __name__ == '__main__': pytest.main(str(__file__.replace('\\', '/') + ' -v')) diff --git a/test/space/ntuples_test.py b/test/space/ntuples_test.py index adb204954db..7ebec7756f3 100644 --- a/test/space/ntuples_test.py +++ b/test/space/ntuples_test.py @@ -1609,9 +1609,43 @@ def other_dist(x, y): FnCustomDist(1) -def _impl_test_ufuncs(fn, name, n_args, n_out): +def test_ufuncs(fn, ufunc): + name, n_args, n_out, _ = ufunc + if (np.issubsctype(fn.dtype, np.floating) or + np.issubsctype(fn.dtype, np.complexfloating)and + name in ['bitwise_and', + 'bitwise_or', + 'bitwise_xor', + 'invert', + 'left_shift', + 'right_shift']): + # Skip integer only methods if floating point type + return + + if (np.issubsctype(fn.dtype, np.complexfloating) and + name in ['remainder', + 'trunc', + 'signbit', + 'invert', + 'left_shift', + 'right_shift', + 'rad2deg', + 'deg2rad', + 'copysign', + 'mod', + 'modf', + 'fmod', + 'logaddexp2', + 'logaddexp', + 'hypot', + 'arctan2', + 'floor', + 'ceil']): + # Skip real only methods for complex + return + # Get the ufunc from numpy as reference - ufunc = getattr(np, name) + npufunc = getattr(np, name) # Create some data data = _vectors(fn, n_args + n_out) @@ -1622,7 +1656,7 @@ def _impl_test_ufuncs(fn, name, n_args, n_out): out_vectors = data[2 * n_args + n_out:] # Out of place: - np_result = ufunc(*in_arrays) + np_result = npufunc(*in_arrays) vec_fun = getattr(data_vector.ufunc, name) odl_result = vec_fun(*in_vectors) assert all_almost_equal(np_result, odl_result) @@ -1635,7 +1669,7 @@ def _impl_test_ufuncs(fn, name, n_args, n_out): assert isinstance(odl_result[i], fn.element_type) # In place: - np_result = ufunc(*(in_arrays + out_arrays)) + np_result = npufunc(*(in_arrays + out_arrays)) vec_fun = getattr(data_vector.ufunc, name) odl_result = vec_fun(*(in_vectors + out_vectors)) assert all_almost_equal(np_result, odl_result) @@ -1648,19 +1682,6 @@ def _impl_test_ufuncs(fn, name, n_args, n_out): assert odl_result[i] is out_vectors[i] -def test_ufuncs(): - # Cannot use fixture due to bug in pytest - fn = Rn(3) - - for name, n_args, n_out, _ in UFUNCS: - if (np.issubsctype(fn.dtype, np.floating) and - name in ['bitwise_and', 'bitwise_or', 'bitwise_xor', 'invert', - 'left_shift', 'right_shift']): - # Skip integer only methods if floating point type - continue - yield _impl_test_ufuncs, fn, name, n_args, n_out - - def _impl_test_reduction(fn, name): ufunc = getattr(np, name) diff --git a/test/tomo/backends/astra_setup_test.py b/test/tomo/backends/astra_setup_test.py index 3d6d3c968df..0137378b276 100644 --- a/test/tomo/backends/astra_setup_test.py +++ b/test/tomo/backends/astra_setup_test.py @@ -31,10 +31,12 @@ # Internal import odl -from odl.tomo.util.testutils import skip_if_no_astra from odl.util.testutils import is_subdict +pytestmark = pytest.mark.skipif("not odl.tomo.ASTRA_AVAILABLE") + + def _discrete_domain(ndim, interp): """Create `DiscreteLp` space with isotropic grid stride. @@ -81,7 +83,6 @@ def _discrete_domain_anisotropic(ndim, interp): dtype='float32') -@skip_if_no_astra def test_vol_geom_2d(): """Create ASTRA 2D volume geometry.""" @@ -110,7 +111,6 @@ def test_vol_geom_2d(): print('\n', vol_geom) -@skip_if_no_astra def test_vol_geom_3d(): """Create ASTRA 2D volume geometry.""" @@ -144,7 +144,6 @@ def test_vol_geom_3d(): print('\n', vol_geom) -@skip_if_no_astra def test_proj_geom_parallel_2d(): """Create ASTRA 2D projection geometry.""" @@ -162,7 +161,6 @@ def test_proj_geom_parallel_2d(): assert 'ProjectionAngles' in proj_geom -@skip_if_no_astra def test_astra_projection_geometry(): """Create ASTRA projection geometry from geometry objects.""" @@ -222,7 +220,6 @@ def test_astra_projection_geometry(): 'WindowMinY': -1.0, 'WindowMaxY': 1.0}} -@skip_if_no_astra def test_volume_data_2d(): """Create ASTRA data structure in 2D.""" @@ -244,7 +241,6 @@ def test_volume_data_2d(): 'option': {}} -@skip_if_no_astra def test_volume_data_3d(): """Create ASTRA data structure in 2D.""" @@ -273,7 +269,6 @@ def test_volume_data_3d(): 'ProjectionAngles': np.linspace(0, 2, 5)} -@skip_if_no_astra def test_parallel_2d_projector(): """Create ASTRA 2D projectors.""" @@ -284,7 +279,6 @@ def test_parallel_2d_projector(): ndim=2, impl='cpu') -@skip_if_no_astra def test_parallel_3d_projector(): """Create ASTRA 3D projectors.""" @@ -301,7 +295,6 @@ def test_parallel_3d_projector(): ndim=3, impl='cpu') -@skip_if_no_astra def test_astra_algorithm(): """Create ASTRA algorithm object.""" @@ -366,7 +359,6 @@ def test_astra_algorithm(): proj_id=proj_id, impl='cuda') -@skip_if_no_astra def test_geom_to_vec(): """Create ASTRA projection geometries vectors using ODL geometries."""