-
Notifications
You must be signed in to change notification settings - Fork 322
test: microgen - _should_include_class() and _should_include_method()
#2321
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
chalmerlowe
merged 4 commits into
autogen
from
test/test__should_include_class_or_method
Oct 15, 2025
+179
−2
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
46dffc3
updates docstrings for functions that handle filtering
chalmerlowe 7d6e28d
adds tests for functions that handle filtering
chalmerlowe ca8c832
refactors tests to use pytest.param()
chalmerlowe 4d661c4
Merge branch 'autogen' into test/test__should_include_class_or_method
chalmerlowe 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
129 changes: 129 additions & 0 deletions
129
scripts/microgenerator/tests/unit/test_generate_filters.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,129 @@ | ||
| import pytest | ||
| from scripts.microgenerator.generate import ( | ||
| _should_include_class, | ||
| _should_include_method, | ||
| ) | ||
|
|
||
|
|
||
| # Tests for _should_include_class | ||
| @pytest.mark.parametrize( | ||
| "class_name, filters, expected", | ||
| [ | ||
| pytest.param("MyClass", {}, True, id="No filters"), | ||
| pytest.param( | ||
| "DatasetClient", | ||
| {"include_suffixes": ["Client", "Service"]}, | ||
| True, | ||
| id="Include suffix match", | ||
| ), | ||
| pytest.param( | ||
| "MyClass", | ||
| {"include_suffixes": ["Client", "Service"]}, | ||
| False, | ||
| id="Include suffix no match", | ||
| ), | ||
| pytest.param( | ||
| "MyBase", | ||
| {"exclude_suffixes": ["Base", "Util"]}, | ||
| False, | ||
| id="Exclude suffix match", | ||
| ), | ||
| pytest.param( | ||
| "MyClass", | ||
| {"exclude_suffixes": ["Base", "Util"]}, | ||
| True, | ||
| id="Exclude suffix no match", | ||
| ), | ||
| pytest.param( | ||
| "DatasetClient", | ||
| {"include_suffixes": ["Client"], "exclude_suffixes": ["BaseClient"]}, | ||
| True, | ||
| id="Mix include/exclude match", | ||
| ), | ||
| pytest.param( | ||
| "BaseClient", | ||
| {"include_suffixes": ["Client"], "exclude_suffixes": ["BaseClient"]}, | ||
| False, | ||
| id="Mix include/exclude no match", | ||
| ), | ||
| pytest.param( | ||
| "MyClass", | ||
| {"include_suffixes": [], "exclude_suffixes": []}, | ||
| True, | ||
| id="Empty filters", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_should_include_class(class_name, filters, expected): | ||
| assert _should_include_class(class_name, filters) is expected | ||
|
|
||
|
|
||
| # Tests for _should_include_method | ||
| @pytest.mark.parametrize( | ||
| "method_name, filters, expected", | ||
| [ | ||
| pytest.param("my_method", {}, True, id="No filters"), | ||
| pytest.param( | ||
| "get_dataset", | ||
| {"include_prefixes": ["get_", "list_"]}, | ||
| True, | ||
| id="Include prefix match (get)", | ||
| ), | ||
| pytest.param( | ||
| "list_jobs", | ||
| {"include_prefixes": ["get_", "list_"]}, | ||
| True, | ||
| id="Include prefix match (list)", | ||
| ), | ||
| pytest.param( | ||
| "create_dataset", | ||
| {"include_prefixes": ["get_", "list_"]}, | ||
| False, | ||
| id="Include prefix no match", | ||
| ), | ||
| pytest.param( | ||
| "_private_method", | ||
| {"exclude_prefixes": ["_", "internal_"]}, | ||
| False, | ||
| id="Exclude prefix match (private)", | ||
| ), | ||
| pytest.param( | ||
| "internal_helper", | ||
| {"exclude_prefixes": ["_", "internal_"]}, | ||
| False, | ||
| id="Exclude prefix match (internal)", | ||
| ), | ||
| pytest.param( | ||
| "get_dataset", | ||
| {"exclude_prefixes": ["_", "internal_"]}, | ||
| True, | ||
| id="Exclude prefix no match", | ||
| ), | ||
| pytest.param( | ||
| "get_dataset", | ||
| {"include_prefixes": ["get_"], "exclude_prefixes": ["get_internal_"]}, | ||
| True, | ||
| id="Mix include/exclude match", | ||
| ), | ||
| pytest.param( | ||
| "get_internal_status", | ||
| {"include_prefixes": ["get_"], "exclude_prefixes": ["get_internal_"]}, | ||
| False, | ||
| id="Mix include/exclude no match (exclude wins)", | ||
| ), | ||
| pytest.param( | ||
| "list_datasets", | ||
| {"include_prefixes": ["get_"], "exclude_prefixes": ["get_internal_"]}, | ||
| False, | ||
| id="Mix include/exclude no match (include fails)", | ||
| ), | ||
| pytest.param( | ||
| "my_method", | ||
| {"include_prefixes": [], "exclude_prefixes": []}, | ||
| True, | ||
| id="Empty filters", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_should_include_method(method_name, filters, expected): | ||
| assert _should_include_method(method_name, filters) is expected |
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.
Just for my curiosity, what happens if a class name satisfies both
include_suffixesandexclude_suffixes?