Skip to content

Commit

Permalink
Test case groundwork.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Jan 18, 2019
1 parent 01024f2 commit f3ffddc
Show file tree
Hide file tree
Showing 19 changed files with 2,919 additions and 119 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ src/azdev.egg-info/*
*.pyc
.vscode/
azdev.egg-info/
.tox/
4 changes: 2 additions & 2 deletions azdev/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from knack import CLI, CLICommandsLoader

from azdev.help import helps
from azdev.help import helps # pylint: disable=unused-import
from azdev.utilities import get_azdev_config_dir


Expand Down Expand Up @@ -37,7 +37,7 @@ def load_arguments(self, command):
def main():
try:
azdev = AzDevCli(cli_name='azdev', commands_loader_cls=AzDevCommandsLoader,
config_dir=get_azdev_config_dir())
config_dir=get_azdev_config_dir())
exit_code = azdev.invoke(sys.argv[1:])
sys.exit(exit_code)
except KeyboardInterrupt:
Expand Down
3 changes: 2 additions & 1 deletion azdev/config/cli_pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ reports=no
# useless-object-inheritance: Specifies it can be removed from python3 bases, but we also support Python 2.7
# chained-comparison: Does not provide guidance on what would be better and arguably these are fine.
# useless-import-alias: Removing the alias often breaks the import, so it isn't really useless after all.
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: Depends on the Python version and the pylint version...
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

[FORMAT]
max-line-length=120
Expand Down
3 changes: 2 additions & 1 deletion azdev/config/ext_pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ reports=no
# useless-object-inheritance: Specifies it can be removed from python3 bases, but we also support Python 2.7
# chained-comparison: Does not provide guidance on what would be better and arguably these are fine.
# useless-import-alias: Removing the alias often breaks the import, so it isn't really useless after all.
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: Depends on the Python version and the pylint version...
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

[TYPECHECK]
# For Azure CLI extensions, we ignore some import errors as they'll be available in the environment of the CLI
Expand Down
2 changes: 1 addition & 1 deletion azdev/operations/extensions/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import json
import zipfile
from wheel.install import WHEEL_INFO_RE # pylint: disable=import-error,no-name-in-module
from wheel.install import WHEEL_INFO_RE

from knack.util import CLIError

Expand Down
4 changes: 2 additions & 2 deletions azdev/operations/linter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def run_linter(modules=None, rule_types=None, rules=None, ci_mode=False):

require_azure_cli()

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

heading('CLI Linter')
Expand Down
5 changes: 5 additions & 0 deletions azdev/operations/linter/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, command_loader=None, help_file_entries=None, loaded_help=None
self._command_loader = command_loader
self._parameters = {}
self._help_file_entries = set(help_file_entries.keys())
self._command_parser = command_loader.cli_ctx.invocation.parser

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

@property
def command_parser(self):
return self._command_parser

def get_command_metadata(self, command_name):
try:
return self._command_loader.command_table[command_name]
Expand Down
15 changes: 9 additions & 6 deletions azdev/operations/linter/rules/help_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
# license information.
# -----------------------------------------------------------------------------

from ..rule_decorators import help_file_entry_rule
from ..linter import RuleError
from ..util import LinterError
import shlex

import mock
from knack.log import get_logger

from ..rule_decorators import help_file_entry_rule
from ..linter import RuleError
from ..util import LinterError

logger = get_logger(__name__)


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

example_text = example.get('text','')
example_text = example.get('text', '')
commands = _extract_commands_from_example(example_text)
while commands:
command = commands.pop()
Expand Down Expand Up @@ -141,7 +144,7 @@ def _process_command_args(command_args):
result_args = []
new_commands = []
unwanted_chars = "$()`"
control_operators = ["&&","||"]
control_operators = ["&&", "||"]

for arg in command_args: # strip unnecessary punctuation, otherwise arg validation could fail.
if arg in control_operators: # handle cases where multiple commands are connected by control operators.
Expand Down
2 changes: 1 addition & 1 deletion azdev/operations/linter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def share_element(first_iter, second_iter):


def _get_command_source(command_name, command_table):
from azure.cli.core.commands import ExtensionCommandSource # pylint: disable=import-error
from azure.cli.core.commands import ExtensionCommandSource # pylint: disable=import-error,no-name-in-module
command = command_table.get(command_name)
# see if command is from an extension
if isinstance(command.command_source, ExtensionCommandSource):
Expand Down
2 changes: 2 additions & 0 deletions azdev/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
get_ext_repo_paths,
get_path_table
)
from .testing import test_cmd
from .tools import (
require_virtual_env,
require_azure_cli
Expand All @@ -58,6 +59,7 @@
'cmd',
'py_cmd',
'pip_cmd',
'test_cmd',
'get_azure_config_dir',
'get_azure_config',
'get_azdev_config_dir',
Expand Down
12 changes: 12 additions & 0 deletions azdev/utilities/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------

def test_cmd(args):
from azdev.__main__ import main
import sys

sys.argv = [sys.executable] + args.split()
return main()
Loading

0 comments on commit f3ffddc

Please sign in to comment.