Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 52566fb

Browse files
Add Python Data Plane Rules of tspconfig.yaml for TSV (Azure#32942)
Co-authored-by: albertxavier100 <[email protected]>
1 parent c18e3c6 commit 52566fb

File tree

2 files changed

+70
-25
lines changed

2 files changed

+70
-25
lines changed

eng/tools/typespec-validation/src/rules/sdk-tspconfig-validation.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export class TspConfigGoAzInjectSpansTrueSubRule extends TspconfigEmitterOptions
345345
}
346346
}
347347

348-
// ----- Python management sub rules -----
348+
// ----- Python management plane sub rules -----
349349
export class TspConfigPythonMgmtPackageDirectorySubRule extends TspconfigEmitterOptionsSubRuleBase {
350350
constructor() {
351351
super("@azure-tools/typespec-python", "package-dir", new RegExp(/^azure-mgmt(-[a-z]+){1,2}$/));
@@ -355,31 +355,33 @@ export class TspConfigPythonMgmtPackageDirectorySubRule extends TspconfigEmitter
355355
}
356356
}
357357

358-
export class TspConfigPythonMgmtPackageNameEqualStringSubRule extends TspconfigEmitterOptionsSubRuleBase {
358+
// ----- Python data plane sub rules -----
359+
export class TspConfigPythonDpPackageDirectorySubRule extends TspconfigEmitterOptionsSubRuleBase {
359360
constructor() {
360-
super("@azure-tools/typespec-python", "package-name", "{package-dir}");
361+
super("@azure-tools/typespec-python", "package-dir", new RegExp(/^azure(-[a-z]+){1,3}$/));
361362
}
362363
protected skip(_: any, folder: string) {
363-
return skipForDataPlane(folder);
364+
return skipForManagementPlane(folder);
364365
}
365366
}
366367

367-
export class TspConfigPythonMgmtGenerateTestTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
368+
// ----- Python azure sub rules -----
369+
export class TspConfigPythonAzPackageNameEqualStringSubRule extends TspconfigEmitterOptionsSubRuleBase {
368370
constructor() {
369-
super("@azure-tools/typespec-python", "generate-test", true);
371+
super("@azure-tools/typespec-python", "package-name", "{package-dir}");
370372
}
371-
protected skip(_: any, folder: string) {
372-
return skipForDataPlane(folder);
373+
}
374+
375+
export class TspConfigPythonAzGenerateTestTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
376+
constructor() {
377+
super("@azure-tools/typespec-python", "generate-test", true);
373378
}
374379
}
375380

376-
export class TspConfigPythonMgmtGenerateSampleTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
381+
export class TspConfigPythonAzGenerateSampleTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
377382
constructor() {
378383
super("@azure-tools/typespec-python", "generate-sample", true);
379384
}
380-
protected skip(_: any, folder: string) {
381-
return skipForDataPlane(folder);
382-
}
383385
}
384386

385387
// ----- CSharp sub rules -----
@@ -431,9 +433,10 @@ export const defaultRules = [
431433
new TspConfigGoDpPackageDirectoryMatchPatternSubRule(),
432434
new TspConfigGoDpModuleMatchPatternSubRule(),
433435
new TspConfigPythonMgmtPackageDirectorySubRule(),
434-
new TspConfigPythonMgmtPackageNameEqualStringSubRule(),
435-
new TspConfigPythonMgmtGenerateTestTrueSubRule(),
436-
new TspConfigPythonMgmtGenerateSampleTrueSubRule(),
436+
new TspConfigPythonDpPackageDirectorySubRule(),
437+
new TspConfigPythonAzPackageNameEqualStringSubRule(),
438+
new TspConfigPythonAzGenerateTestTrueSubRule(),
439+
new TspConfigPythonAzGenerateSampleTrueSubRule(),
437440
new TspConfigCsharpAzPackageDirectorySubRule(),
438441
new TspConfigCsharpAzNamespaceEqualStringSubRule(),
439442
new TspConfigCsharpAzClearOutputFolderTrueSubRule(),

eng/tools/typespec-validation/test/sdk-tspconfig-validation.test.ts

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ import {
2222
TspConfigGoDpServiceDirMatchPatternSubRule,
2323
TspConfigJavaAzPackageDirectorySubRule,
2424
TspConfigPythonMgmtPackageDirectorySubRule,
25-
TspConfigPythonMgmtPackageNameEqualStringSubRule,
26-
TspConfigPythonMgmtGenerateTestTrueSubRule,
27-
TspConfigPythonMgmtGenerateSampleTrueSubRule,
25+
TspConfigPythonAzPackageNameEqualStringSubRule,
26+
TspConfigPythonAzGenerateTestTrueSubRule,
27+
TspConfigPythonAzGenerateSampleTrueSubRule,
2828
TspConfigCsharpAzPackageDirectorySubRule,
2929
TspConfigCsharpAzNamespaceEqualStringSubRule,
3030
TspConfigCsharpAzClearOutputFolderTrueSubRule,
3131
TspConfigCsharpMgmtPackageDirectorySubRule,
3232
TspconfigSubRuleBase,
33+
TspConfigPythonDpPackageDirectorySubRule,
3334
} from "../src/rules/sdk-tspconfig-validation.js";
3435
import { TsvTestHost } from "./tsv-test-host.js";
3536
import { join } from "path";
@@ -112,16 +113,17 @@ function createEmitterOptionTestCases(
112113
): Case[] {
113114
const cases: Case[] = [];
114115

116+
const language = emitterName.split("-").pop();
115117
cases.push({
116-
description: `Validate ${emitterName}'s option:${key} with valid value ${validValue}`,
118+
description: `Validate ${language}'s option:${key} with valid value ${validValue}`,
117119
folder,
118120
tspconfigContent: createEmitterOptionExample(emitterName, { key: key, value: validValue }),
119121
success: true,
120122
subRules,
121123
});
122124

123125
cases.push({
124-
description: `Validate ${emitterName}'s option:${key} with invalid value ${invalidValue}`,
126+
description: `Validate ${language}'s option:${key} with invalid value ${invalidValue}`,
125127
folder,
126128
tspconfigContent: createEmitterOptionExample(emitterName, {
127129
key: key,
@@ -132,7 +134,7 @@ function createEmitterOptionTestCases(
132134
});
133135

134136
cases.push({
135-
description: `Validate ${emitterName}'s option:${key} with undefined value`,
137+
description: `Validate ${language}'s option:${key} with undefined value`,
136138
folder,
137139
tspconfigContent: createEmitterOptionExample(emitterName),
138140
success: allowUndefined ? true : false,
@@ -141,7 +143,7 @@ function createEmitterOptionTestCases(
141143

142144
if (!allowUndefined && key.includes(".")) {
143145
cases.push({
144-
description: `Validate ${emitterName}'s option:${key} with incomplete key`,
146+
description: `Validate ${language}'s option:${key} with incomplete key`,
145147
folder,
146148
tspconfigContent: createEmitterOptionExample(emitterName, {
147149
key: key.split(".").slice(0, -1).join("."),
@@ -368,7 +370,7 @@ const pythonManagementPackageNameTestCases = createEmitterOptionTestCases(
368370
"package-name",
369371
"{package-dir}",
370372
"aaa",
371-
[new TspConfigPythonMgmtPackageNameEqualStringSubRule()],
373+
[new TspConfigPythonAzPackageNameEqualStringSubRule()],
372374
);
373375

374376
const pythonManagementGenerateTestTestCases = createEmitterOptionTestCases(
@@ -377,7 +379,7 @@ const pythonManagementGenerateTestTestCases = createEmitterOptionTestCases(
377379
"generate-test",
378380
true,
379381
false,
380-
[new TspConfigPythonMgmtGenerateTestTrueSubRule()],
382+
[new TspConfigPythonAzGenerateTestTrueSubRule()],
381383
);
382384

383385
const pythonManagementGenerateSampleTestCases = createEmitterOptionTestCases(
@@ -386,7 +388,43 @@ const pythonManagementGenerateSampleTestCases = createEmitterOptionTestCases(
386388
"generate-sample",
387389
true,
388390
false,
389-
[new TspConfigPythonMgmtGenerateSampleTrueSubRule()],
391+
[new TspConfigPythonAzGenerateSampleTrueSubRule()],
392+
);
393+
394+
const pythonDpPackageDirTestCases = createEmitterOptionTestCases(
395+
"@azure-tools/typespec-python",
396+
"",
397+
"package-dir",
398+
"azure-aaa-bbb-ccc",
399+
"azure-aa-b-c-d",
400+
[new TspConfigPythonDpPackageDirectorySubRule()],
401+
);
402+
403+
const pythonAzPackageNameTestCases = createEmitterOptionTestCases(
404+
"@azure-tools/typespec-python",
405+
"",
406+
"package-name",
407+
"{package-dir}",
408+
"aaa",
409+
[new TspConfigPythonAzPackageNameEqualStringSubRule()],
410+
);
411+
412+
const pythonAzGenerateTestTestCases = createEmitterOptionTestCases(
413+
"@azure-tools/typespec-python",
414+
"",
415+
"generate-test",
416+
true,
417+
false,
418+
[new TspConfigPythonAzGenerateTestTrueSubRule()],
419+
);
420+
421+
const pythonAzGenerateSampleTestCases = createEmitterOptionTestCases(
422+
"@azure-tools/typespec-python",
423+
"",
424+
"generate-sample",
425+
true,
426+
false,
427+
[new TspConfigPythonAzGenerateSampleTrueSubRule()],
390428
);
391429

392430
const csharpAzPackageDirTestCases = createEmitterOptionTestCases(
@@ -457,6 +495,10 @@ describe("tspconfig", function () {
457495
...pythonManagementPackageNameTestCases,
458496
...pythonManagementGenerateTestTestCases,
459497
...pythonManagementGenerateSampleTestCases,
498+
...pythonDpPackageDirTestCases,
499+
...pythonAzPackageNameTestCases,
500+
...pythonAzGenerateTestTestCases,
501+
...pythonAzGenerateSampleTestCases,
460502
// csharp
461503
...csharpAzPackageDirTestCases,
462504
...csharpAzNamespaceTestCases,

0 commit comments

Comments
 (0)