Skip to content

Reduce exception message for loading missing files. #2925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/iris/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2010 - 2017, Met Office
# (C) British Crown Copyright 2010 - 2018, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -169,11 +169,10 @@ def expand_filespecs(file_specs):
msg = "One or more of the files specified did not exist:"
for pattern, expanded in six.iteritems(glob_expanded):
if expanded:
file_list = '\n - {}'.format(', '.join(expanded))
msg += '\n - "{}" matched {} file(s)'.format(pattern,
len(expanded))
else:
file_list = ''
msg += '\n - "{}" matched {} file(s){}'.format(
pattern, len(expanded), file_list)
msg += '\n * "{}" didn\'t match any files'.format(pattern)
raise IOError(msg)

return [fname for fnames in all_expanded for fname in fnames]
Expand Down
7 changes: 3 additions & 4 deletions lib/iris/tests/unit/io/test_expand_filespecs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2017, Met Office
# (C) British Crown Copyright 2017 - 2018, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_return_order(self):
self.assertEqual(result, expected[::-1])

def test_no_files_found(self):
msg = r'\/no_exist.txt\" matched 0 file\(s\)'
msg = r'\/no_exist.txt\" didn\'t match any files'
with self.assertRaisesRegexp(IOError, msg):
iio.expand_filespecs([os.path.join(self.tmpdir, 'no_exist.txt')])

Expand All @@ -91,9 +91,8 @@ def test_files_and_none(self):
os.path.join(self.tmpdir, '*')])
expected = textwrap.dedent("""
One or more of the files specified did not exist:
- "{0}/does_not_exist.txt" matched 0 file(s)
* "{0}/does_not_exist.txt" didn\'t match any files
- "{0}/*" matched 2 file(s)
- {0}/a.foo, {0}/b.txt
""").strip().format(self.tmpdir)

self.assertStringEqual(str(err.exception), expected)
Expand Down