Skip to content

Commit b2f40bd

Browse files
committed
TEST: De-indent tests, cleanup style
1 parent 78f8e71 commit b2f40bd

File tree

1 file changed

+53
-77
lines changed

1 file changed

+53
-77
lines changed

nibabel/tests/test_filename_parser.py

Lines changed: 53 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -18,83 +18,59 @@ def test_filenames():
1818
types_exts = (('image', '.img'), ('header', '.hdr'))
1919
for t_fname in ('test.img', 'test.hdr', 'test', 'test.'):
2020
tfns = types_filenames(t_fname, types_exts)
21-
assert (tfns ==
22-
{'image': 'test.img',
23-
'header': 'test.hdr'})
24-
# enforcing extensions raises an error for bad extension
25-
with pytest.raises(TypesFilenamesError):
26-
types_filenames('test.funny', types_exts)
27-
# If not enforcing extensions, it does the best job it can,
28-
# assuming the passed filename is for the first type (in this case
29-
# 'image')
30-
tfns = types_filenames('test.funny', types_exts,
31-
enforce_extensions=False)
32-
assert (tfns ==
33-
{'header': 'test.hdr',
34-
'image': 'test.funny'})
35-
# .gz and .bz2 suffixes to extensions, by default, are removed
36-
# before extension checking etc, and then put back onto every
37-
# returned filename.
38-
tfns = types_filenames('test.img.gz', types_exts)
39-
assert (tfns ==
40-
{'header': 'test.hdr.gz',
41-
'image': 'test.img.gz'})
42-
tfns = types_filenames('test.img.bz2', types_exts)
43-
assert (tfns ==
44-
{'header': 'test.hdr.bz2',
45-
'image': 'test.img.bz2'})
46-
# of course, if we don't know about e.g. gz, and enforce_extensions
47-
# is on, we get an errror
48-
with pytest.raises(TypesFilenamesError):
49-
types_filenames('test.img.gz', types_exts, ())
50-
# if we don't know about .gz extension, and not enforcing, then we
51-
# get something a bit odd
52-
tfns = types_filenames('test.img.gz', types_exts,
53-
trailing_suffixes=(),
54-
enforce_extensions=False)
55-
assert (tfns ==
56-
{'header': 'test.img.hdr',
57-
'image': 'test.img.gz'})
58-
# the suffixes we remove and replaces can be any suffixes.
59-
tfns = types_filenames('test.img.bzr', types_exts, ('.bzr',))
60-
assert (tfns ==
61-
{'header': 'test.hdr.bzr',
62-
'image': 'test.img.bzr'})
63-
# If we specifically pass the remove / replace suffixes, then we
64-
# don't remove / replace the .gz and .bz2, unless they are passed
65-
# specifically.
66-
tfns = types_filenames('test.img.bzr', types_exts,
67-
trailing_suffixes=('.bzr',),
68-
enforce_extensions=False)
69-
assert (tfns ==
70-
{'header': 'test.hdr.bzr',
71-
'image': 'test.img.bzr'})
72-
# but, just .gz or .bz2 as extension gives an error, if enforcing is on
73-
with pytest.raises(TypesFilenamesError):
74-
types_filenames('test.gz', types_exts)
75-
with pytest.raises(TypesFilenamesError):
76-
types_filenames('test.bz2', types_exts)
77-
# if enforcing is off, it tries to work out what the other files
78-
# should be assuming the passed filename is of the first input type
79-
tfns = types_filenames('test.gz', types_exts,
80-
enforce_extensions=False)
81-
assert (tfns ==
82-
{'image': 'test.gz',
83-
'header': 'test.hdr.gz'})
84-
# case (in)sensitivity, and effect of uppercase, lowercase
85-
tfns = types_filenames('test.IMG', types_exts)
86-
assert (tfns ==
87-
{'image': 'test.IMG',
88-
'header': 'test.HDR'})
89-
tfns = types_filenames('test.img',
90-
(('image', '.IMG'), ('header', '.HDR')))
91-
assert (tfns ==
92-
{'header': 'test.hdr',
93-
'image': 'test.img'})
94-
tfns = types_filenames('test.IMG.Gz', types_exts)
95-
assert (tfns ==
96-
{'image': 'test.IMG.Gz',
97-
'header': 'test.HDR.Gz'})
21+
assert tfns == {'image': 'test.img', 'header': 'test.hdr'}
22+
# enforcing extensions raises an error for bad extension
23+
with pytest.raises(TypesFilenamesError):
24+
types_filenames('test.funny', types_exts)
25+
# If not enforcing extensions, it does the best job it can,
26+
# assuming the passed filename is for the first type (in this case
27+
# 'image')
28+
tfns = types_filenames('test.funny', types_exts, enforce_extensions=False)
29+
assert tfns == {'header': 'test.hdr', 'image': 'test.funny'}
30+
# .gz and .bz2 suffixes to extensions, by default, are removed
31+
# before extension checking etc, and then put back onto every
32+
# returned filename.
33+
tfns = types_filenames('test.img.gz', types_exts)
34+
assert tfns == {'header': 'test.hdr.gz', 'image': 'test.img.gz'}
35+
tfns = types_filenames('test.img.bz2', types_exts)
36+
assert tfns == {'header': 'test.hdr.bz2', 'image': 'test.img.bz2'}
37+
# of course, if we don't know about e.g. gz, and enforce_extensions
38+
# is on, we get an errror
39+
with pytest.raises(TypesFilenamesError):
40+
types_filenames('test.img.gz', types_exts, ())
41+
# if we don't know about .gz extension, and not enforcing, then we
42+
# get something a bit odd
43+
tfns = types_filenames('test.img.gz', types_exts,
44+
trailing_suffixes=(),
45+
enforce_extensions=False)
46+
assert tfns == {'header': 'test.img.hdr', 'image': 'test.img.gz'}
47+
# the suffixes we remove and replaces can be any suffixes.
48+
tfns = types_filenames('test.img.bzr', types_exts, ('.bzr',))
49+
assert tfns == {'header': 'test.hdr.bzr', 'image': 'test.img.bzr'}
50+
# If we specifically pass the remove / replace suffixes, then we
51+
# don't remove / replace the .gz and .bz2, unless they are passed
52+
# specifically.
53+
tfns = types_filenames('test.img.bzr', types_exts,
54+
trailing_suffixes=('.bzr',),
55+
enforce_extensions=False)
56+
assert tfns == {'header': 'test.hdr.bzr', 'image': 'test.img.bzr'}
57+
# but, just .gz or .bz2 as extension gives an error, if enforcing is on
58+
with pytest.raises(TypesFilenamesError):
59+
types_filenames('test.gz', types_exts)
60+
with pytest.raises(TypesFilenamesError):
61+
types_filenames('test.bz2', types_exts)
62+
# if enforcing is off, it tries to work out what the other files
63+
# should be assuming the passed filename is of the first input type
64+
tfns = types_filenames('test.gz', types_exts,
65+
enforce_extensions=False)
66+
assert tfns == {'image': 'test.gz', 'header': 'test.hdr.gz'}
67+
# case (in)sensitivity, and effect of uppercase, lowercase
68+
tfns = types_filenames('test.IMG', types_exts)
69+
assert tfns == {'image': 'test.IMG', 'header': 'test.HDR'}
70+
tfns = types_filenames('test.img', (('image', '.IMG'), ('header', '.HDR')))
71+
assert tfns == {'header': 'test.hdr', 'image': 'test.img'}
72+
tfns = types_filenames('test.IMG.Gz', types_exts)
73+
assert tfns == {'image': 'test.IMG.Gz', 'header': 'test.HDR.Gz'}
9874

9975

10076
def test_parse_filename():

0 commit comments

Comments
 (0)