-
Notifications
You must be signed in to change notification settings - Fork 33
Add test to enforce keyword arguments #1664
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
h-mayorquin
merged 1 commit into
deprecate_postional_only_on_nwbfile
from
test_for_enforcing_nwbfile_position_only
Feb 13, 2026
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Tests to enforce keyword-only argument conventions for add_to_nwbfile methods. | ||
|
|
||
| These tests ensure that all interface add_to_nwbfile methods enforce keyword-only arguments | ||
| after nwbfile and metadata. Only nwbfile and metadata should be positional. | ||
|
|
||
| During the deprecation period (before August 2026), methods use *args with FutureWarning. | ||
| After the deprecation period, methods should use bare * for keyword-only enforcement. | ||
|
|
||
| See the developer style guide for details on the convention. | ||
| """ | ||
|
|
||
| import inspect | ||
|
|
||
| import pytest | ||
|
|
||
| from neuroconv.datainterfaces import interface_list | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "interface_class", | ||
| interface_list, | ||
| ids=lambda cls: cls.__name__, | ||
| ) | ||
| def test_add_to_nwbfile_only_nwbfile_metadata_positional(interface_class): | ||
| """Only nwbfile and metadata should be positional in add_to_nwbfile.""" | ||
| if "add_to_nwbfile" not in interface_class.__dict__: | ||
| pytest.skip(f"{interface_class.__name__} does not override add_to_nwbfile") | ||
|
|
||
| add_to_nwbfile_method = getattr(interface_class, "add_to_nwbfile") | ||
| sig = inspect.signature(add_to_nwbfile_method) | ||
|
|
||
| # No add_to_nwbfile uses POSITIONAL_ONLY (/), so POSITIONAL_OR_KEYWORD means "can be passed positionally" | ||
| can_be_passed_positionally = lambda param: param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD | ||
| positional_params = {name for name, param in sig.parameters.items() if can_be_passed_positionally(param)} | ||
|
|
||
| allowed_positional_params = {"self", "nwbfile", "metadata"} | ||
| assert positional_params == allowed_positional_params, ( | ||
| f"{interface_class.__name__}.add_to_nwbfile() positional parameters are {positional_params}, " | ||
| f"expected {allowed_positional_params}. " | ||
| f"All other parameters should be keyword-only (use * or *args)." | ||
| ) | ||
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.