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

Commit

Permalink
20210402 linting and doc (#812)
Browse files Browse the repository at this point in the history
* testcase -> test case

* for #783

* for #777

* for #798

* #811

* shrink impact

* output

* fix -y
  • Loading branch information
changlong-liu authored Apr 7, 2021
1 parent 1c7662d commit 71b8167
Show file tree
Hide file tree
Showing 22 changed files with 173 additions and 150 deletions.
16 changes: 8 additions & 8 deletions doc/04-scenario-test-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Notice 2: *Even if no configuration is provided, you can still override the auto
## How to configure?

### Basic test-scenario
In basic test-scenario, all test examples are composed in one testcase.
In basic test-scenario, all test examples are composed in one test case.
Test scenario configuration can be done in file readme.cli.md, here is an example for it.
~~~
cli:
Expand All @@ -44,8 +44,8 @@ Two kind of step can be used in the test-scenario, they are:
},
~~~

### Mutli-testcase scenario
You can config multiple testcases in the test-scenario with below format:
### Mutli-test-cases scenario
You can config multiple test cases in the test-scenario with below format:
~~~
cli:
cli-name: managednetwork
Expand All @@ -68,11 +68,11 @@ cli:
- name: ScopeAssignmentsList
- name: ScopeAssignmentsDelete
~~~
In above sample, four testcases are configured, and they will be generated in two test files:
- test_ManagedNetworks_scenario.py: three testcases will be generated in it: ManagedNetworks_scenario1, ManagedNetworks_scenario2, ManagedNetworks_scenario3.
- test_ScopeAssignments_scenario.py: one testcase generated in it: ScopeAssignments.
In above sample, four test cases are configured, and they will be generated in two test files:
- test_ManagedNetworks_scenario.py: three test cases will be generated in it: ManagedNetworks_scenario1, ManagedNetworks_scenario2, ManagedNetworks_scenario3.
- test_ScopeAssignments_scenario.py: one test case generated in it: ScopeAssignments.

Note: the part before the underscore('_') in the testcase name will be used to descibe in which test file the case will be generated.
Note: the part before the underscore('_') in the test case name will be used to descibe in which test file the case will be generated.


## What if multiple examples in swagger have duplicated name?
Expand Down Expand Up @@ -426,7 +426,7 @@ az:
~~~

## How to generate cmdlet tests
The cmdlet tests can be run under virtual server to check CLI command availability. Each CLI operation is a testcase in cmdlet tests:
The cmdlet tests can be run under virtual server to check CLI command availability. Each CLI operation is a test case in cmdlet tests:
~~~
class PositiveTest(ScenarioTest):
# EXAMPLE: /Operation/get/Operations_List
Expand Down
8 changes: 8 additions & 0 deletions src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ function processFolderPath() {
const pythonSdkOutputFolder: string = AzConfiguration.getValue(
CodeGenConstants.pythonSdkOutputFolder,
);

if (isNullOrUndefined(extensionName)) {
throw new Error('--az.extensions should not be null!');
}
if (isNullOrUndefined(pythonSdkOutputFolder)) {
throw new Error('--python-sdk-output-folder should not be null!');
}

let sdkFolder = pythonSdkOutputFolder.replace(azOutputFolder, '');
if (sdkFolder.startsWith('/')) {
sdkFolder = sdkFolder.substring(1, sdkFolder.length);
Expand Down
9 changes: 6 additions & 3 deletions src/generate/renders/CliTopAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class CliTopAction extends TemplateBase {
headerGenerator.disableUnusedWildcardImport = true;
headerGenerator.generationMode = GenerationMode.Incremental;
let output: string[] = headerGenerator.getLines();
output = output.concat(this.loadGeneratedAction(0));
output = output.concat(this.loadGeneratedAction(0, true));
return output;
} else {
const existingMode: GenerationMode = HeaderGenerator.GetCliGenerationMode(base);
Expand Down Expand Up @@ -79,7 +79,7 @@ export class CliTopAction extends TemplateBase {

// Add loading code block
if (!hasLoadLogic) {
output = output.concat(this.loadGeneratedAction(0));
output = output.concat(this.loadGeneratedAction(0, true));
}

const appendLineStartIdx = skipLineIdx < keepLineIdx ? keepLineIdx : skipLineIdx;
Expand All @@ -91,11 +91,14 @@ export class CliTopAction extends TemplateBase {
}
}

private loadGeneratedAction(indent: number): string[] {
private loadGeneratedAction(indent: number, incremental = false): string[] {
const output: string[] = [];
const indentStr: string = getIndentString(indent);

output.push('');
if (incremental) {
output.push(indentStr + '# pylint: disable=unused-wildcard-import,wildcard-import');
}
output.push(indentStr + 'from .generated.action import * # noqa: F403');
output.push(indentStr + 'try:');
output.push(indentStr + ' from .manual.action import * # noqa: F403');
Expand Down
10 changes: 6 additions & 4 deletions src/generate/renders/CliTopCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ export class CliTopCustom extends TemplateBase {
headerGenerator.disableUnusedWildcardImport = true;
headerGenerator.generationMode = GenerationMode.Incremental;
let output: string[] = headerGenerator.getLines();
output = output.concat(this.loadGeneratedCustom(0));

output = output.concat(this.loadGeneratedCustom(0, true));
return output;
} else {
const existingMode: GenerationMode = HeaderGenerator.GetCliGenerationMode(base);
Expand Down Expand Up @@ -73,7 +72,7 @@ export class CliTopCustom extends TemplateBase {

// Add loading code block
if (!hasLoadLogic) {
output = output.concat(this.loadGeneratedCustom(0));
output = output.concat(this.loadGeneratedCustom(0, true));
}

const appendLineStartIdx = skipLineIdx < keepLineIdx ? keepLineIdx : skipLineIdx;
Expand All @@ -85,11 +84,14 @@ export class CliTopCustom extends TemplateBase {
}
}

private loadGeneratedCustom(indent: number): string[] {
private loadGeneratedCustom(indent: number, incremental = false): string[] {
const output: string[] = [];
const indentStr: string = getIndentString(indent);

output.push('');
if (incremental) {
output.push(indentStr + '# pylint: disable=unused-wildcard-import,wildcard-import');
}
output.push(indentStr + 'from .generated.custom import * # noqa: F403');
output.push(indentStr + 'try:');
output.push(indentStr + ' from .manual.custom import * # noqa: F403');
Expand Down
2 changes: 1 addition & 1 deletion src/generate/renders/generated/CliParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function getCommandBody(model: CodeModelAz, needGeneric = false, debug = false)
argument += ' Expect value: KEY1=VALUE1 KEY2=VALUE2 ...';
}
} else {
argument += ' Expected value: json-string/@json-file.';
argument += ' Expected value: json-string/json-file/@json-file.';
}
}
if (debug) {
Expand Down
7 changes: 2 additions & 5 deletions src/generate/renders/tests/CliTestCmdlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class CliCmdletTest extends TemplateBase {
>([
['extension', new RenderInput()],
['commandGroup', new RenderInput()],
['command', new RenderInput()],
['command', new RenderInput(['methodName'])],
['method', new RenderInput()],
['azExample', new RenderInput(['id', 'httpMethod', 'rawCommandStringItems'])],
]);
Expand Down Expand Up @@ -103,10 +103,7 @@ export class CliCmdletTest extends TemplateBase {
);
}

if (
commandLines[0].indexOf(' delete') > -1 &&
example.httpMethod.toLowerCase() === 'delete'
) {
if (command.methodName === 'delete') {
commandLines[0] += ' -y';
}
const exampleInfo = new ExampleInfo();
Expand Down
5 changes: 1 addition & 4 deletions src/generate/renders/tests/CliTestStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ export class CliTestStep extends TemplateBase {
);
} else {
stepBuff[cmdString] = functionName;
if (
exampleCmd[0].indexOf(' delete') > -1 &&
examples[exampleIdx].HttpMethod.toLowerCase() === 'delete'
) {
if (examples[exampleIdx].Method === 'delete') {
exampleCmd[0] += ' -y';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# pylint: disable=no-self-use,too-many-lines
from __future__ import print_function

# pylint: disable=unused-wildcard-import,wildcard-import
from .generated.custom import * # noqa: F403
try:
from .manual.custom import * # noqa: F403
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def load_arguments(self, _):
'should be automatically upgraded by the platform if there is a newer version of the extension '
'available.')
c.argument('settings', type=validate_file_or_dict, help='Json formatted public settings for the extension. '
'Expected value: json-string/@json-file.')
'Expected value: json-string/json-file/@json-file.')
c.argument('protected_settings', type=validate_file_or_dict, help='The extension can contain either '
'protectedSettings or protectedSettingsFromKeyVault or no protected settings at all. Expected '
'value: json-string/@json-file.')
'value: json-string/json-file/@json-file.')
c.argument('name', type=str, help='The virtual machine extension name.', arg_group='Instance View')
c.argument('type_', options_list=['--type'], type=str, help='Specifies the type of the extension; an example '
'is "CustomScriptExtension".', arg_group='Instance View')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def load_arguments(self, _):
validator=get_default_location_from_resource_group)
c.argument('tags', tags_type)
c.argument('test_inherit', type=validate_file_or_dict, help='Test Job Base Expected value: '
'json-string/@json-file.')
'json-string/json-file/@json-file.')
c.argument('factory_vsts_configuration', action=AddFactoryVstsConfiguration, nargs='+', help='Factory\'s VSTS '
'repo information.', arg_group='RepoConfiguration')
c.argument('factory_git_hub_configuration', action=AddFactoryGitHubConfiguration, nargs='+', help='Factory\'s '
Expand Down Expand Up @@ -121,7 +121,7 @@ def load_arguments(self, _):
c.argument('if_match', type=str, help='ETag of the trigger entity. Should only be specified for update, for '
'which it should match existing entity or can be * for unconditional update.')
c.argument('properties', type=validate_file_or_dict, help='Properties of the trigger. Expected value: '
'json-string/@json-file.')
'json-string/json-file/@json-file.')

with self.argument_context('datafactory trigger update') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand All @@ -132,7 +132,7 @@ def load_arguments(self, _):
'which it should match existing entity or can be * for unconditional update.')
c.argument('description', type=str, help='Trigger description.')
c.argument('annotations', type=validate_file_or_dict, help='List of tags that can be used for describing the '
'trigger. Expected value: json-string/@json-file.')
'trigger. Expected value: json-string/json-file/@json-file.')
c.ignore('trigger')

with self.argument_context('datafactory trigger delete') as c:
Expand Down Expand Up @@ -215,9 +215,10 @@ def load_arguments(self, _):
c.argument('fake_identity', action=AddFakeIdentity, nargs='+', help='This is only for az test.')
c.argument('zones', nargs='+', help='This is only for az test.')
c.argument('compute_properties', type=validate_file_or_dict, help='The compute resource for managed '
'integration runtime. Expected value: json-string/@json-file.', arg_group='Type Properties')
'integration runtime. Expected value: json-string/json-file/@json-file.', arg_group='Type '
'Properties')
c.argument('ssis_properties', type=validate_file_or_dict, help='SSIS properties for managed integration '
'runtime. Expected value: json-string/@json-file.', arg_group='Type Properties')
'runtime. Expected value: json-string/json-file/@json-file.', arg_group='Type Properties')

with self.argument_context('datafactory integration-runtime self-hosted create') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand All @@ -228,7 +229,7 @@ def load_arguments(self, _):
'update, for which it should match existing entity or can be * for unconditional update.')
c.argument('description', type=str, help='Integration runtime description.')
c.argument('linked_info', type=validate_file_or_dict, help='The base definition of a linked integration '
'runtime. Expected value: json-string/@json-file.', arg_group='Type Properties')
'runtime. Expected value: json-string/json-file/@json-file.', arg_group='Type Properties')

with self.argument_context('datafactory integration-runtime update') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def load_arguments(self, _):
'associated with the Kusto cluster. The user identity dictionary key references will be ARM '
'resource ids in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/prov'
'iders/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')
'json-string/json-file/@json-file.', arg_group='Identity')

with self.argument_context('kusto cluster update') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down Expand Up @@ -110,7 +110,7 @@ def load_arguments(self, _):
'associated with the Kusto cluster. The user identity dictionary key references will be ARM '
'resource ids in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/prov'
'iders/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')
'json-string/json-file/@json-file.', arg_group='Identity')

with self.argument_context('kusto cluster delete') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def load_arguments(self, _):
'associated with the Kusto cluster. The user identity dictionary key references will be ARM '
'resource ids in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/prov'
'iders/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')
'json-string/json-file/@json-file.', arg_group='Identity')

with self.argument_context('kusto cluster update') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down Expand Up @@ -110,7 +110,7 @@ def load_arguments(self, _):
'associated with the Kusto cluster. The user identity dictionary key references will be ARM '
'resource ids in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/prov'
'iders/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')
'json-string/json-file/@json-file.', arg_group='Identity')

with self.argument_context('kusto cluster delete') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def load_arguments(self, _):
'associated with the Kusto cluster. The user identity dictionary key references will be ARM '
'resource ids in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/prov'
'iders/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')
'json-string/json-file/@json-file.', arg_group='Identity')

with self.argument_context('kusto cluster update') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down Expand Up @@ -124,7 +124,7 @@ def load_arguments(self, _):
'associated with the Kusto cluster. The user identity dictionary key references will be ARM '
'resource ids in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/prov'
'iders/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')
'json-string/json-file/@json-file.', arg_group='Identity')

with self.argument_context('kusto cluster delete') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def load_arguments(self, _):
'associated with the Kusto cluster. The user identity dictionary key references will be ARM '
'resource ids in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/prov'
'iders/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')
'json-string/json-file/@json-file.', arg_group='Identity')

with self.argument_context('kusto cluster update') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down Expand Up @@ -124,7 +124,7 @@ def load_arguments(self, _):
'associated with the Kusto cluster. The user identity dictionary key references will be ARM '
'resource ids in the form: \'/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/prov'
'iders/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}\'. Expected value: '
'json-string/@json-file.', arg_group='Identity')
'json-string/json-file/@json-file.', arg_group='Identity')

with self.argument_context('kusto cluster delete') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down
Loading

0 comments on commit 71b8167

Please sign in to comment.