Skip to content
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 8 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/azure-cli-core/azure/cli/core/tests/test_argcomplete.py
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'))
Copy link
Member

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?

Copy link
Contributor Author

@bebound bebound Jan 7, 2025

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 and env, like we did in line 59.
Also, run_cmd is identical to the external autocompletion call, so I prefer to keep it.

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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some bugs in azdev. The azure-cli-core recordings are saved in the tests folder, ignoring the profile name, which causes recording conflicts. Therefore, I mock the HTTP requests.

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')
2 changes: 1 addition & 1 deletion src/azure-cli-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
]

DEPENDENCIES = [
'argcomplete~=3.3.0',
'argcomplete~=3.5.2',
'azure-cli-telemetry==1.1.0.*',
'azure-mgmt-core>=1.2.0,<2',
'cryptography',
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Darwin.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
antlr4-python3-runtime==4.13.1
applicationinsights==0.11.9
argcomplete==3.3.0
argcomplete==3.5.2
asn1crypto==0.24.0
azure-appconfiguration==1.7.0
azure-batch==14.2.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Linux.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
antlr4-python3-runtime==4.13.1
applicationinsights==0.11.9
argcomplete==3.3.0
argcomplete==3.5.2
asn1crypto==0.24.0
azure-appconfiguration==1.7.0
azure-batch==14.2.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.windows.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
antlr4-python3-runtime==4.13.1
applicationinsights==0.11.9
argcomplete==3.3.0
argcomplete==3.5.2
asn1crypto==0.24.0
azure-appconfiguration==1.7.0
azure-batch==14.2.0
Expand Down