-
Notifications
You must be signed in to change notification settings - Fork 74
[_708] new __slots__ members to prevent configuration miswrites #791
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
d-w-moore
wants to merge
5
commits into
irods:main
Choose a base branch
from
d-w-moore:708.m
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
5 commits
Select commit
Hold shift + click to select a range
98ee4b6
[_708] new __slots__ members to prevent configuration misfires
d-w-moore 994ff71
ruff: whitespace
d-w-moore fb14c34
adding noqa notation
d-w-moore 7dd2912
extra space before # noqa
d-w-moore f4c5a62
comments/explanations
d-w-moore 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,43 @@ | ||
| import unittest | ||
|
|
||
| import irods.client_configuration as cfg | ||
|
|
||
|
|
||
| # Test assignments on the negative and positive space of the | ||
| # client configuration. | ||
| class TestClientConfigurationAttributes(unittest.TestCase): | ||
| def test_configuration_writes_and_miswrites__issue_708(self): | ||
| # For caching configuration objects | ||
| configuration_level = {} | ||
| leaf_names = [] | ||
|
|
||
| for dotted_name, value, is_conf in cfg._var_items_as_generator(): # noqa: SLF001 | ||
| with self.subTest(dotted_name=dotted_name): | ||
| name_parts = dotted_name.split('.') | ||
| namespace = '.'.join(name_parts[:-1]) | ||
| attribute_name = name_parts[-1] | ||
| if isinstance(value, cfg.iRODSConfiguration): | ||
| # Store a parent object corresponding to a namespace. For any leaf value | ||
|
Check failure on line 20 in irods/test/client_configuration_test.py
|
||
| # subsequently found in the top-down descent, to be sitting directly within | ||
| # that namespace, the "else is_conf" part of this if/else will run the core | ||
| # part of the test on the corresponding configuration setting. | ||
| configuration_level[dotted_name] = value | ||
| elif is_conf: | ||
| # A configuration setting was actually found (i.e. a "leaf" value within a dotted name.) | ||
|
|
||
| # Store the leaf name for proof positive of subtests actually run. | ||
| leaf_names.append(attribute_name) | ||
|
|
||
| # Test the positive space, i.e. the 'hit'. This simply tests that the | ||
| # setting may be written to without error: | ||
| setattr(configuration_level[namespace], attribute_name, value) | ||
d-w-moore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Test the negative space, i.e. a deliberate 'miss'. This time we must fail; | ||
| # otherwise we'd get a silent miswrite in the form of a write to the incorrect attribute. | ||
| # (The new __slots__ members are there to prevent this): | ||
| with self.assertRaises(AttributeError): | ||
| setattr(configuration_level[namespace], attribute_name + '_1', value) | ||
|
|
||
| # These cases were identified as likely ones for possible failed writes via misspelling. | ||
| self.assertIn('irods_query_limit', leaf_names) | ||
| self.assertIn('xml_parser_default', leaf_names) | ||
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.