Skip to content

Commit f5eb350

Browse files
authored
Merge branch 'master' into PGH
2 parents f7d505e + 26b81aa commit f5eb350

26 files changed

+75
-82
lines changed

nibabel/batteryrunners.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def __str__(self):
252252
def message(self):
253253
"""formatted message string, including fix message if present"""
254254
if self.fix_msg:
255-
return '; '.join((self.problem_msg, self.fix_msg))
255+
return f'{self.problem_msg}; {self.fix_msg}'
256256
return self.problem_msg
257257

258258
def log_raise(self, logger, error_level=40):

nibabel/cmdline/tests/test_convert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_convert_dtype(tmp_path, data_dtype):
7171

7272

7373
@pytest.mark.parametrize(
74-
'ext,img_class',
74+
('ext', 'img_class'),
7575
[
7676
('mgh', nib.MGHImage),
7777
('img', nib.Nifti1Pair),
@@ -94,7 +94,7 @@ def test_convert_by_extension(tmp_path, ext, img_class):
9494

9595

9696
@pytest.mark.parametrize(
97-
'ext,img_class',
97+
('ext', 'img_class'),
9898
[
9999
('mgh', nib.MGHImage),
100100
('img', nib.Nifti1Pair),
@@ -141,7 +141,7 @@ def test_convert_nifti_int_fail(tmp_path):
141141

142142

143143
@pytest.mark.parametrize(
144-
'orig_dtype,alias,expected_dtype',
144+
('orig_dtype', 'alias', 'expected_dtype'),
145145
[
146146
('int64', 'mask', 'uint8'),
147147
('int64', 'compat', 'int32'),

nibabel/cmdline/tests/test_roi.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_nib_roi(tmp_path, inplace):
119119

120120

121121
@pytest.mark.parametrize(
122-
'args, errmsg',
122+
('args', 'errmsg'),
123123
(
124124
(('-i', '1:1'), 'Cannot take zero-length slice'),
125125
(('-j', '1::2'), 'Downsampling is not supported'),
@@ -138,12 +138,8 @@ def test_nib_roi_bad_slices(capsys, args, errmsg):
138138
def test_entrypoint(capsys):
139139
# Check that we handle missing args as expected
140140
with mock.patch('sys.argv', ['nib-roi', '--help']):
141-
try:
141+
with pytest.raises(SystemExit):
142142
main()
143-
except SystemExit:
144-
pass
145-
else:
146-
assert False, 'argparse exits on --help. If changing to another parser, update test.'
147143
captured = capsys.readouterr()
148144
assert captured.out.startswith('usage: nib-roi')
149145

nibabel/data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ def list_files(self, relative=True):
8787
for base, dirs, files in os.walk(self.base_path):
8888
if relative:
8989
base = base[len(self.base_path) + 1 :]
90-
for filename in files:
91-
out_list.append(pjoin(base, filename))
90+
out_list.extend(pjoin(base, filename) for filename in files)
9291
return out_list
9392

9493

nibabel/gifti/gifti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def _to_xml_element(self):
374374
def print_summary(self):
375375
print('Dataspace: ', xform_codes.niistring[self.dataspace])
376376
print('XFormSpace: ', xform_codes.niistring[self.xformspace])
377-
print('Affine Transformation Matrix: \n', self.xform)
377+
print('Affine Transformation Matrix:\n', self.xform)
378378

379379

380380
def _data_tag_element(dataarray, encoding, dtype, ordering):

nibabel/gifti/tests/test_gifti.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,14 @@ def test_gifti_coord(capsys):
423423
gcs.xform = None
424424
gcs.print_summary()
425425
captured = capsys.readouterr()
426-
assert captured.out == '\n'.join(
427-
[
428-
'Dataspace: NIFTI_XFORM_UNKNOWN',
429-
'XFormSpace: NIFTI_XFORM_UNKNOWN',
430-
'Affine Transformation Matrix: ',
431-
' None\n',
432-
]
426+
assert (
427+
captured.out
428+
== """\
429+
Dataspace: NIFTI_XFORM_UNKNOWN
430+
XFormSpace: NIFTI_XFORM_UNKNOWN
431+
Affine Transformation Matrix:
432+
None
433+
"""
433434
)
434435
gcs.to_xml()
435436

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,9 @@ def fake_shape_dependents(
429429

430430
class PrintBase:
431431
def __repr__(self):
432-
attr_strs = []
433-
for attr in dir(self):
434-
if attr[0].isupper():
435-
attr_strs.append(f'{attr}={getattr(self, attr)}')
432+
attr_strs = [
433+
f'{attr}={getattr(self, attr)}' for attr in dir(self) if attr[0].isupper()
434+
]
436435
return f"{self.__class__.__name__}({', '.join(attr_strs)})"
437436

438437
class DimIdxSeqElem(pydicom.Dataset):

nibabel/nifti1.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,15 @@ class NiftiExtension(ty.Generic[T]):
325325
"""
326326

327327
code: int
328-
encoding: ty.Optional[str] = None
328+
encoding: str | None = None
329329
_content: bytes
330-
_object: ty.Optional[T] = None
330+
_object: T | None = None
331331

332332
def __init__(
333333
self,
334-
code: ty.Union[int, str],
334+
code: int | str,
335335
content: bytes = b'',
336-
object: ty.Optional[T] = None,
336+
object: T | None = None,
337337
) -> None:
338338
"""
339339
Parameters
@@ -565,9 +565,9 @@ class Nifti1DicomExtension(Nifti1Extension[DicomDataset]):
565565

566566
def __init__(
567567
self,
568-
code: ty.Union[int, str],
569-
content: ty.Union[bytes, DicomDataset, None] = None,
570-
parent_hdr: ty.Optional[Nifti1Header] = None,
568+
code: int | str,
569+
content: bytes | DicomDataset | None = None,
570+
parent_hdr: Nifti1Header | None = None,
571571
) -> None:
572572
"""
573573
Parameters

nibabel/streamlines/tests/test_streamlines.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ def test_save_tractogram_file(self):
191191
trk_file = trk.TrkFile(tractogram)
192192

193193
# No need for keyword arguments.
194-
with self.assertRaises(ValueError):
194+
with pytest.raises(ValueError):
195195
nib.streamlines.save(trk_file, 'dummy.trk', header={})
196196

197197
# Wrong extension.
198198
with pytest.warns(ExtensionWarning, match='extension'):
199199
trk_file = trk.TrkFile(tractogram)
200-
with self.assertRaises(ValueError):
200+
with pytest.raises(ValueError):
201201
nib.streamlines.save(trk_file, 'dummy.tck', header={})
202202

203203
with InTemporaryDirectory():
@@ -207,7 +207,7 @@ def test_save_tractogram_file(self):
207207

208208
def test_save_empty_file(self):
209209
tractogram = Tractogram(affine_to_rasmm=np.eye(4))
210-
for ext, cls in FORMATS.items():
210+
for ext in FORMATS:
211211
with InTemporaryDirectory():
212212
filename = 'streamlines' + ext
213213
nib.streamlines.save(tractogram, filename)
@@ -216,7 +216,7 @@ def test_save_empty_file(self):
216216

217217
def test_save_simple_file(self):
218218
tractogram = Tractogram(DATA['streamlines'], affine_to_rasmm=np.eye(4))
219-
for ext, cls in FORMATS.items():
219+
for ext in FORMATS:
220220
with InTemporaryDirectory():
221221
filename = 'streamlines' + ext
222222
nib.streamlines.save(tractogram, filename)
@@ -262,7 +262,7 @@ def test_save_complex_file(self):
262262
def test_save_sliced_tractogram(self):
263263
tractogram = Tractogram(DATA['streamlines'], affine_to_rasmm=np.eye(4))
264264
original_tractogram = tractogram.copy()
265-
for ext, cls in FORMATS.items():
265+
for ext in FORMATS:
266266
with InTemporaryDirectory():
267267
filename = 'streamlines' + ext
268268
nib.streamlines.save(tractogram[::2], filename)
@@ -272,18 +272,18 @@ def test_save_sliced_tractogram(self):
272272
assert_tractogram_equal(tractogram, original_tractogram)
273273

274274
def test_load_unknown_format(self):
275-
with self.assertRaises(ValueError):
275+
with pytest.raises(ValueError):
276276
nib.streamlines.load('')
277277

278278
def test_save_unknown_format(self):
279-
with self.assertRaises(ValueError):
279+
with pytest.raises(ValueError):
280280
nib.streamlines.save(Tractogram(), '')
281281

282282
def test_save_from_generator(self):
283283
tractogram = Tractogram(DATA['streamlines'], affine_to_rasmm=np.eye(4))
284284

285285
# Just to create a generator
286-
for ext, _ in FORMATS.items():
286+
for ext in FORMATS:
287287
filtered = (s for s in tractogram.streamlines if True)
288288
lazy_tractogram = LazyTractogram(lambda: filtered, affine_to_rasmm=np.eye(4))
289289

nibabel/testing/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def bytesio_filemap(klass):
1515
"""Return bytes io filemap for this image class `klass`"""
1616
file_map = klass.make_file_map()
17-
for name, fileholder in file_map.items():
17+
for fileholder in file_map.values():
1818
fileholder.fileobj = BytesIO()
1919
fileholder.pos = 0
2020
return file_map

0 commit comments

Comments
 (0)