Skip to content

Commit 35beaba

Browse files
committed
Style issues, use capsys
1 parent 2331e9d commit 35beaba

File tree

5 files changed

+8
-35
lines changed

5 files changed

+8
-35
lines changed

bin/nib-stats.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

nibabel/cmdline/stats.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def _get_parser():
2727
choices=("mm3", "vox"), help="Preferred output units")
2828
return p
2929

30+
3031
def main(args=None):
3132
"""Main program function."""
3233
parser = _get_parser()

nibabel/cmdline/tests/test_stats.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,7 @@
1717
from nibabel import Nifti1Image
1818

1919

20-
class Capturing(list):
21-
def __enter__(self):
22-
self._stdout = sys.stdout
23-
sys.stdout = self._stringio = StringIO()
24-
return self
25-
def __exit__(self, *args):
26-
self.extend(self._stringio.getvalue().splitlines())
27-
del self._stringio # free up some memory
28-
sys.stdout = self._stdout
29-
30-
31-
def test_volume(tmpdir):
20+
def test_volume(tmpdir, capsys):
3221
mask_data = np.zeros((20, 20, 20), dtype='u1')
3322
mask_data[5:15, 5:15, 5:15] = 1
3423
img = Nifti1Image(mask_data, np.eye(4))
@@ -37,11 +26,11 @@ def test_volume(tmpdir):
3726
save(img, infile)
3827

3928
args = (f"{infile} --Volume")
40-
with Capturing() as vol_mm3:
41-
main(args.split())
29+
main(args.split())
30+
vol_mm3 = capsys.readouterr()
4231
args = (f"{infile} --Volume --units vox")
43-
with Capturing() as vol_vox:
44-
main(args.split())
32+
main(args.split())
33+
vol_vox = capsys.readouterr()
4534

4635
assert float(vol_mm3[0]) == 1000.0
4736
assert int(vol_vox[0]) == 1000

nibabel/funcs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,3 @@ def _aff_is_diag(aff):
215215
""" Utility function returning True if affine is nearly diagonal """
216216
rzs_aff = aff[:3, :3]
217217
return np.allclose(rzs_aff, np.diag(np.diag(rzs_aff)))
218-

nibabel/imagestats.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import numpy as np
1414
from nibabel.imageclasses import spatial_axes_first
1515

16+
1617
def count_nonzero_voxels(img):
1718
"""
1819
Count number of non-zero voxels
@@ -30,6 +31,7 @@ def count_nonzero_voxels(img):
3031
"""
3132
return np.count_nonzero(img.dataobj)
3233

34+
3335
def mask_volume(img):
3436
""" Compute volume of mask image.
3537

0 commit comments

Comments
 (0)