Skip to content

Commit 7392e8f

Browse files
committed
TEST: Style and parameterization fixes for readability
1 parent 592b310 commit 7392e8f

17 files changed

+153
-201
lines changed

nibabel/cifti2/tests/test_cifti2io_header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def test_read_geometry():
255255
[ 0, 0, 0, 1]]
256256
expected_dimensions = (91, 109, 91)
257257
assert (geometry_mapping.volume.transformation_matrix_voxel_indices_ijk_to_xyz.matrix ==
258-
expected_affine).all()
258+
expected_affine).all()
259259
assert geometry_mapping.volume.volume_dimensions == expected_dimensions
260260

261261

nibabel/tests/test_arraywriters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,12 @@ def test_dumber_writers():
610610
aw.slope = 2.0
611611
assert aw.slope == 2.0
612612
with pytest.raises(AttributeError):
613-
getattr(aw, 'inter')
613+
aw.inter
614614
aw = ArrayWriter(arr)
615615
with pytest.raises(AttributeError):
616-
getattr(aw, 'slope')
616+
aw.slope
617617
with pytest.raises(AttributeError):
618-
getattr(aw, 'inter')
618+
aw.inter
619619
# Attempt at scaling should raise error for dumb type
620620
with pytest.raises(WriterError):
621621
ArrayWriter(arr, np.int16)

nibabel/tests/test_files_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_files_interface():
5757
assert img.get_filename() == 'test.nii'
5858
assert img.file_map['image'].filename == 'test.nii'
5959
with pytest.raises(KeyError):
60-
img.file_map.__getitem__('header')
60+
img.file_map['header']
6161
# pair - note new class
6262
img = Nifti1Pair(arr, aff)
6363
img.set_filename('test')

nibabel/tests/test_image_load_save.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ def test_save_load():
137137
del re_img2
138138
spm99.save(img, sifn)
139139
re_img3 = nils.load(sifn)
140-
assert isinstance(re_img3,
141-
spm99.Spm99AnalyzeImage)
140+
assert isinstance(re_img3, spm99.Spm99AnalyzeImage)
142141
assert_array_equal(re_img3.get_fdata(), data)
143142
assert_array_equal(re_img3.affine, affine)
144143
ni1.save(re_img3, nifn)
@@ -301,30 +300,14 @@ def wat(hdr):
301300

302301
def test_guessed_image_type():
303302
# Test whether we can guess the image type from example files
304-
assert (nils.guessed_image_type(
305-
pjoin(DATA_PATH, 'example4d.nii.gz')) ==
306-
Nifti1Image)
307-
assert (nils.guessed_image_type(
308-
pjoin(DATA_PATH, 'nifti1.hdr')) ==
309-
Nifti1Pair)
310-
assert (nils.guessed_image_type(
311-
pjoin(DATA_PATH, 'example_nifti2.nii.gz')) ==
312-
Nifti2Image)
313-
assert (nils.guessed_image_type(
314-
pjoin(DATA_PATH, 'nifti2.hdr')) ==
315-
Nifti2Pair)
316-
assert (nils.guessed_image_type(
317-
pjoin(DATA_PATH, 'tiny.mnc')) ==
318-
Minc1Image)
319-
assert (nils.guessed_image_type(
320-
pjoin(DATA_PATH, 'small.mnc')) ==
321-
Minc2Image)
322-
assert (nils.guessed_image_type(
323-
pjoin(DATA_PATH, 'test.mgz')) ==
324-
MGHImage)
325-
assert (nils.guessed_image_type(
326-
pjoin(DATA_PATH, 'analyze.hdr')) ==
327-
Spm2AnalyzeImage)
303+
assert nils.guessed_image_type(pjoin(DATA_PATH, 'example4d.nii.gz')) == Nifti1Image
304+
assert nils.guessed_image_type(pjoin(DATA_PATH, 'nifti1.hdr')) == Nifti1Pair
305+
assert nils.guessed_image_type(pjoin(DATA_PATH, 'example_nifti2.nii.gz')) == Nifti2Image
306+
assert nils.guessed_image_type(pjoin(DATA_PATH, 'nifti2.hdr')) == Nifti2Pair
307+
assert nils.guessed_image_type(pjoin(DATA_PATH, 'tiny.mnc')) == Minc1Image
308+
assert nils.guessed_image_type(pjoin(DATA_PATH, 'small.mnc')) == Minc2Image
309+
assert nils.guessed_image_type(pjoin(DATA_PATH, 'test.mgz')) == MGHImage
310+
assert nils.guessed_image_type(pjoin(DATA_PATH, 'analyze.hdr')) == Spm2AnalyzeImage
328311

329312

330313
def test_fail_save():

nibabel/tests/test_nifti1.py

Lines changed: 86 additions & 85 deletions
Large diffs are not rendered by default.

nibabel/tests/test_nifti2.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ def test_eol_check(self):
4949
hdr['eol_check'] = 0
5050
fhdr, message, raiser = self.log_chk(hdr, 20)
5151
assert_array_equal(fhdr['eol_check'], good_eol)
52-
assert (message ==
53-
'EOL check all 0; '
54-
'setting EOL check to 13, 10, 26, 10')
52+
assert message == 'EOL check all 0; setting EOL check to 13, 10, 26, 10'
5553
hdr['eol_check'] = (13, 10, 0, 10)
5654
fhdr, message, raiser = self.log_chk(hdr, 40)
5755
assert_array_equal(fhdr['eol_check'], good_eol)
5856
assert (message ==
59-
'EOL check not 0 or 13, 10, 26, 10; '
60-
'data may be corrupted by EOL conversion; '
61-
'setting EOL check to 13, 10, 26, 10')
57+
'EOL check not 0 or 13, 10, 26, 10; '
58+
'data may be corrupted by EOL conversion; '
59+
'setting EOL check to 13, 10, 26, 10')
6260

6361

6462
class TestNifti2PairHeader(_Nifti2Mixin, TestNifti1PairHeader):

nibabel/tests/test_optpkg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def assert_bad(pkg_name, min_version=None):
2626
assert not have_pkg
2727
assert isinstance(pkg, TripWire)
2828
with pytest.raises(TripWireError):
29-
getattr(pkg, 'a_method')
29+
pkg.a_method
3030
with pytest.raises(SkipTest):
3131
setup()
3232

@@ -77,7 +77,6 @@ def test_versions():
7777
try:
7878
pkg.some_method
7979
except TripWireError as err:
80-
assert (str(err) ==
81-
'These functions need _a_fake_package version >= 3.0')
80+
assert str(err) == 'These functions need _a_fake_package version >= 3.0'
8281
finally:
8382
del sys.modules[fake_name]

nibabel/tests/test_orientations.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -267,25 +267,25 @@ def test_ornt2axcodes():
267267
# Recoding orientation to axis codes
268268
labels = (('left', 'right'), ('back', 'front'), ('down', 'up'))
269269
assert ornt2axcodes([[0, 1],
270-
[1, 1],
271-
[2, 1]], labels) == ('right', 'front', 'up')
270+
[1, 1],
271+
[2, 1]], labels) == ('right', 'front', 'up')
272272
assert ornt2axcodes([[0, -1],
273-
[1, -1],
274-
[2, -1]], labels) == ('left', 'back', 'down')
273+
[1, -1],
274+
[2, -1]], labels) == ('left', 'back', 'down')
275275
assert ornt2axcodes([[2, -1],
276-
[1, -1],
277-
[0, -1]], labels) == ('down', 'back', 'left')
276+
[1, -1],
277+
[0, -1]], labels) == ('down', 'back', 'left')
278278
assert ornt2axcodes([[1, 1],
279-
[2, -1],
280-
[0, 1]], labels) == ('front', 'down', 'right')
279+
[2, -1],
280+
[0, 1]], labels) == ('front', 'down', 'right')
281281
# default is RAS output directions
282282
assert ornt2axcodes([[0, 1],
283-
[1, 1],
284-
[2, 1]]) == ('R', 'A', 'S')
283+
[1, 1],
284+
[2, 1]]) == ('R', 'A', 'S')
285285
# dropped axes produce None
286286
assert ornt2axcodes([[0, 1],
287-
[np.nan, np.nan],
288-
[2, 1]]) == ('R', None, 'S')
287+
[np.nan, np.nan],
288+
[2, 1]]) == ('R', None, 'S')
289289
# Non integer axes raises error
290290
with pytest.raises(ValueError):
291291
ornt2axcodes([[0.1, 1]])
@@ -365,10 +365,8 @@ def test_axcodes2ornt():
365365
def test_aff2axcodes():
366366
assert aff2axcodes(np.eye(4)) == tuple('RAS')
367367
aff = [[0, 1, 0, 10], [-1, 0, 0, 20], [0, 0, 1, 30], [0, 0, 0, 1]]
368-
assert (aff2axcodes(aff, (('L', 'R'), ('B', 'F'), ('D', 'U'))) ==
369-
('B', 'R', 'U'))
370-
assert (aff2axcodes(aff, (('L', 'R'), ('B', 'F'), ('D', 'U'))) ==
371-
('B', 'R', 'U'))
368+
assert aff2axcodes(aff, (('L', 'R'), ('B', 'F'), ('D', 'U'))) == ('B', 'R', 'U')
369+
assert aff2axcodes(aff, (('L', 'R'), ('B', 'F'), ('D', 'U'))) == ('B', 'R', 'U')
372370

373371

374372
def test_inv_ornt_aff():

nibabel/tests/test_parrec.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ def test_sorting_multiple_echos_and_contrasts():
345345
np.arange(1, nslices+1))
346346
current_echo = slice_offset % nechos + 1
347347
# same echo for each slice in the group
348-
assert (np.all(sorted_echos[istart:iend] == current_echo) ==
349-
True)
348+
assert np.all(sorted_echos[istart:iend] == current_echo)
350349
# outermost sort index is image_type_mr
351350
assert np.all(sorted_types[:ntotal//4] == 0)
352351
assert np.all(sorted_types[ntotal//4:ntotal//2] == 1)
@@ -403,8 +402,7 @@ def test_sorting_multiecho_ASL():
403402

404403
# check volume labels
405404
vol_labels = asl_hdr.get_volume_labels()
406-
assert (list(vol_labels.keys()) ==
407-
['echo number', 'label type', 'dynamic scan number'])
405+
assert list(vol_labels.keys()) == ['echo number', 'label type', 'dynamic scan number']
408406
assert_array_equal(vol_labels['dynamic scan number'], [1]*6 + [2]*6)
409407
assert_array_equal(vol_labels['label type'], [1]*3 + [2]*3 + [1]*3 + [2]*3)
410408
assert_array_equal(vol_labels['echo number'], [1, 2, 3]*4)

nibabel/tests/test_processing.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,11 @@ def test_resample_to_output():
287287
img_ni1 = Nifti2Image(data, np.eye(4))
288288
img_ni2 = Nifti2Image(data, np.eye(4))
289289
# Default is Nifti1Image
290-
assert (
291-
resample_to_output(img_ni2).__class__ ==
292-
Nifti1Image)
290+
assert resample_to_output(img_ni2).__class__ == Nifti1Image
293291
# Can be overriden
294-
assert (
295-
resample_to_output(img_ni1, out_class=Nifti2Image).__class__ ==
296-
Nifti2Image)
292+
assert resample_to_output(img_ni1, out_class=Nifti2Image).__class__ == Nifti2Image
297293
# None specifies out_class from input
298-
assert (
299-
resample_to_output(img_ni2, out_class=None).__class__ ==
300-
Nifti2Image)
294+
assert resample_to_output(img_ni2, out_class=None).__class__ == Nifti2Image
301295

302296

303297
@needs_scipy
@@ -347,17 +341,11 @@ def test_smooth_image():
347341
img_ni1 = Nifti2Image(data, np.eye(4))
348342
img_ni2 = Nifti2Image(data, np.eye(4))
349343
# Default is Nifti1Image
350-
assert (
351-
smooth_image(img_ni2, 0).__class__ ==
352-
Nifti1Image)
344+
assert smooth_image(img_ni2, 0).__class__ == Nifti1Image
353345
# Can be overriden
354-
assert (
355-
smooth_image(img_ni1, 0, out_class=Nifti2Image).__class__ ==
356-
Nifti2Image)
346+
assert smooth_image(img_ni1, 0, out_class=Nifti2Image).__class__ == Nifti2Image
357347
# None specifies out_class from input
358-
assert (
359-
smooth_image(img_ni2, 0, out_class=None).__class__ ==
360-
Nifti2Image)
348+
assert smooth_image(img_ni2, 0, out_class=None).__class__ == Nifti2Image
361349

362350

363351
@needs_scipy

0 commit comments

Comments
 (0)