-
Notifications
You must be signed in to change notification settings - Fork 11
Add check for NWB schema version to ensure official releases #607
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
Draft
bendichter
wants to merge
2
commits into
dev
Choose a base branch
from
add-check-nwb-schema-version-official-release
base: dev
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.
Draft
Changes from all commits
Commits
Show all changes
2 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
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 |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| check_experimenter_form, | ||
| check_institution, | ||
| check_keywords, | ||
| check_nwb_schema_version_official_release, | ||
| check_processing_module_name, | ||
| check_session_id_no_slashes, | ||
| check_session_start_time_future_date, | ||
|
|
@@ -619,3 +620,75 @@ def test_check_subject_id_with_slashes(): | |
| object_name="subject", | ||
| location="/general/subject", | ||
| ) | ||
|
|
||
|
|
||
| def test_check_nwb_schema_version_official_release_pass(): | ||
| """Test that official schema versions pass the check.""" | ||
| # The current schema version (2.8.0) should be considered official | ||
| assert check_nwb_schema_version_official_release(minimal_nwbfile) is None | ||
|
|
||
|
|
||
| def test_check_nwb_schema_version_official_release_fail(): | ||
| """Test that unofficial schema versions fail the check.""" | ||
| # We need to mock the schema version to test different scenarios | ||
| import unittest.mock | ||
|
|
||
| # Test development version | ||
| with unittest.mock.patch("pynwb.get_manager") as mock_manager: | ||
|
Comment on lines
+634
to
+637
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the comment on the check, but I think these tests could also be updated/simplified using mock nwbfiles with the |
||
| mock_catalog = unittest.mock.MagicMock() | ||
| mock_namespace = unittest.mock.MagicMock() | ||
| mock_namespace.version = "2.8.0-dev" | ||
| mock_catalog.get_namespace.return_value = mock_namespace | ||
| mock_manager.return_value.namespace_catalog = mock_catalog | ||
|
|
||
| result = check_nwb_schema_version_official_release(minimal_nwbfile) | ||
| assert result == InspectorMessage( | ||
| message=( | ||
| "The NWB schema version '2.8.0-dev' appears to be a development or pre-release version. " | ||
| "For production data, it is recommended to use only official release versions " | ||
| "(e.g., '2.8.0') to ensure compatibility and reproducibility." | ||
| ), | ||
| importance=Importance.BEST_PRACTICE_VIOLATION, | ||
| check_function_name="check_nwb_schema_version_official_release", | ||
| object_type="NWBFile", | ||
| object_name="root", | ||
| location="/", | ||
| ) | ||
|
|
||
|
|
||
| def test_check_nwb_schema_version_pre_release_versions(): | ||
| """Test that various pre-release versions are detected.""" | ||
| import unittest.mock | ||
|
|
||
| test_cases = [ | ||
| ("2.8.0-alpha", "development or pre-release"), | ||
| ("2.8.0-beta", "development or pre-release"), | ||
| ("2.8.0-rc1", "development or pre-release"), | ||
| ("2.8.0-dev", "development or pre-release"), | ||
| ("2.8.0-pre", "development or pre-release"), | ||
| ("2.8.0.custom", "non-standard"), | ||
| ("v2.8.0", "non-standard"), | ||
| ] | ||
|
|
||
| for version, version_type in test_cases: | ||
| with unittest.mock.patch("pynwb.get_manager") as mock_manager: | ||
| mock_catalog = unittest.mock.MagicMock() | ||
| mock_namespace = unittest.mock.MagicMock() | ||
| mock_namespace.version = version | ||
| mock_catalog.get_namespace.return_value = mock_namespace | ||
| mock_manager.return_value.namespace_catalog = mock_catalog | ||
|
|
||
| result = check_nwb_schema_version_official_release(minimal_nwbfile) | ||
| assert result is not None | ||
| assert version in result.message | ||
| assert version_type in result.message | ||
|
|
||
|
|
||
| def test_check_nwb_schema_version_exception_handling(): | ||
| """Test that exceptions in schema version detection are handled gracefully.""" | ||
| import unittest.mock | ||
|
|
||
| with unittest.mock.patch("pynwb.get_manager", side_effect=Exception("Mock error")): | ||
| # Should return None when unable to determine schema version | ||
| result = check_nwb_schema_version_official_release(minimal_nwbfile) | ||
| assert result is None | ||
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.
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.
This check uses the loaded namespace from PyNWB to check the schema version validity and not the nwbfile argument provided. I think it would be more direct to check the
nwb_versionattribute of the nwbfile provided. Thoughts?