Skip to content

Commit 366fa0e

Browse files
committed
Use FileNotFoundError. Implement in py3k for Python 2 compatibility.
1 parent 65e8932 commit 366fa0e

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

nibabel/loadsave.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .filebasedimages import ImageFileError
1919
from .imageclasses import all_image_classes
2020
from .arrayproxy import is_proxy
21-
21+
from .py3k import FileNotFoundError
2222

2323
def load(filename, **kwargs):
2424
''' Load file given filename, guessing at file type
@@ -36,7 +36,7 @@ def load(filename, **kwargs):
3636
Image of guessed type
3737
'''
3838
if not op.exists(filename):
39-
raise IOError("No such file: '%s'" % filename)
39+
raise FileNotFoundError("No such file: '%s'" % filename)
4040
sniff = None
4141
for image_klass in all_image_classes:
4242
is_valid, sniff = image_klass.path_maybe_image(filename, sniff)

nibabel/py3k.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def open_latin1(filename, mode='r'):
4040
strchar = 'U'
4141
ints2bytes = lambda seq: bytes(seq)
4242
ZEROB = bytes([0])
43+
FileNotFoundError = FileNotFoundError
4344
else:
4445
import StringIO
4546
StringIO = BytesIO = StringIO.StringIO
@@ -62,6 +63,8 @@ def open_latin1(filename, mode='r'):
6263
ints2bytes = lambda seq: ''.join(chr(i) for i in seq)
6364
ZEROB = chr(0)
6465

66+
class FileNotFoundError(IOError):
67+
pass
6568

6669
def getexception():
6770
return sys.exc_info()[1]

nibabel/tests/test_loadsave.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from nose.tools import (assert_true, assert_false, assert_raises,
2424
assert_equal, assert_not_equal)
25+
from ..py3k import FileNotFoundError
2526

2627
data_path = pjoin(dirname(__file__), 'data')
2728

@@ -54,7 +55,7 @@ def test_read_img_data():
5455

5556

5657
def test_file_not_found():
57-
assert_raises(IOError, load, 'does_not_exist.nii.gz')
58+
assert_raises(FileNotFoundError, load, 'does_not_exist.nii.gz')
5859

5960

6061
def test_read_img_data_nifti():

0 commit comments

Comments
 (0)