Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
fix issues (#499)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiaoqiao Zhang <55688292+qiaozha@users.noreply.github.com>
  • Loading branch information
changlong-liu and qiaozha authored Aug 12, 2020
1 parent 62610e8 commit 1928d83
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/plugins/azgenerator/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ export class CodeModelCliImpl implements CodeModelAz {
example.Parameters = this.ConvertToCliParameters(params);
example.MethodResponses = this.Method.responses || [];
example.Method_IsLongRun = this.Method.extensions?.['x-ms-long-running-operation'] ? true : false;
if (this.Method_GetSplitOriginalOperation && Object.keys(this.Examples).length>1) {
if (this.Method_GetSplitOriginalOperation) {
//filter example by name for generic createorupdate
if(this.Command_MethodName.toLowerCase()=="update" && !id.toLowerCase().endsWith("_update"))
return;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/azgenerator/TemplateAzureCliActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export function GenerateAzureCliActions(model: CodeModelAz): string[] {

if (outputCode.length != 0) {
header.addImport("argparse");
header.addFromImport("knack.util", ["CLIError"]);
header.addFromImport("collections", ["defaultdict"]);
header.addFromImport("knack.util", ["CLIError"]);
output = header.getLines().concat(outputCode);
}
else {
Expand Down
31 changes: 20 additions & 11 deletions src/plugins/azgenerator/TemplateAzureCliTestInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function GenerateAzureCliTestInit(model: CodeModelAz): string[] {
output.push("# regenerated.");
output.push("# --------------------------------------------------------------------------");
output.push("import inspect");
output.push("import logging")
output.push("import os");
output.push("import sys");
output.push("import traceback");
Expand All @@ -28,12 +29,15 @@ export function GenerateAzureCliTestInit(model: CodeModelAz): string[] {
output.push("from azure.cli.testsdk.exceptions import CliTestError, CliExecutionError, JMESPathCheckAssertionError");
output.push("");
output.push("");
output.push("logger = logging.getLogger('azure.cli.testsdk')");
output.push("logger.addHandler(logging.StreamHandler())");
output.push("__path__ = __import__('pkgutil').extend_path(__path__, __name__)");
output.push("exceptions = []");
output.push('test_map = dict()');
output.push('SUCCESSED = "successed"');
output.push('FAILED = "failed"');
output.push('');
output.push('');
output.push('def try_manual(func):');
output.push(' def import_manual_function(origin_func):');
output.push(' from importlib import import_module');
Expand All @@ -53,14 +57,15 @@ export function GenerateAzureCliTestInit(model: CodeModelAz): string[] {
output.push(' func_to_call = func');
output.push(' try:');
output.push(' func_to_call = import_manual_function(func)');
output.push(' print("Found manual override for {}(...)".format(func.__name__))')
output.push(' func_to_call = import_manual_function(func)');
output.push(' logger.info("Found manual override for %s(...)", func.__name__)')
output.push(' except (ImportError, AttributeError):');
output.push(' pass');
output.push(' return func_to_call');
output.push('');
output.push(' def wrapper(*args, **kwargs):');
output.push(' func_to_call = get_func_to_call()');
output.push(' print("running {}()...".format(func.__name__))');
output.push(' logger.info("running %s()...", func.__name__)');
output.push(' try:');
output.push(' test_map[func.__name__] = dict()');
output.push(' test_map[func.__name__]["result"] = SUCCESSED');
Expand All @@ -69,16 +74,18 @@ export function GenerateAzureCliTestInit(model: CodeModelAz): string[] {
output.push(' test_map[func.__name__]["error_normalized"] = ""');
output.push(' test_map[func.__name__]["start_dt"] = dt.datetime.utcnow()');
output.push(' ret = func_to_call(*args, **kwargs)');
output.push(' except (AssertionError, AzureError, CliTestError, CliExecutionError, SystemExit, JMESPathCheckAssertionError) as e:');
output.push(' except (AssertionError, AzureError, CliTestError, CliExecutionError, SystemExit,');
output.push(' JMESPathCheckAssertionError) as e:');
output.push(' test_map[func.__name__]["end_dt"] = dt.datetime.utcnow()');
output.push(' test_map[func.__name__]["result"] = FAILED');
output.push(' test_map[func.__name__]["error_message"] = str(e).replace("\\r\\n", " ").replace("\\n", " ")[:500]');
output.push(' test_map[func.__name__]["error_stack"] = traceback.format_exc().replace("\\r\\n", " ").replace("\\n", " ")[:500]');
output.push(' print("--------------------------------------")');
output.push(' print("step exception: ", e)');
output.push(' print("--------------------------------------", file=sys.stderr)');
output.push(' print("step exception in {}: {}".format(func.__name__, e), file=sys.stderr)');
output.push(' traceback.print_exc()');
output.push(' test_map[func.__name__]["error_stack"] = traceback.format_exc().replace(');
output.push(' "\\r\\n", " ").replace("\\n", " ")[:500]');
output.push(' logger.info("--------------------------------------")');
output.push(' logger.info("step exception: %s", e)');
output.push(' logger.error("--------------------------------------")');
output.push(' logger.error("step exception in %s: %s", func.__name__, e)');
output.push(' logger.info(traceback.format_exc())');
output.push(' exceptions.append((func.__name__, sys.exc_info()))');
output.push(' else:');
output.push(' test_map[func.__name__]["end_dt"] = dt.datetime.utcnow()');
Expand All @@ -88,12 +95,12 @@ export function GenerateAzureCliTestInit(model: CodeModelAz): string[] {
output.push(' return get_func_to_call()');
output.push(' return wrapper');
output.push('');
output.push('');
output.push('def calc_coverage(filename):');
output.push(' filename = filename.split(".")[0]');
output.push(' coverage_name = filename + "_coverage.md"');
output.push(' with open(coverage_name, "w") as f:');
output.push(' f.write("|Scenario|Result|ErrorMessage|ErrorStack|ErrorNormalized|StartDt|EndDt|\\n")');
output.push(' failed = 0');
output.push(' total = len(test_map)');
output.push(' covered = 0');
output.push(' for k, v in test_map.items():');
Expand All @@ -102,10 +109,12 @@ export function GenerateAzureCliTestInit(model: CodeModelAz): string[] {
output.push(' continue');
output.push(' if v["result"] == SUCCESSED:');
output.push(' covered += 1');
output.push(' f.write("|{step_name}|{result}|{error_message}|{error_stack}|{error_normalized}|{start_dt}|{end_dt}|\\n".format(step_name=k, **v))');
output.push(' f.write("|{step_name}|{result}|{error_message}|{error_stack}|{error_normalized}|{start_dt}|"');
output.push(' "{end_dt}|\\n".format(step_name=k, **v))');
output.push(' f.write("Coverage: {}/{}\\n".format(covered, total))');
output.push(' print("Create coverage\\n", file=sys.stderr)');
output.push('');
output.push('');
output.push('def raise_if():');
output.push(' if exceptions:');
output.push(' if len(exceptions) <= 1:');
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/azgenerator/TemplateAzureCliTestScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ function InitiateDependencies(model: CodeModelAz, imports: string[], decorators:
for (let [class_name, kargs_key, hasCreateExample, object_name] of internalObjects) {
if (hasCreateExample && model.RandomizeNames)
{
let snakeName = ToSnakeCase(class_name);
ToMultiLine(` '${kargs_key}': self.create_random_name(prefix='${object_name}'[:${Math.floor(object_name.length/2)}], length=${object_name.length}),`, initiates);
const RANDOMIZE_MIN_LEN = 4;
let prefixLen = Math.floor(object_name.length/2);
if(object_name.length-prefixLen<RANDOMIZE_MIN_LEN) prefixLen = Math.max(object_name.length-RANDOMIZE_MIN_LEN, 0);
ToMultiLine(` '${kargs_key}': self.create_random_name(prefix='${object_name}'[:${prefixLen}], length=${Math.max(object_name.length, RANDOMIZE_MIN_LEN)}),`, initiates);
}
else
initiates.push(` '${kargs_key}': '${object_name}',`); // keep the original name in example if there is no create example in the test-scenario
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# pylint: disable=protected-access

import argparse
from knack.util import CLIError
from collections import defaultdict
from knack.util import CLIError


class AddPolicySigningCertificatesKeys(argparse._AppendAction):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# regenerated.
# --------------------------------------------------------------------------
import inspect
import logging
import os
import sys
import traceback
Expand All @@ -18,12 +19,15 @@
from azure.cli.testsdk.exceptions import CliTestError, CliExecutionError, JMESPathCheckAssertionError


logger = logging.getLogger('azure.cli.testsdk')
logger.addHandler(logging.StreamHandler())
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
exceptions = []
test_map = dict()
SUCCESSED = "successed"
FAILED = "failed"


def try_manual(func):
def import_manual_function(origin_func):
from importlib import import_module
Expand All @@ -43,14 +47,15 @@ def get_func_to_call():
func_to_call = func
try:
func_to_call = import_manual_function(func)
print("Found manual override for {}(...)".format(func.__name__))
func_to_call = import_manual_function(func)
logger.info("Found manual override for %s(...)", func.__name__)
except (ImportError, AttributeError):
pass
return func_to_call

def wrapper(*args, **kwargs):
func_to_call = get_func_to_call()
print("running {}()...".format(func.__name__))
logger.info("running %s()...", func.__name__)
try:
test_map[func.__name__] = dict()
test_map[func.__name__]["result"] = SUCCESSED
Expand All @@ -59,16 +64,18 @@ def wrapper(*args, **kwargs):
test_map[func.__name__]["error_normalized"] = ""
test_map[func.__name__]["start_dt"] = dt.datetime.utcnow()
ret = func_to_call(*args, **kwargs)
except (AssertionError, AzureError, CliTestError, CliExecutionError, SystemExit, JMESPathCheckAssertionError) as e:
except (AssertionError, AzureError, CliTestError, CliExecutionError, SystemExit,
JMESPathCheckAssertionError) as e:
test_map[func.__name__]["end_dt"] = dt.datetime.utcnow()
test_map[func.__name__]["result"] = FAILED
test_map[func.__name__]["error_message"] = str(e).replace("\r\n", " ").replace("\n", " ")[:500]
test_map[func.__name__]["error_stack"] = traceback.format_exc().replace("\r\n", " ").replace("\n", " ")[:500]
print("--------------------------------------")
print("step exception: ", e)
print("--------------------------------------", file=sys.stderr)
print("step exception in {}: {}".format(func.__name__, e), file=sys.stderr)
traceback.print_exc()
test_map[func.__name__]["error_stack"] = traceback.format_exc().replace(
"\r\n", " ").replace("\n", " ")[:500]
logger.info("--------------------------------------")
logger.info("step exception: %s", e)
logger.error("--------------------------------------")
logger.error("step exception in %s: %s", func.__name__, e)
logger.info(traceback.format_exc())
exceptions.append((func.__name__, sys.exc_info()))
else:
test_map[func.__name__]["end_dt"] = dt.datetime.utcnow()
Expand All @@ -78,12 +85,12 @@ def wrapper(*args, **kwargs):
return get_func_to_call()
return wrapper


def calc_coverage(filename):
filename = filename.split(".")[0]
coverage_name = filename + "_coverage.md"
with open(coverage_name, "w") as f:
f.write("|Scenario|Result|ErrorMessage|ErrorStack|ErrorNormalized|StartDt|EndDt|\n")
failed = 0
total = len(test_map)
covered = 0
for k, v in test_map.items():
Expand All @@ -92,10 +99,12 @@ def calc_coverage(filename):
continue
if v["result"] == SUCCESSED:
covered += 1
f.write("|{step_name}|{result}|{error_message}|{error_stack}|{error_normalized}|{start_dt}|{end_dt}|\n".format(step_name=k, **v))
f.write("|{step_name}|{result}|{error_message}|{error_stack}|{error_normalized}|{start_dt}|"
"{end_dt}|\n".format(step_name=k, **v))
f.write("Coverage: {}/{}\n".format(covered, total))
print("Create coverage\n", file=sys.stderr)


def raise_if():
if exceptions:
if len(exceptions) <= 1:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# regenerated.
# --------------------------------------------------------------------------
import inspect
import logging
import os
import sys
import traceback
Expand All @@ -18,12 +19,15 @@
from azure.cli.testsdk.exceptions import CliTestError, CliExecutionError, JMESPathCheckAssertionError


logger = logging.getLogger('azure.cli.testsdk')
logger.addHandler(logging.StreamHandler())
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
exceptions = []
test_map = dict()
SUCCESSED = "successed"
FAILED = "failed"


def try_manual(func):
def import_manual_function(origin_func):
from importlib import import_module
Expand All @@ -43,14 +47,15 @@ def get_func_to_call():
func_to_call = func
try:
func_to_call = import_manual_function(func)
print("Found manual override for {}(...)".format(func.__name__))
func_to_call = import_manual_function(func)
logger.info("Found manual override for %s(...)", func.__name__)
except (ImportError, AttributeError):
pass
return func_to_call

def wrapper(*args, **kwargs):
func_to_call = get_func_to_call()
print("running {}()...".format(func.__name__))
logger.info("running %s()...", func.__name__)
try:
test_map[func.__name__] = dict()
test_map[func.__name__]["result"] = SUCCESSED
Expand All @@ -59,16 +64,18 @@ def wrapper(*args, **kwargs):
test_map[func.__name__]["error_normalized"] = ""
test_map[func.__name__]["start_dt"] = dt.datetime.utcnow()
ret = func_to_call(*args, **kwargs)
except (AssertionError, AzureError, CliTestError, CliExecutionError, SystemExit, JMESPathCheckAssertionError) as e:
except (AssertionError, AzureError, CliTestError, CliExecutionError, SystemExit,
JMESPathCheckAssertionError) as e:
test_map[func.__name__]["end_dt"] = dt.datetime.utcnow()
test_map[func.__name__]["result"] = FAILED
test_map[func.__name__]["error_message"] = str(e).replace("\r\n", " ").replace("\n", " ")[:500]
test_map[func.__name__]["error_stack"] = traceback.format_exc().replace("\r\n", " ").replace("\n", " ")[:500]
print("--------------------------------------")
print("step exception: ", e)
print("--------------------------------------", file=sys.stderr)
print("step exception in {}: {}".format(func.__name__, e), file=sys.stderr)
traceback.print_exc()
test_map[func.__name__]["error_stack"] = traceback.format_exc().replace(
"\r\n", " ").replace("\n", " ")[:500]
logger.info("--------------------------------------")
logger.info("step exception: %s", e)
logger.error("--------------------------------------")
logger.error("step exception in %s: %s", func.__name__, e)
logger.info(traceback.format_exc())
exceptions.append((func.__name__, sys.exc_info()))
else:
test_map[func.__name__]["end_dt"] = dt.datetime.utcnow()
Expand All @@ -78,12 +85,12 @@ def wrapper(*args, **kwargs):
return get_func_to_call()
return wrapper


def calc_coverage(filename):
filename = filename.split(".")[0]
coverage_name = filename + "_coverage.md"
with open(coverage_name, "w") as f:
f.write("|Scenario|Result|ErrorMessage|ErrorStack|ErrorNormalized|StartDt|EndDt|\n")
failed = 0
total = len(test_map)
covered = 0
for k, v in test_map.items():
Expand All @@ -92,10 +99,12 @@ def calc_coverage(filename):
continue
if v["result"] == SUCCESSED:
covered += 1
f.write("|{step_name}|{result}|{error_message}|{error_stack}|{error_normalized}|{start_dt}|{end_dt}|\n".format(step_name=k, **v))
f.write("|{step_name}|{result}|{error_message}|{error_stack}|{error_normalized}|{start_dt}|"
"{end_dt}|\n".format(step_name=k, **v))
f.write("Coverage: {}/{}\n".format(covered, total))
print("Create coverage\n", file=sys.stderr)


def raise_if():
if exceptions:
if len(exceptions) <= 1:
Expand Down
8 changes: 7 additions & 1 deletion src/test/scenarios/datafactory/input/datafactory.json
Original file line number Diff line number Diff line change
Expand Up @@ -3979,7 +3979,13 @@
"type": "string",
"enum": [
"On",
"Off"
"Off",
"fakeValue1",
"fakeValue2",
"fakeValue3",
"fakeValue4",
"fakeValue5",
"fakeValue6"
],
"x-ms-enum": {
"name": "IntegrationRuntimeAutoUpdate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ def load_arguments(self, _):
c.argument('factory_name', type=str, help='The factory name.', id_part='name')
c.argument('integration_runtime_name', options_list=['--name', '-n'], type=str, help='The integration runtime '
'name.', id_part='child_name_1')
c.argument('auto_update', arg_type=get_enum_type(['On', 'Off']), help='Enables or disables the auto-update '
'feature of the self-hosted integration runtime. See https://go.microsoft.com/fwlink/?linkid=854189.'
'')
c.argument('auto_update', arg_type=get_enum_type(['On', 'Off', 'fakeValue1', 'fakeValue2', 'fakeValue3', ''
'fakeValue4', 'fakeValue5', 'fakeValue6']), help='Enables or '
'disables the auto-update feature of the self-hosted integration runtime. See '
'https://go.microsoft.com/fwlink/?linkid=854189.')
c.argument('update_delay_offset', type=str, help='The time offset (in hours) in the day, e.g., PT03H is 3 '
'hours. The integration runtime auto update will happen on that time.')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# pylint: disable=protected-access

import argparse
from knack.util import CLIError
from collections import defaultdict
from knack.util import CLIError


class AddFactoryVstsConfiguration(argparse.Action):
Expand Down
Loading

0 comments on commit 1928d83

Please sign in to comment.