Skip to content

Commit 5c9dfff

Browse files
Merge pull request #602 from effigies/test/coverage
MRG: Increase coverage where easy Just looking through the coverage report for easy fixes.
2 parents 3518672 + f993b63 commit 5c9dfff

10 files changed

+61
-36
lines changed

.coveragerc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ include = */nibabel/*, */nisext/*
55
omit =
66
*/externals/*
77
*/benchmarks/*
8-
*/ast.py
9-
*/codegen.py
8+
*/tests/*

nibabel/analyze.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,10 +1086,6 @@ def to_file_map(self, file_map=None):
10861086
# Write header
10871087
hdr.write_to(hdrf)
10881088
# Write image
1089-
shape = hdr.get_data_shape()
1090-
if data.shape != shape:
1091-
raise HeaderDataError('Data should be shape (%s)' %
1092-
', '.join(str(s) for s in shape))
10931089
# Seek to writing position, get there by writing zeros if seek fails
10941090
seek_tell(imgf, hdr.get_data_offset(), write0=True)
10951091
# Write array data

nibabel/deprecated.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ class ModuleProxy(object):
3131
def __init__(self, module_name):
3232
self._module_name = module_name
3333

34-
def __hasattr__(self, key):
35-
mod = __import__(self._module_name, fromlist=[''])
36-
return hasattr(mod, key)
37-
3834
def __getattr__(self, key):
3935
mod = __import__(self._module_name, fromlist=[''])
4036
return getattr(mod, key)

nibabel/tests/test_analyze.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,10 @@ def test_from_header(self):
525525
hdr.set_data_dtype(np.float64)
526526
hdr.set_data_shape((1, 2, 3))
527527
hdr.set_zooms((3.0, 2.0, 1.0))
528-
copy = klass.from_header(hdr)
529-
assert_equal(hdr, copy)
530-
assert_false(hdr is copy)
528+
for check in (True, False):
529+
copy = klass.from_header(hdr, check=check)
530+
assert_equal(hdr, copy)
531+
assert_false(hdr is copy)
531532

532533
class C(object):
533534

nibabel/tests/test_arrayproxy.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -381,27 +381,23 @@ def test_keep_file_open_true_false_invalid():
381381
x , y, z = [int(c) for c in voxels[i, :]]
382382
assert proxy_kfp[x, y, z] == x * 100 + y * 10 + z
383383
assert CountingImageOpener.num_openers == 1
384+
del proxy_kfp
385+
del proxy_no_kfp
384386
# Test that the keep_file_open flag has no effect if an open file
385387
# handle is passed in
386388
with open(fname, 'rb') as fobj:
387-
proxy_no_kfp = ArrayProxy(fobj, ((10, 10, 10), dtype),
388-
keep_file_open=False)
389-
assert not proxy_no_kfp._keep_file_open
390-
for i in range(voxels.shape[0]):
391-
assert proxy_no_kfp[x, y, z] == x * 100 + y * 10 + z
389+
for kfo in (True, False, 'auto'):
390+
proxy = ArrayProxy(fobj, ((10, 10, 10), dtype),
391+
keep_file_open=kfo)
392+
if kfo == 'auto':
393+
kfo = False
394+
assert proxy._keep_file_open is kfo
395+
for i in range(voxels.shape[0]):
396+
assert proxy[x, y, z] == x * 100 + y * 10 + z
397+
assert not fobj.closed
398+
del proxy
392399
assert not fobj.closed
393-
del proxy_no_kfp
394-
proxy_no_kfp = None
395-
assert not fobj.closed
396-
proxy_kfp = ArrayProxy(fobj, ((10, 10, 10), dtype),
397-
keep_file_open=True)
398-
assert proxy_kfp._keep_file_open
399-
for i in range(voxels.shape[0]):
400-
assert proxy_kfp[x, y, z] == x * 100 + y * 10 + z
401-
assert not fobj.closed
402-
del proxy_kfp
403-
proxy_kfp = None
404-
assert not fobj.closed
400+
assert fobj.closed
405401
# Test invalid values of keep_file_open
406402
with assert_raises(ValueError):
407403
ArrayProxy(fname, ((10, 10, 10), dtype), keep_file_open=0)

nibabel/tests/test_image_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,10 @@ def validate_data_interface(self, imaker, params):
339339
# cache state.
340340
img.uncache()
341341
assert_true(img.in_memory)
342-
# Values to get_data caching parameter must be 'fill' or
342+
# Values to get_(f)data caching parameter must be 'fill' or
343343
# 'unchanged'
344344
assert_raises(ValueError, img.get_data, caching='something')
345+
assert_raises(ValueError, img.get_fdata, caching='something')
345346
# Data shape is same as image shape
346347
assert_equal(img.shape, method().shape)
347348
# Values to get_data caching parameter must be 'fill' or

nibabel/tests/test_orientations.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
''' Testing for orientations module '''
1010

1111
import numpy as np
12+
import warnings
1213

1314
from nose.tools import assert_true, assert_equal, assert_raises
1415

1516
from numpy.testing import assert_array_equal
1617

1718
from ..orientations import (io_orientation, ornt_transform, inv_ornt_aff,
1819
flip_axis, apply_orientation, OrientationError,
19-
ornt2axcodes, axcodes2ornt, aff2axcodes)
20+
ornt2axcodes, axcodes2ornt, aff2axcodes,
21+
orientation_affine)
2022

2123
from ..affines import from_matvec, to_matvec
2224

@@ -245,6 +247,12 @@ def test_ornt_transform():
245247
[[0, 1, 1], [1, 1, 1]],
246248
[[0, 1, 1], [1, 1, 1]])
247249

250+
# Target axes must exist in source
251+
assert_raises(ValueError,
252+
ornt_transform,
253+
[[0, 1], [1, 1], [1, 1]],
254+
[[0, 1], [1, 1], [2, 1]])
255+
248256

249257
def test_ornt2axcodes():
250258
# Recoding orientation to axis codes
@@ -347,3 +355,13 @@ def test_inv_ornt_aff():
347355
# io_orientations test)
348356
assert_raises(OrientationError, inv_ornt_aff,
349357
[[0, 1], [1, -1], [np.nan, np.nan]], (3, 4, 5))
358+
359+
360+
def test_orientation_affine_deprecation():
361+
aff1 = inv_ornt_aff([[0, 1], [1, -1], [2, 1]], (3, 4, 5))
362+
with warnings.catch_warnings(record=True) as warns:
363+
warnings.simplefilter('always')
364+
aff2 = orientation_affine([[0, 1], [1, -1], [2, 1]], (3, 4, 5))
365+
assert_equal(len(warns), 1)
366+
assert_equal(warns[0].category, DeprecationWarning)
367+
assert_array_equal(aff1, aff2)

nibabel/tests/test_pkg_info.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
""" Testing package info
2+
"""
3+
4+
import nibabel as nib
5+
6+
def test_pkg_info():
7+
"""Simple smoke test
8+
9+
Hits:
10+
- nibabel.get_info
11+
- nibabel.pkg_info.get_pkg_info
12+
- nibabel.pkg_info.pkg_commit_hash
13+
"""
14+
info = nib.get_info()

nibabel/tests/test_processing.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ def test_resample_to_output():
214214
img2 = resample_to_output(img, vox_sizes)
215215
# Check 2D works
216216
img_2d = Nifti1Image(data[0], np.eye(4))
217-
img3 = resample_to_output(img_2d)
218-
assert_array_equal(img3.shape, (3, 4, 1))
219-
assert_array_equal(img3.affine, np.eye(4))
220-
assert_array_equal(img3.dataobj, data[0][..., None])
217+
for vox_sizes in (None, 1, (1, 1), (1, 1, 1)):
218+
img3 = resample_to_output(img_2d, vox_sizes)
219+
assert_array_equal(img3.shape, (3, 4, 1))
220+
assert_array_equal(img3.affine, np.eye(4))
221+
assert_array_equal(img3.dataobj, data[0][..., None])
221222
# Even 1D
222223
img_1d = Nifti1Image(data[0, 0], np.eye(4))
223224
img3 = resample_to_output(img_1d)

nibabel/tests/test_quaternions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,6 @@ def test_angle_axis():
185185
yield nq.nearly_equivalent, q, q2
186186
aa_mat = nq.angle_axis2mat(theta, vec)
187187
yield assert_array_almost_equal, aa_mat, M
188+
unit_vec = vec / np.sqrt(vec.dot(vec))
189+
aa_mat2 = nq.angle_axis2mat(theta, unit_vec, is_normalized=True)
190+
yield assert_array_almost_equal, aa_mat2, M

0 commit comments

Comments
 (0)