-
Notifications
You must be signed in to change notification settings - Fork 300
PP constraint #1237
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
PP constraint #1237
Changes from all commits
Commits
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
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
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
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
53 changes: 53 additions & 0 deletions
53
lib/iris/tests/unit/fileformats/pp/test__convert_constraints.py
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,53 @@ | ||
| # (C) British Crown Copyright 2014, 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.fileformats.pp.load` function.""" | ||
|
|
||
| # Import iris.tests first so that some things can be initialised before | ||
| # importing anything else. | ||
| import iris.tests as tests | ||
|
|
||
| import mock | ||
|
|
||
| import iris | ||
| from iris.fileformats.pp import _convert_constraints | ||
| from iris.fileformats.pp import STASH | ||
|
|
||
|
|
||
| class Test_convert_constraints(tests.IrisTest): | ||
| def test_single_stash(self): | ||
| stcube = mock.Mock(stash=STASH.from_msi('m01s03i236')) | ||
| constraint = iris.AttributeConstraint(STASH='m01s03i236') | ||
| pp_filter = _convert_constraints(constraint) | ||
| self.assertTrue(pp_filter(stcube)) | ||
|
|
||
| def test_multiple_with_stash(self): | ||
| constraints = [iris.Constraint('air_potential_temperature'), | ||
| iris.AttributeConstraint(STASH='m01s00i004')] | ||
| pp_filter = _convert_constraints(constraints) | ||
| stcube = mock.Mock(stash=STASH.from_msi('m01s00i004')) | ||
| self.assertTrue(pp_filter(stcube)) | ||
|
|
||
| def test_no_stash(self): | ||
| constraints = [iris.Constraint('air_potential_temperature'), | ||
| iris.AttributeConstraint(source='asource')] | ||
| pp_filter = _convert_constraints(constraints) | ||
| stcube = mock.Mock(stash=STASH.from_msi('m01s00i004')) | ||
| self.assertTrue(pp_filter(stcube)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| tests.main() |
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,61 @@ | ||
| # (C) British Crown Copyright 2014, 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 :func:`iris.fileformats.rules.load_cubes`.""" | ||
|
|
||
| # Import iris.tests first so that some things can be initialised before | ||
| # importing anything else. | ||
| import iris.tests as tests | ||
|
|
||
| import mock | ||
|
|
||
| import iris | ||
| from iris.fileformats import pp | ||
| from iris.fileformats.pp_rules import convert | ||
| from iris.fileformats.rules import load_cubes | ||
|
|
||
|
|
||
| class Test(tests.IrisTest): | ||
| def test_pp_with_stash_constraint(self): | ||
| filenames = [tests.get_data_path(('PP', 'globClim1', 'dec_subset.pp'))] | ||
| stcon = iris.AttributeConstraint(STASH='m01s00i004') | ||
| pp_constraints = pp._convert_constraints(stcon) | ||
| pp_loader = iris.fileformats.rules.Loader(pp.load, {}, | ||
| convert, pp._load_rules) | ||
| cubes = list(load_cubes(filenames, None, pp_loader, pp_constraints)) | ||
| self.assertEqual(len(cubes), 38) | ||
|
|
||
| def test_pp_with_stash_constraints(self): | ||
| filenames = [tests.get_data_path(('PP', 'globClim1', 'dec_subset.pp'))] | ||
| stcon1 = iris.AttributeConstraint(STASH='m01s00i004') | ||
| stcon2 = iris.AttributeConstraint(STASH='m01s00i010') | ||
| pp_constraints = pp._convert_constraints([stcon1, stcon2]) | ||
| pp_loader = iris.fileformats.rules.Loader(pp.load, {}, | ||
| convert, pp._load_rules) | ||
| cubes = list(load_cubes(filenames, None, pp_loader, pp_constraints)) | ||
| self.assertEqual(len(cubes), 76) | ||
|
|
||
| def test_pp_no_constraint(self): | ||
| filenames = [tests.get_data_path(('PP', 'globClim1', 'dec_subset.pp'))] | ||
| pp_constraints = pp._convert_constraints(None) | ||
| pp_loader = iris.fileformats.rules.Loader(pp.load, {}, | ||
| convert, pp._load_rules) | ||
| cubes = list(load_cubes(filenames, None, pp_loader, pp_constraints)) | ||
| self.assertEqual(len(cubes), 152) | ||
|
|
||
|
|
||
| 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.
Sorry, it's super-picky but please could we have a blank line before the closing
""".