-
Notifications
You must be signed in to change notification settings - Fork 92
first test for data inventory #1684
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
Open
LOCEANlloydizard
wants to merge
3
commits into
echostack-org:main
Choose a base branch
from
LOCEANlloydizard:test-data-inventory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| #!/usr/bin/env python3 | ||
| """Validate the test data inventory against the Pooch test-data bundles.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import ast | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import yaml | ||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
|
|
||
| CONFTST = ROOT / "echopype" / "tests" / "conftest.py" | ||
| INVENTORY = ROOT / "docs" / "source" / "test_data_inventory.yml" | ||
|
|
||
|
|
||
| REQUIRED_BUNDLE_KEYS = { | ||
| "documented_checksum", | ||
| "instrument", | ||
| "description", | ||
| "source", | ||
| "contributor", | ||
| "references", | ||
| "notes", | ||
| "files", | ||
| } | ||
|
|
||
| REQUIRED_FILE_KEYS = { | ||
| "instrument", | ||
| "description", | ||
| "source", | ||
| "contributor", | ||
| "references", | ||
| "notes", | ||
| } | ||
|
|
||
|
|
||
| def load_conftest_bundles_and_registry(): | ||
| source = CONFTST.read_text(encoding="utf-8") | ||
| tree = ast.parse(source) | ||
|
|
||
| bundles = None | ||
| registry = None | ||
|
|
||
| for node in ast.walk(tree): | ||
| if not isinstance(node, ast.Assign): | ||
| continue | ||
|
|
||
| for target in node.targets: | ||
| if isinstance(target, ast.Name) and target.id == "bundles": | ||
| bundles = ast.literal_eval(node.value) | ||
| elif isinstance(target, ast.Name) and target.id == "registry": | ||
| registry = ast.literal_eval(node.value) | ||
|
|
||
| if bundles is None: | ||
| raise RuntimeError(f"Could not find 'bundles' in {CONFTST}") | ||
|
|
||
| if registry is None: | ||
| raise RuntimeError(f"Could not find 'registry' in {CONFTST}") | ||
|
|
||
| return bundles, registry | ||
|
|
||
|
|
||
| def load_inventory(): | ||
| with INVENTORY.open(encoding="utf-8") as f: | ||
| return yaml.safe_load(f) | ||
|
|
||
|
|
||
| def main(): | ||
| bundles, registry = load_conftest_bundles_and_registry() | ||
| inventory = load_inventory() | ||
|
|
||
| errors = [] | ||
|
|
||
| conftest_bundles = set(bundles) | ||
| inventory_bundles = set(inventory) | ||
|
|
||
| missing = sorted(conftest_bundles - inventory_bundles) | ||
| if missing: | ||
| errors.append( | ||
| "Bundles listed in conftest.py but missing from inventory:\n - " | ||
| + "\n - ".join(missing) | ||
| ) | ||
|
|
||
| extra = sorted(inventory_bundles - conftest_bundles) | ||
| if extra: | ||
| errors.append( | ||
| "Bundles listed in inventory but not in conftest.py:\n - " + "\n - ".join(extra) | ||
| ) | ||
|
|
||
| for bundle in sorted(conftest_bundles & inventory_bundles): | ||
| metadata = inventory[bundle] | ||
|
|
||
| missing_keys = REQUIRED_BUNDLE_KEYS - set(metadata) | ||
| if missing_keys: | ||
| errors.append( | ||
| f"{bundle}: missing required bundle keys: " + ", ".join(sorted(missing_keys)) | ||
| ) | ||
|
|
||
| checksum = metadata.get("documented_checksum") | ||
| if checksum is not None and checksum != registry[bundle]: | ||
| errors.append( | ||
| f"{bundle}: documented_checksum does not match conftest.py registry\n" | ||
| f" inventory: {checksum}\n" | ||
| f" registry: {registry[bundle]}" | ||
| ) | ||
|
|
||
| files = metadata.get("files", {}) | ||
| if files is None: | ||
| errors.append(f"{bundle}: files must be a mapping, not null") | ||
| continue | ||
|
|
||
| for filename, file_metadata in files.items(): | ||
| missing_file_keys = REQUIRED_FILE_KEYS - set(file_metadata) | ||
| if missing_file_keys: | ||
| errors.append( | ||
| f"{bundle} / {filename}: missing required file keys: " | ||
| + ", ".join(sorted(missing_file_keys)) | ||
| ) | ||
|
|
||
| if errors: | ||
| print("\nTEST DATA INVENTORY CHECK FAILED\n") | ||
| print("\n\n".join(errors)) | ||
| sys.exit(1) | ||
|
|
||
| print("Test data inventory is valid.") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| 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
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,44 @@ | ||
| (contrib:test-data)= | ||
|
|
||
| # Test data inventory | ||
|
|
||
| echopype uses a collection of test data bundles to support unit and integration tests across different sonar models and file formats. These bundles are distributed through GitHub release assets and downloaded automatically using Pooch during testing. | ||
|
|
||
| The test data inventory is maintained in: | ||
|
|
||
| ```text | ||
| docs/source/test_data_inventory.yml | ||
| ``` | ||
|
|
||
| This inventory serves as the central metadata registry for the test data bundles currently used by the test suite. It includes, when available: | ||
|
|
||
| * instrument type, | ||
| * file descriptions, | ||
| * data source, | ||
| * contributor, | ||
| * references, | ||
| * additional notes. | ||
|
|
||
| The inventory is validated in CI against the list of test data bundles declared in the test suite (`echopype/tests/conftest.py`). When a new test data bundle is added, the inventory should be updated accordingly. | ||
|
|
||
| ## Inventory fields | ||
|
|
||
| | Field | Description | | ||
| | :-------------------- | :------------------------------------------------------------------------------ | | ||
| | `documented_checksum` | SHA256 checksum of the bundle version for which the metadata has been reviewed. | | ||
| | `instrument` | Sonar or instrument type, when known. | | ||
| | `description` | Short description of the bundle or file. | | ||
| | `source` | Origin of the dataset, when known. | | ||
| | `contributor` | Contributor or data provider, when known. | | ||
| | `references` | Related publications, documentation, or external resources. | | ||
| | `notes` | Additional information or context. | | ||
| | `files` | Metadata for individual files contained in the bundle. | | ||
|
|
||
| ## Adding a new test data bundle | ||
|
|
||
| When adding a new test data bundle: | ||
|
|
||
| 1. Add the bundle to the Pooch registry in `echopype/tests/conftest.py`. | ||
| 2. Add a corresponding entry to `docs/source/test_data_inventory.yml`. | ||
| 3. Populate the available metadata fields as completely as possible. | ||
| 4. If the bundle metadata has been reviewed, update `documented_checksum` to match the bundle checksum in the Pooch registry. |
Oops, something went wrong.
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.
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.
Maybe it's this?