-
Notifications
You must be signed in to change notification settings - Fork 2
Initial ACDD Tests #65
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
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
588df34
Initial ACDD Tests
abkfenris f22a39b
Clean up initial ACDD rules
abkfenris 2be2967
Switch pyproject back to optional-dependencies
abkfenris a62900d
Update tests/plugins/acdd/rules/test_attributes.py
abkfenris 69937a2
Fix reccomended misspellings
abkfenris 0ee6c0d
Merge branch 'main' into acdd
forman 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import xarray as xr | ||
| from xrlint.testing import RuleTest, RuleTester | ||
|
|
||
| from xrlint.plugins.acdd.rules.attributes import ( | ||
| Attributes_1_3_Highly_Reccomended, | ||
| ) | ||
|
|
||
| valid_1_3_highly_rec_dataset = xr.Dataset( | ||
| attrs={ | ||
| "title": "Tis only a test", | ||
| "summary": "This is only a test dataset.", | ||
| "keywords": "test, example, sample", | ||
| "Conventions": "ACDD-1.3", | ||
| }, | ||
| ) | ||
| invalid_1_3_highly_rec_dataset = xr.Dataset() | ||
|
|
||
|
|
||
| Attributes_1_3_Highly_ReccomendedTest = RuleTester.define_test( | ||
| "1.3-attrs-highly-recommended", | ||
| Attributes_1_3_Highly_Reccomended, | ||
| valid=[RuleTest(dataset=valid_1_3_highly_rec_dataset)], | ||
| invalid=[ | ||
| RuleTest( | ||
| dataset=invalid_1_3_highly_rec_dataset, | ||
| expected=[ | ||
| "Missing highly recommended attribute 'title'", | ||
| "Missing highly recommended attribute 'keywords'", | ||
| "Missing highly recommended attribute 'summary'", | ||
| "Missing highly recommended attribute 'Conventions'", | ||
| ], | ||
| ), | ||
| ], | ||
| ) | ||
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,35 @@ | ||
| import xarray as xr | ||
| from xrlint.testing import RuleTest, RuleTester | ||
|
|
||
| from xrlint.plugins.acdd.rules.conventions import Conventions | ||
|
|
||
| valid_dataset_0 = xr.Dataset(attrs={"Conventions": "ACDD-1.3"}) | ||
|
|
||
| invalid_dataset_0 = xr.Dataset() | ||
| invalid_dataset_1 = xr.Dataset(attrs={"Conventions": "ACDD-1.2"}) | ||
| invalid_dataset_2 = xr.Dataset(attrs={"Conventions": 1.3}) | ||
|
|
||
|
|
||
| ConventionsTest = RuleTester.define_test( | ||
| "1.3-conventions", | ||
| Conventions, | ||
| valid=[ | ||
| RuleTest(dataset=valid_dataset_0), | ||
| ], | ||
| invalid=[ | ||
| RuleTest( | ||
| dataset=invalid_dataset_0, | ||
| expected=["Missing attribute 'Conventions'."], | ||
| ), | ||
| RuleTest( | ||
| dataset=invalid_dataset_1, | ||
| expected=[ | ||
| "Attribute 'Conventions' needs to contain 'ACDD-1.3' in addition to the current: 'ACDD-1.2'", | ||
| ], | ||
| ), | ||
| RuleTest( | ||
| dataset=invalid_dataset_2, | ||
| expected=["Invalid attribute 'Conventions': 1.3"], | ||
| ), | ||
| ], | ||
| ) |
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,26 @@ | ||
| import xarray as xr | ||
| from xrlint.testing import RuleTest, RuleTester | ||
|
|
||
| from xrlint.plugins.acdd.rules.no_id_blanks import NoBlanksInID | ||
|
|
||
| valid_dataset_0 = xr.Dataset(attrs={"id": "testing_dataset"}) | ||
|
|
||
| invalid_dataset_0 = xr.Dataset() | ||
| invalid_dataset_1 = xr.Dataset(attrs={"id": "testing dataset"}) | ||
|
|
||
|
|
||
| IdBlanksTest = RuleTester.define_test( | ||
| "1.3-no-blanks-in-id", | ||
| NoBlanksInID, | ||
| valid=[RuleTest(dataset=valid_dataset_0)], | ||
| invalid=[ | ||
| RuleTest( | ||
| dataset=invalid_dataset_0, | ||
| expected=["Missing attribute 'id'"], | ||
| ), | ||
| RuleTest( | ||
| dataset=invalid_dataset_1, | ||
| expected=["There should not be blanks in the id field"], | ||
| ), | ||
| ], | ||
| ) |
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 @@ | ||
| import xarray as xr | ||
| from xrlint.testing import RuleTest, RuleTester | ||
|
|
||
| from xrlint.plugins.acdd.rules.iso_dates import IsoDates | ||
|
|
||
| valid_dataset_0 = xr.Dataset(attrs={"date_created": "2023-10-05T12:34:56Z"}) | ||
| valid_dataset_1 = xr.Dataset(attrs={"date_modified": "2023-10-05"}) | ||
| valid_dataset_2 = xr.Dataset(attrs={"date_issued": "2023-10-05T12:34:56+00:00"}) | ||
| valid_dataset_3 = xr.Dataset( | ||
| attrs={"date_metadata_modified": "2023-10-05T12:34:56-05:00"}, | ||
| ) | ||
| valid_dataset_4 = xr.Dataset() # No date attributes | ||
|
|
||
|
|
||
| invalid_dataset_0 = xr.Dataset(attrs={"date_created": "10/05/2023"}) | ||
| invalid_dataset_1 = xr.Dataset(attrs={"date_issued": "2023-13-05"}) | ||
| invalid_dataset_2 = xr.Dataset(attrs={"date_modified": "2023-10-05 12:34:56"}) | ||
| invalid_dataset_3 = xr.Dataset(attrs={"date_metadata_modified": "2023/10/05"}) | ||
| invalid_dataset_4 = xr.Dataset( | ||
| attrs={"date_created": "2023-10-05T25:34:56Z"}, | ||
| ) # Invalid hour | ||
|
|
||
| IsoDatesTest = RuleTester.define_test( | ||
| "1.3-dates-iso-format", | ||
| IsoDates, | ||
| valid=[ | ||
| RuleTest(dataset=valid_dataset_0), | ||
| RuleTest(dataset=valid_dataset_1), | ||
| RuleTest(dataset=valid_dataset_2), | ||
| RuleTest(dataset=valid_dataset_3), | ||
| RuleTest(dataset=valid_dataset_4), | ||
| ], | ||
| invalid=[ | ||
| RuleTest( | ||
| dataset=invalid_dataset_0, | ||
| expected=["Attribute 'date_created' is not in ISO format: '10/05/2023'"], | ||
| ), | ||
| RuleTest( | ||
| dataset=invalid_dataset_1, | ||
| expected=["Attribute 'date_issued' is not in ISO format: '2023-13-05'"], | ||
| ), | ||
| RuleTest( | ||
| dataset=invalid_dataset_2, | ||
| expected=[ | ||
| "Attribute 'date_modified' is not in ISO format: '2023-10-05 12:34:56'", | ||
| ], | ||
| ), | ||
| RuleTest( | ||
| dataset=invalid_dataset_3, | ||
| expected=[ | ||
| "Attribute 'date_metadata_modified' is not in ISO format: '2023/10/05'", | ||
| ], | ||
| ), | ||
| RuleTest( | ||
| dataset=invalid_dataset_4, | ||
| expected=[ | ||
| "Attribute 'date_created' is not in ISO format: '2023-10-05T25:34:56Z'", | ||
| ], | ||
| ), | ||
| ], | ||
| ) |
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,28 @@ | ||
| import xarray as xr | ||
| from xrlint.testing import RuleTest, RuleTester | ||
|
|
||
| from xrlint.plugins.acdd.rules.metadata_link import MetadataLink | ||
|
|
||
| valid_dataset_0 = xr.Dataset(attrs={"metadata_link": "http://example.com/metadata"}) | ||
| valid_dataset_1 = xr.Dataset(attrs={"metadata_link": "https://example.com/metadata"}) | ||
| valid_dataset_2 = xr.Dataset() | ||
|
|
||
| invalid_dataset_0 = xr.Dataset(attrs={"metadata_link": "example.com/metadata"}) | ||
|
|
||
| Metadata_LinkTest = RuleTester.define_test( | ||
| "1.3-metadata-link", | ||
| MetadataLink, | ||
| valid=[ | ||
| RuleTest(dataset=valid_dataset_0), | ||
| RuleTest(dataset=valid_dataset_1), | ||
| RuleTest(dataset=valid_dataset_2), | ||
| ], | ||
| invalid=[ | ||
| RuleTest( | ||
| dataset=invalid_dataset_0, | ||
| expected=[ | ||
| "Metadata URL should include http:// or https://: 'example.com/metadata'", | ||
| ], | ||
| ), | ||
| ], | ||
| ) |
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,38 @@ | ||
| from unittest import TestCase | ||
|
|
||
| from xrlint.plugins.acdd import export_plugin | ||
|
|
||
|
|
||
| class TestACDDPlugin(TestCase): | ||
| def test_rules_complete(self): | ||
| plugin = export_plugin() | ||
| self.assertEqual( | ||
| { | ||
| "1.3-conventions", | ||
| "1.0-attrs-suggested", | ||
| "1.0-attrs-highly-recommended", | ||
| "1.0-attrs-recommended", | ||
| "1.3-attrs-recommended", | ||
| "1.3-attrs-suggested", | ||
| "1.3-attrs-highly-recommended", | ||
| "1.3-no-blanks-in-id", | ||
| "1.3-metadata-link", | ||
| "1.3-dates-iso-format", | ||
| }, | ||
| set(plugin.rules.keys()), | ||
| ) | ||
|
|
||
| def test_configs_complete(self): | ||
| plugin = export_plugin() | ||
| self.assertEqual( | ||
| { | ||
| "recommended", | ||
| "acdd_1.3", | ||
| "acdd_1.3_strict_reccomended", | ||
| "acdd_1.3_strict", | ||
| "acdd_1.3_warn", | ||
| "acdd_1.1", | ||
| "acdd_1.0", | ||
| }, | ||
| set(plugin.configs.keys()), | ||
| ) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.