-
Notifications
You must be signed in to change notification settings - Fork 3k
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
{Packaging} Bump argcomplete to 3.5.2 #30532
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
309abe2
Init
bebound 006d768
Add test
bebound 12cd227
Add dynamic completion
bebound 575ac75
Minor fix
bebound edaeb38
Mask resource name
bebound 5ae962a
Remove recording
bebound 7263e55
Minor fix
bebound b11264d
Use TestCase
bebound 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
66 changes: 66 additions & 0 deletions
66
src/azure-cli-core/azure/cli/core/tests/test_argcomplete.py
This file contains 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,66 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from unittest import mock, TestCase | ||
|
||
from azure.cli.core.mock import DummyCli | ||
from azure.cli.core.util import run_cmd | ||
|
||
|
||
class ArgcompleteScenarioTest(TestCase): | ||
|
||
def argcomplete_env(self, comp_line, comp_point): | ||
return { | ||
'COMP_LINE': comp_line, | ||
'COMP_POINT': comp_point, | ||
'_ARGCOMPLETE': '1', | ||
'_ARGCOMPLETE_IFS': ' ', | ||
'_ARGCOMPLETE_SUPPRESS_SPACE': '0', | ||
'ARGCOMPLETE_USE_TEMPFILES': '1', | ||
'_ARGCOMPLETE_STDOUT_FILENAME': './argcomplete.out', } | ||
|
||
def test_completion(self): | ||
import os | ||
import sys | ||
|
||
from azure.cli.core.parser import AzCompletionFinder | ||
|
||
if sys.platform == 'win32': | ||
self.skipTest('Skip argcomplete test on Windows') | ||
|
||
run_cmd(['az'], env=self.argcomplete_env('az account sh', '13')) | ||
with open('argcomplete.out') as f: | ||
self.assertEqual(f.read(), 'show ') | ||
os.remove('argcomplete.out') | ||
|
||
run_cmd(['az'], capture_output=True, env=self.argcomplete_env('az account s', '12')) | ||
with open('argcomplete.out') as f: | ||
self.assertEqual(f.read(), 'set show') | ||
os.remove('argcomplete.out') | ||
|
||
run_cmd(['az'], env=self.argcomplete_env('az account szzz', '15')) | ||
with open('argcomplete.out') as f: | ||
self.assertFalse(f.read()) | ||
os.remove('argcomplete.out') | ||
|
||
class MockCompletionFinder(AzCompletionFinder): | ||
def __call__(self, *args, **kwargs): | ||
import sys | ||
return super().__call__(*args, exit_method=sys.exit, **kwargs) | ||
|
||
def dummy_completor(*args, **kwargs): | ||
return ['dummystorage'] | ||
|
||
cli = DummyCli() | ||
# argcomplete uses os._exit to exit, which is also used by pytest. Patch AzCompletionFinder to use sys.exit | ||
# There is no recording for this test case, as completer is mocked. | ||
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. There are some bugs in azdev. The |
||
with mock.patch('azure.cli.core.parser.AzCompletionFinder', MockCompletionFinder): | ||
with mock.patch('azure.cli.core.commands.parameters.get_resource_name_completion_list', lambda _: dummy_completor): | ||
env = self.argcomplete_env('az storage blob list -c test --account-name dumm', '48') | ||
with mock.patch.dict(os.environ, env): | ||
self.assertRaises(SystemExit, cli.invoke, ['az']) | ||
with open('argcomplete.out') as f: | ||
self.assertEqual(f.read(), 'dummystorage ') | ||
os.remove('argcomplete.out') |
This file contains 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 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 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 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
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.
Can this be changed to a
cli.invoke
?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.
Yes, but we need to mock the
AzCompletionFinder
andenv
, like we did in line 59.Also,
run_cmd
is identical to the external autocompletion call, so I prefer to keep it.