Skip to content

Commit f3ffddc

Browse files
committed
Test case groundwork.
1 parent 01024f2 commit f3ffddc

File tree

19 files changed

+2919
-119
lines changed

19 files changed

+2919
-119
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ src/azdev.egg-info/*
77
*.pyc
88
.vscode/
99
azdev.egg-info/
10+
.tox/

azdev/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from knack import CLI, CLICommandsLoader
1111

12-
from azdev.help import helps
12+
from azdev.help import helps # pylint: disable=unused-import
1313
from azdev.utilities import get_azdev_config_dir
1414

1515

@@ -37,7 +37,7 @@ def load_arguments(self, command):
3737
def main():
3838
try:
3939
azdev = AzDevCli(cli_name='azdev', commands_loader_cls=AzDevCommandsLoader,
40-
config_dir=get_azdev_config_dir())
40+
config_dir=get_azdev_config_dir())
4141
exit_code = azdev.invoke(sys.argv[1:])
4242
sys.exit(exit_code)
4343
except KeyboardInterrupt:

azdev/config/cli_pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ reports=no
1010
# useless-object-inheritance: Specifies it can be removed from python3 bases, but we also support Python 2.7
1111
# chained-comparison: Does not provide guidance on what would be better and arguably these are fine.
1212
# useless-import-alias: Removing the alias often breaks the import, so it isn't really useless after all.
13-
disable=missing-docstring,locally-disabled,fixme,cyclic-import,too-many-arguments,invalid-name,duplicate-code,useless-object-inheritance,chained-comparison,useless-import-alias
13+
# useless-suppression: Depends on the Python version and the pylint version...
14+
disable=missing-docstring,locally-disabled,fixme,cyclic-import,too-many-arguments,invalid-name,duplicate-code,useless-object-inheritance,chained-comparison,useless-import-alias,useless-suppression
1415

1516
[FORMAT]
1617
max-line-length=120

azdev/config/ext_pylintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ reports=no
1010
# useless-object-inheritance: Specifies it can be removed from python3 bases, but we also support Python 2.7
1111
# chained-comparison: Does not provide guidance on what would be better and arguably these are fine.
1212
# useless-import-alias: Removing the alias often breaks the import, so it isn't really useless after all.
13-
disable=missing-docstring,locally-disabled,fixme,cyclic-import,too-many-arguments,invalid-name,duplicate-code,useless-object-inheritance,chained-comparison,useless-import-alias
13+
# useless-suppression: Depends on the Python version and the pylint version...
14+
disable=missing-docstring,locally-disabled,fixme,cyclic-import,too-many-arguments,invalid-name,duplicate-code,useless-object-inheritance,chained-comparison,useless-import-alias,useless-suppression
1415

1516
[TYPECHECK]
1617
# For Azure CLI extensions, we ignore some import errors as they'll be available in the environment of the CLI

azdev/operations/extensions/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
import json
99
import zipfile
10-
from wheel.install import WHEEL_INFO_RE # pylint: disable=import-error,no-name-in-module
10+
from wheel.install import WHEEL_INFO_RE
1111

1212
from knack.util import CLIError
1313

azdev/operations/linter/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def run_linter(modules=None, rule_types=None, rules=None, ci_mode=False):
2929

3030
require_azure_cli()
3131

32-
from azure.cli.core import get_default_cli # pylint: disable=import-error
33-
from azure.cli.core.file_util import ( # pylint: disable=import-error
32+
from azure.cli.core import get_default_cli # pylint: disable=import-error,no-name-in-module
33+
from azure.cli.core.file_util import ( # pylint: disable=import-error,no-name-in-module
3434
get_all_help, create_invoker_and_load_cmds_and_args)
3535

3636
heading('CLI Linter')

azdev/operations/linter/linter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self, command_loader=None, help_file_entries=None, loaded_help=None
2323
self._command_loader = command_loader
2424
self._parameters = {}
2525
self._help_file_entries = set(help_file_entries.keys())
26+
self._command_parser = command_loader.cli_ctx.invocation.parser
2627

2728
for command_name, command in self._command_loader.command_table.items():
2829
self._parameters[command_name] = set()
@@ -41,6 +42,10 @@ def command_groups(self):
4142
def help_file_entries(self):
4243
return self._help_file_entries
4344

45+
@property
46+
def command_parser(self):
47+
return self._command_parser
48+
4449
def get_command_metadata(self, command_name):
4550
try:
4651
return self._command_loader.command_table[command_name]

azdev/operations/linter/rules/help_rules.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
# license information.
55
# -----------------------------------------------------------------------------
66

7-
from ..rule_decorators import help_file_entry_rule
8-
from ..linter import RuleError
9-
from ..util import LinterError
107
import shlex
8+
119
import mock
1210
from knack.log import get_logger
1311

12+
from ..rule_decorators import help_file_entry_rule
13+
from ..linter import RuleError
14+
from ..util import LinterError
15+
1416
logger = get_logger(__name__)
1517

1618

@@ -61,10 +63,11 @@ def faulty_help_example_parameters_rule(linter, help_entry):
6163
for example in linter.get_help_entry_examples(help_entry):
6264
max_profile = example.get('max_profile')
6365
if max_profile and max_profile != 'latest':
64-
logger.warning("\n\tSKIPPING example: {}\n\tas its max profile is {}, instead of latest.".format(example['text'], example['max_profile']))
66+
logger.warning('\n\tSKIPPING example: %s\n\tas its max profile is %s, '
67+
'instead of latest.', example['text'], example['max_profile'])
6568
continue
6669

67-
example_text = example.get('text','')
70+
example_text = example.get('text', '')
6871
commands = _extract_commands_from_example(example_text)
6972
while commands:
7073
command = commands.pop()
@@ -141,7 +144,7 @@ def _process_command_args(command_args):
141144
result_args = []
142145
new_commands = []
143146
unwanted_chars = "$()`"
144-
control_operators = ["&&","||"]
147+
control_operators = ["&&", "||"]
145148

146149
for arg in command_args: # strip unnecessary punctuation, otherwise arg validation could fail.
147150
if arg in control_operators: # handle cases where multiple commands are connected by control operators.

azdev/operations/linter/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def share_element(first_iter, second_iter):
7676

7777

7878
def _get_command_source(command_name, command_table):
79-
from azure.cli.core.commands import ExtensionCommandSource # pylint: disable=import-error
79+
from azure.cli.core.commands import ExtensionCommandSource # pylint: disable=import-error,no-name-in-module
8080
command = command_table.get(command_name)
8181
# see if command is from an extension
8282
if isinstance(command.command_source, ExtensionCommandSource):

azdev/utilities/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
get_ext_repo_paths,
4242
get_path_table
4343
)
44+
from .testing import test_cmd
4445
from .tools import (
4546
require_virtual_env,
4647
require_azure_cli
@@ -58,6 +59,7 @@
5859
'cmd',
5960
'py_cmd',
6061
'pip_cmd',
62+
'test_cmd',
6163
'get_azure_config_dir',
6264
'get_azure_config',
6365
'get_azdev_config_dir',

azdev/utilities/testing.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# -----------------------------------------------------------------------------
6+
7+
def test_cmd(args):
8+
from azdev.__main__ import main
9+
import sys
10+
11+
sys.argv = [sys.executable] + args.split()
12+
return main()

0 commit comments

Comments
 (0)