-
Notifications
You must be signed in to change notification settings - Fork 110
add override capabilities to repeated capabilities documentation #2183
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
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bc59057
add overwrite to repeated capabilities
elebel-emerson db0726d
Test for rep caps template
elebel-emerson dcb3894
codegen
elebel-emerson 92b5d19
Revert changes to file modes
elebel-emerson a5b270d
remove auto_prefix_addition_supported
elebel-emerson 9cd7344
expanding metadata instead of creating
elebel-emerson 33883f0
change repeated capabilities to pass
elebel-emerson eae401f
remove functional change
elebel-emerson 53574b6
testing chained rep caps
elebel-emerson 4b2ab0d
fixing whitespace/code sections
elebel-emerson 8e16ee1
change to use valid_indices instead of valid_identifiers
elebel-emerson 6d34dba
fixing bolding of first line of rep_caps
elebel-emerson 3108727
change nifake from keys to indices
elebel-emerson 2fed2e4
make whitespace more consistent
elebel-emerson 92ec484
Merge branch 'master' of https://github.com/ni/nimi-python into updat…
elebel-emerson 6a5105a
fix whitespace and pull from main
elebel-emerson b24a22f
use textwrap
elebel-emerson 99e7fb4
fix comment
elebel-emerson 8bfd388
going to be overwritten metadata
elebel-emerson 0bec19d
different test than default
elebel-emerson d4a1106
fixes from PR Comments
elebel-emerson 26b3c1b
Stop testing indentations
elebel-emerson 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| from pathlib import Path | ||
| from tempfile import TemporaryDirectory | ||
| from types import SimpleNamespace | ||
|
|
||
| from build.generate_template import generate_template | ||
| from build.helper.metadata_add_all import add_all_config_metadata | ||
|
|
||
|
|
||
| def _render_rep_caps(config): | ||
| repo_root = Path(__file__).resolve().parents[2] | ||
| template_path = repo_root / 'build' / 'templates' / 'rep_caps.rst.mako' | ||
| metadata = SimpleNamespace(config=add_all_config_metadata(config)) | ||
| with TemporaryDirectory() as temp_dir: | ||
| output_path = Path(temp_dir) / 'rep_caps.rst' | ||
| generate_template(str(template_path), {'metadata': metadata}, str(output_path)) | ||
| return output_path.read_text() | ||
|
|
||
|
|
||
| def test_custom_documentation_overwrites_rep_caps_template_defaults(): | ||
| config = { | ||
| 'module_name': 'nifake', | ||
| 'c_function_prefix': 'niFake_', | ||
| 'repeated_capabilities': [ | ||
| { | ||
| 'prefix': 'res', | ||
| 'python_name': 'resources', | ||
| 'documentation': { | ||
| 'description': 'Resource repeated capabilities use fully-qualified identifiers.', | ||
| 'valid_indices': ['dev0/res0', 'dev0/res1'], | ||
| 'examples': [ | ||
| { | ||
| 'code': ( | ||
| "session.resources['dev0/res0'].channel_enabled = True\n" | ||
| "session.resources['dev0/res1'].channel_enabled = True" | ||
| ), | ||
| 'description': ( | ||
| 'The first line enables resource 0.\n' | ||
| 'The second line enables resource 1.' | ||
| ), | ||
| }, | ||
| { | ||
| 'code': "session.resources['dev0/res2'].channel_enabled = True", | ||
| 'description': '', | ||
| }, | ||
| ], | ||
| }, | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| rendered = _render_rep_caps(config) | ||
|
|
||
| assert 'Resource repeated capabilities use fully-qualified identifiers.' in rendered | ||
| assert "Valid Indices: :python:`'dev0/res0, dev0/res1'`." in rendered | ||
| assert "session.resources['dev0/res0'].channel_enabled = True" in rendered | ||
| assert "session.resources['dev0/res1'].channel_enabled = True" in rendered | ||
| assert "session.resources['dev0/res2'].channel_enabled = True" in rendered | ||
| assert 'The first line enables resource 0.' in rendered | ||
| assert 'The second line enables resource 1.' in rendered | ||
|
|
||
| # Custom documentation should override the generic auto-prefix guidance. | ||
| assert 'If no prefix is added to the items in the parameter' not in rendered | ||
| assert "session.resources['0-2'].channel_enabled = True" not in rendered | ||
| assert "'res0, res1, res2'" not in rendered | ||
|
|
||
|
|
||
| def test_rep_caps_template_preserves_default_prefixed_behavior(): | ||
| config = { | ||
| 'module_name': 'nifake', | ||
| 'c_function_prefix': 'niFake_', | ||
| 'repeated_capabilities': [ | ||
| { | ||
| 'prefix': 'channel', | ||
| 'python_name': 'channels', | ||
| }, | ||
| { | ||
| 'prefix': '', | ||
| 'python_name': 'instruments', | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| rendered = _render_rep_caps(config) | ||
|
|
||
| assert 'If no prefix is added to the items in the parameter' in rendered | ||
| assert "session.channels['0-2'].channel_enabled = True" in rendered | ||
| assert "'channel0, channel1, channel2'" in rendered | ||
| example_description = ( | ||
| " passes a string of :python:`'channel0, channel1, channel2'` to the set attribute function." | ||
| ) | ||
| assert rendered.count(example_description) == 2 | ||
| assert '\n passes a string' not in rendered | ||
| assert "set attribute function.\n\n\ninstruments\n" in rendered | ||
| assert rendered.endswith('\n\n\n\n') | ||
| assert not any(line.isspace() for line in rendered.splitlines()) | ||
|
|
||
|
|
||
| def test_rep_caps_template_expands_default_documentation_fields(): | ||
| config = { | ||
| 'module_name': 'nifake', | ||
| 'c_function_prefix': 'niFake_', | ||
| 'repeated_capabilities': [ | ||
| { | ||
| 'prefix': 'channel', | ||
| 'python_name': 'channels', | ||
| 'documentation': { | ||
| 'description': 'Custom channel documentation.', | ||
| }, | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| rendered = _render_rep_caps(config) | ||
|
|
||
| assert 'Custom channel documentation.' in rendered | ||
| assert "session.channels['channel0-channel2'].channel_enabled = True" in rendered | ||
| assert "'channel0, channel1, channel2'" in rendered |
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
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.