From 7b8a1b82339883c3831f153b88e8549ff0e5e1df Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Mon, 11 Nov 2019 12:07:09 -0500 Subject: [PATCH 1/8] moving test_affines to pytest --- nibabel/tests/test_affines.py | 97 +++++++++++++++++------------------ 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/nibabel/tests/test_affines.py b/nibabel/tests/test_affines.py index 13b554c5a8..01121e3874 100644 --- a/nibabel/tests/test_affines.py +++ b/nibabel/tests/test_affines.py @@ -9,10 +9,8 @@ from ..affines import (AffineError, apply_affine, append_diag, to_matvec, from_matvec, dot_reduce, voxel_sizes, obliquity) - -from nose.tools import assert_equal, assert_raises -from numpy.testing import assert_array_equal, assert_almost_equal, \ - assert_array_almost_equal +import pytest +import numpy.testing as npt def validated_apply_affine(T, xyz): @@ -32,28 +30,27 @@ def test_apply_affine(): rng = np.random.RandomState(20110903) aff = np.diag([2, 3, 4, 1]) pts = rng.uniform(size=(4, 3)) - assert_array_equal(apply_affine(aff, pts), - pts * [[2, 3, 4]]) + npt.assert_equal(apply_affine(aff, pts), pts * [[2, 3, 4]]) aff[:3, 3] = [10, 11, 12] - assert_array_equal(apply_affine(aff, pts), - pts * [[2, 3, 4]] + [[10, 11, 12]]) + npt.assert_equal(apply_affine(aff, pts), + pts * [[2, 3, 4]] + [[10, 11, 12]]) aff[:3, :] = rng.normal(size=(3, 4)) exp_res = np.concatenate((pts.T, np.ones((1, 4))), axis=0) exp_res = np.dot(aff, exp_res)[:3, :].T - assert_array_equal(apply_affine(aff, pts), exp_res) + npt.assert_equal(apply_affine(aff, pts), exp_res) # Check we get the same result as the previous implementation - assert_almost_equal(validated_apply_affine(aff, pts), apply_affine(aff, pts)) + npt.assert_almost_equal(validated_apply_affine(aff, pts), apply_affine(aff, pts)) # Check that lists work for inputs - assert_array_equal(apply_affine(aff.tolist(), pts.tolist()), exp_res) + npt.assert_equal(apply_affine(aff.tolist(), pts.tolist()), exp_res) # Check that it's the same as a banal implementation in the simple case aff = np.array([[0, 2, 0, 10], [3, 0, 0, 11], [0, 0, 4, 12], [0, 0, 0, 1]]) pts = np.array([[1, 2, 3], [2, 3, 4], [4, 5, 6], [6, 7, 8]]) exp_res = (np.dot(aff[:3, :3], pts.T) + aff[:3, 3:4]).T - assert_array_equal(apply_affine(aff, pts), exp_res) + npt.assert_equal(apply_affine(aff, pts), exp_res) # That points can be reshaped and you'll get the same shape output pts = pts.reshape((2, 2, 3)) exp_res = exp_res.reshape((2, 2, 3)) - assert_array_equal(apply_affine(aff, pts), exp_res) + npt.assert_equal(apply_affine(aff, pts), exp_res) # That ND also works for N in range(2, 6): aff = np.eye(N) @@ -67,7 +64,7 @@ def test_apply_affine(): exp_pts = np.dot(aff, new_pts) exp_pts = np.rollaxis(exp_pts[:-1, :], 0, 2) exp_res = exp_pts.reshape((2, 3, nd)) - assert_array_almost_equal(res, exp_res) + npt.assert_almost_equal(res, exp_res) def test_matrix_vector(): @@ -78,39 +75,39 @@ def test_matrix_vector(): newmat, newvec = to_matvec(xform) mat = xform[:-1, :-1] vec = xform[:-1, -1] - assert_array_equal(newmat, mat) - assert_array_equal(newvec, vec) - assert_equal(newvec.shape, (M - 1,)) - assert_array_equal(from_matvec(mat, vec), xform) + npt.assert_equal(newmat, mat) + npt.assert_equal(newvec, vec) + npt.assert_equal(newvec.shape, (M - 1,)) + npt.assert_equal(from_matvec(mat, vec), xform) # Check default translation works xform_not = xform[:] xform_not[:-1, :] = 0 - assert_array_equal(from_matvec(mat), xform) - assert_array_equal(from_matvec(mat, None), xform) + npt.assert_equal(from_matvec(mat), xform) + npt.assert_equal(from_matvec(mat, None), xform) # Check array-like works newmat, newvec = to_matvec(xform.tolist()) - assert_array_equal(newmat, mat) - assert_array_equal(newvec, vec) - assert_array_equal(from_matvec(mat.tolist(), vec.tolist()), xform) + npt.assert_equal(newmat, mat) + npt.assert_equal(newvec, vec) + npt.assert_equal(from_matvec(mat.tolist(), vec.tolist()), xform) def test_append_diag(): # Routine for appending diagonal elements - assert_array_equal(append_diag(np.diag([2, 3, 1]), [1]), + npt.assert_equal(append_diag(np.diag([2, 3, 1]), [1]), np.diag([2, 3, 1, 1])) - assert_array_equal(append_diag(np.diag([2, 3, 1]), [1, 1]), + npt.assert_equal(append_diag(np.diag([2, 3, 1]), [1, 1]), np.diag([2, 3, 1, 1, 1])) aff = np.array([[2, 0, 0], [0, 3, 0], [0, 0, 1], [0, 0, 1]]) - assert_array_equal(append_diag(aff, [5], [9]), + npt.assert_equal(append_diag(aff, [5], [9]), [[2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 0, 1], [0, 0, 5, 9], [0, 0, 0, 1]]) - assert_array_equal(append_diag(aff, [5, 6], [9, 10]), + npt.assert_equal(append_diag(aff, [5, 6], [9, 10]), [[2, 0, 0, 0, 0], [0, 3, 0, 0, 0], [0, 0, 0, 0, 1], @@ -120,38 +117,40 @@ def test_append_diag(): aff = np.array([[2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 0, 1]]) - assert_array_equal(append_diag(aff, [5], [9]), + npt.assert_equal(append_diag(aff, [5], [9]), [[2, 0, 0, 0, 0], [0, 3, 0, 0, 0], [0, 0, 0, 5, 9], [0, 0, 0, 0, 1]]) # Length of starts has to match length of steps - assert_raises(AffineError, append_diag, aff, [5, 6], [9]) + with pytest.raises(AffineError): + append_diag(aff, [5, 6], [9]) def test_dot_reduce(): # Chaining numpy dot # Error for no arguments - assert_raises(TypeError, dot_reduce) + with pytest.raises(TypeError): + dot_reduce() # Anything at all on its own, passes through - assert_equal(dot_reduce(1), 1) - assert_equal(dot_reduce(None), None) - assert_equal(dot_reduce([1, 2, 3]), [1, 2, 3]) + npt.assert_equal(dot_reduce(1), 1) + npt.assert_equal(dot_reduce(None), None) + npt.assert_equal(dot_reduce([1, 2, 3]), [1, 2, 3]) # Two or more -> dot product vec = [1, 2, 3] mat = np.arange(4, 13).reshape((3, 3)) - assert_array_equal(dot_reduce(vec, mat), np.dot(vec, mat)) - assert_array_equal(dot_reduce(mat, vec), np.dot(mat, vec)) + npt.assert_equal(dot_reduce(vec, mat), np.dot(vec, mat)) + npt.assert_equal(dot_reduce(mat, vec), np.dot(mat, vec)) mat2 = np.arange(13, 22).reshape((3, 3)) - assert_array_equal(dot_reduce(mat2, vec, mat), - np.dot(mat2, np.dot(vec, mat))) - assert_array_equal(dot_reduce(mat, vec, mat2, ), - np.dot(mat, np.dot(vec, mat2))) + npt.assert_equal(dot_reduce(mat2, vec, mat), + np.dot(mat2, np.dot(vec, mat))) + npt.assert_equal(dot_reduce(mat, vec, mat2, ), + np.dot(mat, np.dot(vec, mat2))) def test_voxel_sizes(): affine = np.diag([2, 3, 4, 1]) - assert_almost_equal(voxel_sizes(affine), [2, 3, 4]) + npt.assert_almost_equal(voxel_sizes(affine), [2, 3, 4]) # Some example rotations rotations = [] for x_rot, y_rot, z_rot in product((0, 0.4), (0, 0.6), (0, 0.8)): @@ -160,16 +159,16 @@ def test_voxel_sizes(): for n in range(2, 10): vox_sizes = np.arange(n) + 4.1 aff = np.diag(list(vox_sizes) + [1]) - assert_almost_equal(voxel_sizes(aff), vox_sizes) + npt.assert_almost_equal(voxel_sizes(aff), vox_sizes) # Translations make no difference aff[:-1, -1] = np.arange(n) + 10 - assert_almost_equal(voxel_sizes(aff), vox_sizes) + npt.assert_almost_equal(voxel_sizes(aff), vox_sizes) # Does not have to be square new_row = np.vstack((np.zeros(n + 1), aff)) - assert_almost_equal(voxel_sizes(new_row), vox_sizes) + npt.assert_almost_equal(voxel_sizes(new_row), vox_sizes) new_col = np.c_[np.zeros(n + 1), aff] - assert_almost_equal(voxel_sizes(new_col), - [0] + list(vox_sizes)) + npt.assert_almost_equal(voxel_sizes(new_col), + [0] + list(vox_sizes)) if n < 3: continue # Rotations do not change the voxel size @@ -177,7 +176,7 @@ def test_voxel_sizes(): rot_affine = np.eye(n + 1) rot_affine[:3, :3] = rotation full_aff = rot_affine.dot(aff) - assert_almost_equal(voxel_sizes(full_aff), vox_sizes) + npt.assert_almost_equal(voxel_sizes(full_aff), vox_sizes) def test_obliquity(): @@ -187,6 +186,6 @@ def test_obliquity(): aligned[:-1, -1] = [-10, -10, -7] R = from_matvec(euler2mat(x=0.09, y=0.001, z=0.001), [0.0, 0.0, 0.0]) oblique = R.dot(aligned) - assert_almost_equal(obliquity(aligned), [0.0, 0.0, 0.0]) - assert_almost_equal(obliquity(oblique) * 180 / pi, - [0.0810285, 5.1569949, 5.1569376]) + npt.assert_almost_equal(obliquity(aligned), [0.0, 0.0, 0.0]) + npt.assert_almost_equal(obliquity(oblique) * 180 / pi, + [0.0810285, 5.1569949, 5.1569376]) From c99ef1274e36f4525ecb526d56080ec91a6a7ade Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Mon, 11 Nov 2019 12:16:43 -0500 Subject: [PATCH 2/8] adding pytest to ravis --- .travis.yml | 1 + setup.cfg | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1b81ba296c..b35a0cb1eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -132,6 +132,7 @@ script: cd for_testing cp ../.coveragerc . nosetests --with-doctest --with-coverage --cover-package nibabel nibabel + pytest -v nibabel/tests/test_affines.py else false fi diff --git a/setup.cfg b/setup.cfg index 5630921dd9..3b5bddae19 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,6 +33,7 @@ install_requires = numpy >=1.12 tests_require = nose >=0.11 + pytest mock test_suite = nose.collector zip_safe = False @@ -54,6 +55,7 @@ test = coverage mock nose >=0.11 + pytest all = %(dicom)s %(doc)s From 7b70af7c9623e847b0eef3ffe0d07615306ac2c6 Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Mon, 11 Nov 2019 12:32:24 -0500 Subject: [PATCH 3/8] adding pytest to the windows env --- .azure-pipelines/windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines/windows.yml b/.azure-pipelines/windows.yml index 0cda80d6ee..5c7aa3d713 100644 --- a/.azure-pipelines/windows.yml +++ b/.azure-pipelines/windows.yml @@ -29,10 +29,9 @@ jobs: displayName: 'Update build tools' - script: | python -m pip install --find-links %EXTRA_WHEELS% %DEPENDS% - python -m pip install nose mock coverage codecov displayName: 'Install dependencies' - script: | - python -m pip install . + python -m pip install .[test] SET NIBABEL_DATA_DIR=%CD%\\nibabel-data displayName: 'Install nibabel' - script: | @@ -40,6 +39,7 @@ jobs: cd for_testing cp ../.coveragerc . nosetests --with-doctest --with-coverage --cover-package nibabel nibabel + pytest -v nibabel/tests/test_affines.py displayName: 'Nose tests' - script: | cd for_testing From 491020fdac11d4f7b0e3d61ecb52c4d43263b401 Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Mon, 11 Nov 2019 12:41:19 -0500 Subject: [PATCH 4/8] testing windows installations --- .azure-pipelines/windows.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.azure-pipelines/windows.yml b/.azure-pipelines/windows.yml index 5c7aa3d713..9cfa7a7e83 100644 --- a/.azure-pipelines/windows.yml +++ b/.azure-pipelines/windows.yml @@ -29,9 +29,11 @@ jobs: displayName: 'Update build tools' - script: | python -m pip install --find-links %EXTRA_WHEELS% %DEPENDS% + python -m pip install nose mock coverage codecov + python -m pip install pytest displayName: 'Install dependencies' - script: | - python -m pip install .[test] + python -m pip install . SET NIBABEL_DATA_DIR=%CD%\\nibabel-data displayName: 'Install nibabel' - script: | From 8868ac99a05ac3614f2329ade7ed616aee41205e Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Mon, 11 Nov 2019 12:48:53 -0500 Subject: [PATCH 5/8] trying a different pytest command for windows --- .azure-pipelines/windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure-pipelines/windows.yml b/.azure-pipelines/windows.yml index 9cfa7a7e83..a719b1f0bf 100644 --- a/.azure-pipelines/windows.yml +++ b/.azure-pipelines/windows.yml @@ -41,7 +41,7 @@ jobs: cd for_testing cp ../.coveragerc . nosetests --with-doctest --with-coverage --cover-package nibabel nibabel - pytest -v nibabel/tests/test_affines.py + pytest -v %CD%\\nibabel\tests\test_affines.py displayName: 'Nose tests' - script: | cd for_testing From 86fe29af08cbeb93c24a3264dfa77ff34ddacb17 Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Mon, 11 Nov 2019 12:53:37 -0500 Subject: [PATCH 6/8] yet another command for windows --- .azure-pipelines/windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure-pipelines/windows.yml b/.azure-pipelines/windows.yml index a719b1f0bf..c28a952343 100644 --- a/.azure-pipelines/windows.yml +++ b/.azure-pipelines/windows.yml @@ -41,7 +41,7 @@ jobs: cd for_testing cp ../.coveragerc . nosetests --with-doctest --with-coverage --cover-package nibabel nibabel - pytest -v %CD%\\nibabel\tests\test_affines.py + pytest -v nibabel\tests\test_affines.py displayName: 'Nose tests' - script: | cd for_testing From eae2b0449dcd76755fda8c5ebcdf0f2b0968adbe Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Mon, 11 Nov 2019 13:06:59 -0500 Subject: [PATCH 7/8] fixing path to the test --- .azure-pipelines/windows.yml | 2 +- .travis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines/windows.yml b/.azure-pipelines/windows.yml index c28a952343..826c7ddc41 100644 --- a/.azure-pipelines/windows.yml +++ b/.azure-pipelines/windows.yml @@ -41,7 +41,7 @@ jobs: cd for_testing cp ../.coveragerc . nosetests --with-doctest --with-coverage --cover-package nibabel nibabel - pytest -v nibabel\tests\test_affines.py + pytest -v ../nibabel/tests/test_affines.py displayName: 'Nose tests' - script: | cd for_testing diff --git a/.travis.yml b/.travis.yml index b35a0cb1eb..39f1a14a45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -132,7 +132,7 @@ script: cd for_testing cp ../.coveragerc . nosetests --with-doctest --with-coverage --cover-package nibabel nibabel - pytest -v nibabel/tests/test_affines.py + pytest -v ../nibabel/tests/test_affines.py else false fi From 6748c6de2385b9613d6f6a752ce7b23a5951a8e7 Mon Sep 17 00:00:00 2001 From: Dorota Jarecka Date: Mon, 11 Nov 2019 13:23:47 -0500 Subject: [PATCH 8/8] revert some of the changes to the test (didnt notice numpy.testing was already used) --- nibabel/tests/test_affines.py | 89 ++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/nibabel/tests/test_affines.py b/nibabel/tests/test_affines.py index 01121e3874..6fd2f59fab 100644 --- a/nibabel/tests/test_affines.py +++ b/nibabel/tests/test_affines.py @@ -9,8 +9,10 @@ from ..affines import (AffineError, apply_affine, append_diag, to_matvec, from_matvec, dot_reduce, voxel_sizes, obliquity) + import pytest -import numpy.testing as npt +from numpy.testing import assert_array_equal, assert_almost_equal, \ + assert_array_almost_equal def validated_apply_affine(T, xyz): @@ -30,27 +32,28 @@ def test_apply_affine(): rng = np.random.RandomState(20110903) aff = np.diag([2, 3, 4, 1]) pts = rng.uniform(size=(4, 3)) - npt.assert_equal(apply_affine(aff, pts), pts * [[2, 3, 4]]) + assert_array_equal(apply_affine(aff, pts), + pts * [[2, 3, 4]]) aff[:3, 3] = [10, 11, 12] - npt.assert_equal(apply_affine(aff, pts), - pts * [[2, 3, 4]] + [[10, 11, 12]]) + assert_array_equal(apply_affine(aff, pts), + pts * [[2, 3, 4]] + [[10, 11, 12]]) aff[:3, :] = rng.normal(size=(3, 4)) exp_res = np.concatenate((pts.T, np.ones((1, 4))), axis=0) exp_res = np.dot(aff, exp_res)[:3, :].T - npt.assert_equal(apply_affine(aff, pts), exp_res) + assert_array_equal(apply_affine(aff, pts), exp_res) # Check we get the same result as the previous implementation - npt.assert_almost_equal(validated_apply_affine(aff, pts), apply_affine(aff, pts)) + assert_almost_equal(validated_apply_affine(aff, pts), apply_affine(aff, pts)) # Check that lists work for inputs - npt.assert_equal(apply_affine(aff.tolist(), pts.tolist()), exp_res) + assert_array_equal(apply_affine(aff.tolist(), pts.tolist()), exp_res) # Check that it's the same as a banal implementation in the simple case aff = np.array([[0, 2, 0, 10], [3, 0, 0, 11], [0, 0, 4, 12], [0, 0, 0, 1]]) pts = np.array([[1, 2, 3], [2, 3, 4], [4, 5, 6], [6, 7, 8]]) exp_res = (np.dot(aff[:3, :3], pts.T) + aff[:3, 3:4]).T - npt.assert_equal(apply_affine(aff, pts), exp_res) + assert_array_equal(apply_affine(aff, pts), exp_res) # That points can be reshaped and you'll get the same shape output pts = pts.reshape((2, 2, 3)) exp_res = exp_res.reshape((2, 2, 3)) - npt.assert_equal(apply_affine(aff, pts), exp_res) + assert_array_equal(apply_affine(aff, pts), exp_res) # That ND also works for N in range(2, 6): aff = np.eye(N) @@ -64,7 +67,7 @@ def test_apply_affine(): exp_pts = np.dot(aff, new_pts) exp_pts = np.rollaxis(exp_pts[:-1, :], 0, 2) exp_res = exp_pts.reshape((2, 3, nd)) - npt.assert_almost_equal(res, exp_res) + assert_array_almost_equal(res, exp_res) def test_matrix_vector(): @@ -75,39 +78,39 @@ def test_matrix_vector(): newmat, newvec = to_matvec(xform) mat = xform[:-1, :-1] vec = xform[:-1, -1] - npt.assert_equal(newmat, mat) - npt.assert_equal(newvec, vec) - npt.assert_equal(newvec.shape, (M - 1,)) - npt.assert_equal(from_matvec(mat, vec), xform) + assert_array_equal(newmat, mat) + assert_array_equal(newvec, vec) + assert newvec.shape == (M - 1,) + assert_array_equal(from_matvec(mat, vec), xform) # Check default translation works xform_not = xform[:] xform_not[:-1, :] = 0 - npt.assert_equal(from_matvec(mat), xform) - npt.assert_equal(from_matvec(mat, None), xform) + assert_array_equal(from_matvec(mat), xform) + assert_array_equal(from_matvec(mat, None), xform) # Check array-like works newmat, newvec = to_matvec(xform.tolist()) - npt.assert_equal(newmat, mat) - npt.assert_equal(newvec, vec) - npt.assert_equal(from_matvec(mat.tolist(), vec.tolist()), xform) + assert_array_equal(newmat, mat) + assert_array_equal(newvec, vec) + assert_array_equal(from_matvec(mat.tolist(), vec.tolist()), xform) def test_append_diag(): # Routine for appending diagonal elements - npt.assert_equal(append_diag(np.diag([2, 3, 1]), [1]), + assert_array_equal(append_diag(np.diag([2, 3, 1]), [1]), np.diag([2, 3, 1, 1])) - npt.assert_equal(append_diag(np.diag([2, 3, 1]), [1, 1]), + assert_array_equal(append_diag(np.diag([2, 3, 1]), [1, 1]), np.diag([2, 3, 1, 1, 1])) aff = np.array([[2, 0, 0], [0, 3, 0], [0, 0, 1], [0, 0, 1]]) - npt.assert_equal(append_diag(aff, [5], [9]), + assert_array_equal(append_diag(aff, [5], [9]), [[2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 0, 1], [0, 0, 5, 9], [0, 0, 0, 1]]) - npt.assert_equal(append_diag(aff, [5, 6], [9, 10]), + assert_array_equal(append_diag(aff, [5, 6], [9, 10]), [[2, 0, 0, 0, 0], [0, 3, 0, 0, 0], [0, 0, 0, 0, 1], @@ -117,7 +120,7 @@ def test_append_diag(): aff = np.array([[2, 0, 0, 0], [0, 3, 0, 0], [0, 0, 0, 1]]) - npt.assert_equal(append_diag(aff, [5], [9]), + assert_array_equal(append_diag(aff, [5], [9]), [[2, 0, 0, 0, 0], [0, 3, 0, 0, 0], [0, 0, 0, 5, 9], @@ -133,24 +136,24 @@ def test_dot_reduce(): with pytest.raises(TypeError): dot_reduce() # Anything at all on its own, passes through - npt.assert_equal(dot_reduce(1), 1) - npt.assert_equal(dot_reduce(None), None) - npt.assert_equal(dot_reduce([1, 2, 3]), [1, 2, 3]) + assert dot_reduce(1) == 1 + assert dot_reduce(None) is None + assert dot_reduce([1, 2, 3]) == [1, 2, 3] # Two or more -> dot product vec = [1, 2, 3] mat = np.arange(4, 13).reshape((3, 3)) - npt.assert_equal(dot_reduce(vec, mat), np.dot(vec, mat)) - npt.assert_equal(dot_reduce(mat, vec), np.dot(mat, vec)) + assert_array_equal(dot_reduce(vec, mat), np.dot(vec, mat)) + assert_array_equal(dot_reduce(mat, vec), np.dot(mat, vec)) mat2 = np.arange(13, 22).reshape((3, 3)) - npt.assert_equal(dot_reduce(mat2, vec, mat), - np.dot(mat2, np.dot(vec, mat))) - npt.assert_equal(dot_reduce(mat, vec, mat2, ), - np.dot(mat, np.dot(vec, mat2))) + assert_array_equal(dot_reduce(mat2, vec, mat), + np.dot(mat2, np.dot(vec, mat))) + assert_array_equal(dot_reduce(mat, vec, mat2, ), + np.dot(mat, np.dot(vec, mat2))) def test_voxel_sizes(): affine = np.diag([2, 3, 4, 1]) - npt.assert_almost_equal(voxel_sizes(affine), [2, 3, 4]) + assert_almost_equal(voxel_sizes(affine), [2, 3, 4]) # Some example rotations rotations = [] for x_rot, y_rot, z_rot in product((0, 0.4), (0, 0.6), (0, 0.8)): @@ -159,16 +162,16 @@ def test_voxel_sizes(): for n in range(2, 10): vox_sizes = np.arange(n) + 4.1 aff = np.diag(list(vox_sizes) + [1]) - npt.assert_almost_equal(voxel_sizes(aff), vox_sizes) + assert_almost_equal(voxel_sizes(aff), vox_sizes) # Translations make no difference aff[:-1, -1] = np.arange(n) + 10 - npt.assert_almost_equal(voxel_sizes(aff), vox_sizes) + assert_almost_equal(voxel_sizes(aff), vox_sizes) # Does not have to be square new_row = np.vstack((np.zeros(n + 1), aff)) - npt.assert_almost_equal(voxel_sizes(new_row), vox_sizes) + assert_almost_equal(voxel_sizes(new_row), vox_sizes) new_col = np.c_[np.zeros(n + 1), aff] - npt.assert_almost_equal(voxel_sizes(new_col), - [0] + list(vox_sizes)) + assert_almost_equal(voxel_sizes(new_col), + [0] + list(vox_sizes)) if n < 3: continue # Rotations do not change the voxel size @@ -176,7 +179,7 @@ def test_voxel_sizes(): rot_affine = np.eye(n + 1) rot_affine[:3, :3] = rotation full_aff = rot_affine.dot(aff) - npt.assert_almost_equal(voxel_sizes(full_aff), vox_sizes) + assert_almost_equal(voxel_sizes(full_aff), vox_sizes) def test_obliquity(): @@ -186,6 +189,6 @@ def test_obliquity(): aligned[:-1, -1] = [-10, -10, -7] R = from_matvec(euler2mat(x=0.09, y=0.001, z=0.001), [0.0, 0.0, 0.0]) oblique = R.dot(aligned) - npt.assert_almost_equal(obliquity(aligned), [0.0, 0.0, 0.0]) - npt.assert_almost_equal(obliquity(oblique) * 180 / pi, - [0.0810285, 5.1569949, 5.1569376]) + assert_almost_equal(obliquity(aligned), [0.0, 0.0, 0.0]) + assert_almost_equal(obliquity(oblique) * 180 / pi, + [0.0810285, 5.1569949, 5.1569376])