-
Notifications
You must be signed in to change notification settings - Fork 300
Fix expand filespecs #2014
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
Closed
Closed
Fix expand filespecs #2014
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed40f0c
Added a unit test for expand filespecs.
davidnmurray 646413f
Changes to exapnd_filespec and a suitable test
davidnmurray 5c3e889
Edit for pep8 issues as seen by Travis
davidnmurray 4a6a2bb
Readability and pep8 compliance edits
davidnmurray e977709
Addition of sorting to account for dictionaries
davidnmurray f78d4d4
value_lists are now sorted prior to expansion
davidnmurray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # (C) British Crown Copyright 2016, Met Office | ||
| # | ||
| # This file is part of Iris. | ||
| # | ||
| # Iris is free software: you can redistribute it and/or modify it under | ||
| # the terms of the GNU Lesser General Public License as published by the | ||
| # Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # Iris is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with Iris. If not, see <http://www.gnu.org/licenses/>. | ||
| """Unit tests for the `iris.io.expand_filespecs` function.""" | ||
|
|
||
| from __future__ import (absolute_import, division, print_function) | ||
| from six.moves import (filter, input, map, range, zip) # noqa | ||
|
|
||
| # Import iris.tests first so that some things can be initialised before | ||
| # importing anything else. | ||
| import iris.tests as tests | ||
|
|
||
| import os | ||
| import tempfile | ||
| import shutil | ||
|
|
||
| import iris.io as iio | ||
|
|
||
|
|
||
| class TestExpandFilespecs(tests.IrisTest): | ||
|
|
||
| def setUp(self): | ||
| tests.IrisTest.setUp(self) | ||
| self.tmpdir = tempfile.mkdtemp() | ||
| self.fnames = ['a.foo', 'b.txt'] | ||
| for fname in self.fnames: | ||
| with open(os.path.join(self.tmpdir, fname), 'w') as fh: | ||
| fh.write('anything') | ||
|
|
||
| def tearDown(self): | ||
| shutil.rmtree(self.tmpdir) | ||
|
|
||
| def test_absolute_path(self): | ||
| result = iio.expand_filespecs([os.path.join(self.tmpdir, '*')]) | ||
| expected = [os.path.join(self.tmpdir, fname) for fname in self.fnames] | ||
| self.assertEqual(result, expected) | ||
|
|
||
| def test_double_slash(self): | ||
| product = iio.expand_filespecs(['//' + os.path.join(self.tmpdir, '*')]) | ||
| predicted = [os.path.join(self.tmpdir, fname) for fname in self.fnames] | ||
| self.assertEqual(product, predicted) | ||
|
|
||
| def test_relative_path(self): | ||
| os.chdir(self.tmpdir) | ||
| item_out = iio.expand_filespecs(['*']) | ||
| item_in = [os.path.join(self.tmpdir, fname) for fname in self.fnames] | ||
| self.assertEqual(item_out, item_in) | ||
|
|
||
| def test_no_files_found(self): | ||
| msg = 'b expanded to empty' | ||
| with self.assertRaisesRegexp(IOError, msg): | ||
| iio.expand_filespecs([self.tmpdir + '_b']) | ||
|
|
||
| def test_files_and_none(self): | ||
| msg = 'b expanded to empty.*expanded to .*b.txt' | ||
| with self.assertRaisesRegexp(IOError, msg): | ||
| iio.expand_filespecs([self.tmpdir + '_b', | ||
| os.path.join(self.tmpdir, '*')]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| tests.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we have completed this PR, I think we should look at making the sort order of the returned filenames consistent and expected. The behaviour I think we need: