From 6c4e8229b9fca90e51d94853ade767f615eb8022 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 13 Feb 2026 12:06:44 +0800 Subject: [PATCH 1/5] [python] Refactor regenerate script to extract shared utilities into regenerate-common module --- ...ctor-regenerate-common-2026-02-13-0-0-0.md | 7 + .../eng/scripts/ci/regenerate-common.ts | 476 +++++++++++++++++ .../eng/scripts/ci/regenerate.ts | 478 ++---------------- 3 files changed, 524 insertions(+), 437 deletions(-) create mode 100644 .chronus/changes/http-client-python_refactor-regenerate-common-2026-02-13-0-0-0.md create mode 100644 packages/http-client-python/eng/scripts/ci/regenerate-common.ts diff --git a/.chronus/changes/http-client-python_refactor-regenerate-common-2026-02-13-0-0-0.md b/.chronus/changes/http-client-python_refactor-regenerate-common-2026-02-13-0-0-0.md new file mode 100644 index 00000000000..0c0b5d7a4a7 --- /dev/null +++ b/.chronus/changes/http-client-python_refactor-regenerate-common-2026-02-13-0-0-0.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Refactor regenerate script to extract shared constants, interfaces, and utilities into a reusable `regenerate-common` module. diff --git a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts new file mode 100644 index 00000000000..7543f464453 --- /dev/null +++ b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts @@ -0,0 +1,476 @@ +/* eslint-disable no-console */ +import { promises } from "fs"; +import { dirname, join, relative, resolve } from "path"; + +// ---- Shared constants ---- + +export const SKIP_SPECS: string[] = ["type/file"]; + +export const SpecialFlags: Record> = { + azure: { + "generate-test": true, + "generate-sample": true, + }, +}; + +// ---- Base emitter options (shared across repos) ---- + +export const BASE_AZURE_EMITTER_OPTIONS: Record< + string, + Record | Record[] +> = { + "azure/client-generator-core/access": { + namespace: "specs.azure.clientgenerator.core.access", + }, + "azure/client-generator-core/alternate-type": { + namespace: "specs.azure.clientgenerator.core.alternatetype", + }, + "azure/client-generator-core/api-version": { + namespace: "specs.azure.clientgenerator.core.apiversion", + }, + "azure/client-generator-core/client-initialization/default": { + namespace: "specs.azure.clientgenerator.core.clientinitialization.default", + }, + "azure/client-generator-core/client-initialization/individually": { + namespace: "specs.azure.clientgenerator.core.clientinitialization.individually", + }, + "azure/client-generator-core/client-initialization/individuallyParent": { + namespace: "specs.azure.clientgenerator.core.clientinitialization.individuallyparent", + }, + "azure/client-generator-core/client-location": { + namespace: "specs.azure.clientgenerator.core.clientlocation", + }, + "azure/client-generator-core/deserialize-empty-string-as-null": { + namespace: "specs.azure.clientgenerator.core.emptystring", + }, + "azure/client-generator-core/flatten-property": { + namespace: "specs.azure.clientgenerator.core.flattenproperty", + }, + "azure/client-generator-core/usage": { + namespace: "specs.azure.clientgenerator.core.usage", + }, + "azure/client-generator-core/override": { + namespace: "specs.azure.clientgenerator.core.override", + }, + "azure/client-generator-core/hierarchy-building": { + namespace: "specs.azure.clientgenerator.core.hierarchybuilding", + }, + "azure/core/basic": { + namespace: "specs.azure.core.basic", + }, + "azure/core/lro/rpc": { + namespace: "specs.azure.core.lro.rpc", + }, + "azure/core/lro/standard": { + namespace: "specs.azure.core.lro.standard", + }, + "azure/core/model": { + namespace: "specs.azure.core.model", + }, + "azure/core/page": { + namespace: "specs.azure.core.page", + }, + "azure/core/scalar": { + namespace: "specs.azure.core.scalar", + }, + "azure/core/traits": { + namespace: "specs.azure.core.traits", + }, + "azure/encode/duration": { + namespace: "specs.azure.encode.duration", + }, + "azure/example/basic": { + namespace: "specs.azure.example.basic", + }, + "azure/payload/pageable": { + namespace: "specs.azure.payload.pageable", + }, + "azure/versioning/previewVersion": { + namespace: "specs.azure.versioning.previewversion", + }, + "client/structure/default": { + namespace: "client.structure.service", + }, + "client/structure/multi-client": { + "package-name": "client-structure-multiclient", + namespace: "client.structure.multiclient", + }, + "client/structure/renamed-operation": { + "package-name": "client-structure-renamedoperation", + namespace: "client.structure.renamedoperation", + }, + "client/structure/two-operation-group": { + "package-name": "client-structure-twooperationgroup", + namespace: "client.structure.twooperationgroup", + }, + "client/naming": { + namespace: "client.naming.main", + }, + "client/overload": { + namespace: "client.overload", + }, + "encode/duration": { + namespace: "encode.duration", + }, + "encode/numeric": { + namespace: "encode.numeric", + }, + "parameters/basic": { + namespace: "parameters.basic", + }, + "parameters/spread": { + namespace: "parameters.spread", + }, + "payload/content-negotiation": { + namespace: "payload.contentnegotiation", + }, + "payload/multipart": { + namespace: "payload.multipart", + }, + "serialization/encoded-name/json": { + namespace: "serialization.encodedname.json", + }, + "special-words": { + namespace: "specialwords", + }, + "service/multi-service": { + namespace: "service.multiservice", + }, +}; + +export const BASE_EMITTER_OPTIONS: Record< + string, + Record | Record[] +> = { + "resiliency/srv-driven/old.tsp": { + "package-name": "resiliency-srv-driven1", + namespace: "resiliency.srv.driven1", + "package-mode": "azure-dataplane", + "package-pprint-name": "ResiliencySrvDriven1", + }, + "resiliency/srv-driven": { + "package-name": "resiliency-srv-driven2", + namespace: "resiliency.srv.driven2", + "package-mode": "azure-dataplane", + "package-pprint-name": "ResiliencySrvDriven2", + }, + "authentication/api-key": { + "clear-output-folder": "true", + }, + "authentication/http/custom": { + "package-name": "authentication-http-custom", + namespace: "authentication.http.custom", + "package-pprint-name": "Authentication Http Custom", + }, + "authentication/union": [ + { + "package-name": "authentication-union", + namespace: "authentication.union", + }, + { + "package-name": "setuppy-authentication-union", + namespace: "setuppy.authentication.union", + "keep-setup-py": "true", + }, + ], + "type/array": { + "package-name": "typetest-array", + namespace: "typetest.array", + }, + "type/dictionary": { + "package-name": "typetest-dictionary", + namespace: "typetest.dictionary", + }, + "type/enum/extensible": { + "package-name": "typetest-enum-extensible", + namespace: "typetest.enum.extensible", + }, + "type/enum/fixed": { + "package-name": "typetest-enum-fixed", + namespace: "typetest.enum.fixed", + }, + "type/model/empty": { + "package-name": "typetest-model-empty", + namespace: "typetest.model.empty", + }, + "type/model/inheritance/enum-discriminator": { + "package-name": "typetest-model-enumdiscriminator", + namespace: "typetest.model.enumdiscriminator", + }, + "type/model/inheritance/nested-discriminator": { + "package-name": "typetest-model-nesteddiscriminator", + namespace: "typetest.model.nesteddiscriminator", + }, + "type/model/inheritance/not-discriminated": { + "package-name": "typetest-model-notdiscriminated", + namespace: "typetest.model.notdiscriminated", + }, + "type/model/inheritance/single-discriminator": { + "package-name": "typetest-model-singlediscriminator", + namespace: "typetest.model.singlediscriminator", + }, + "type/model/inheritance/recursive": { + "package-name": "typetest-model-recursive", + namespace: "typetest.model.recursive", + }, + "type/model/usage": { + "package-name": "typetest-model-usage", + namespace: "typetest.model.usage", + }, + "type/model/visibility": [ + { + "package-name": "typetest-model-visibility", + namespace: "typetest.model.visibility", + }, + { + "package-name": "headasbooleantrue", + namespace: "headasbooleantrue", + "head-as-boolean": "true", + }, + { + "package-name": "headasbooleanfalse", + namespace: "headasbooleanfalse", + "head-as-boolean": "false", + }, + ], + "type/property/nullable": { + "package-name": "typetest-property-nullable", + namespace: "typetest.property.nullable", + }, + "type/property/optionality": { + "package-name": "typetest-property-optional", + namespace: "typetest.property.optional", + }, + "type/property/additional-properties": { + "package-name": "typetest-property-additionalproperties", + namespace: "typetest.property.additionalproperties", + }, + "type/scalar": { + "package-name": "typetest-scalar", + namespace: "typetest.scalar", + }, + "type/property/value-types": { + "package-name": "typetest-property-valuetypes", + namespace: "typetest.property.valuetypes", + }, + "type/union": { + "package-name": "typetest-union", + namespace: "typetest.union", + }, + "type/union/discriminated": { + "package-name": "typetest-discriminatedunion", + namespace: "typetest.discriminatedunion", + }, + "type/file": { + "package-name": "typetest-file", + namespace: "typetest.file", + }, + documentation: { + "package-name": "specs-documentation", + namespace: "specs.documentation", + }, +}; + +// ---- Shared interfaces ---- + +export interface TspCommand { + outputDir: string; + command: string | string[]; +} + +export interface RegenerateFlagsInput { + flavor?: string; + debug?: boolean; + name?: string; + pyodide?: boolean; +} + +export interface RegenerateFlags { + flavor: string; + debug: boolean; + name?: string; + pyodide?: boolean; +} + +export interface ProcessedEmitterOption { + options: Record; + outputDir: string; +} + +export interface RegenerateConfig { + azureHttpSpecs: string; + httpSpecs: string; + emitterOptions: Record | Record[]>; + azureEmitterOptions: Record | Record[]>; + preprocess: (flags: RegenerateFlagsInput) => Promise; + getCmdList: (spec: string, flags: RegenerateFlags) => TspCommand[]; + executeCommand: (cmd: TspCommand) => Promise; +} + +// ---- Shared utility functions ---- + +export function toPosix(dir: string): string { + return dir.replace(/\\/g, "/"); +} + +export function getEmitterOption( + spec: string, + flavor: string, + config: RegenerateConfig, +): Record[] { + const specDir = spec.includes("azure") ? config.azureHttpSpecs : config.httpSpecs; + const relativeSpec = toPosix(relative(specDir, spec)); + const key = relativeSpec.includes("resiliency/srv-driven/old.tsp") + ? relativeSpec + : dirname(relativeSpec); + const emitter_options = config.emitterOptions[key] || + (flavor === "azure" ? config.azureEmitterOptions[key] : [{}]) || [{}]; + return Array.isArray(emitter_options) ? emitter_options : [emitter_options]; +} + +export async function getSubdirectories( + baseDir: string, + flags: RegenerateFlags, +): Promise { + const subdirectories: string[] = []; + + async function searchDir(currentDir: string) { + const items = await promises.readdir(currentDir, { withFileTypes: true }); + + const promisesArray = items.map(async (item) => { + const subDirPath = join(currentDir, item.name); + if (item.isDirectory()) { + const mainTspPath = join(subDirPath, "main.tsp"); + const clientTspPath = join(subDirPath, "client.tsp"); + + const mainTspRelativePath = toPosix(relative(baseDir, mainTspPath)); + + if (SKIP_SPECS.some((skipSpec) => mainTspRelativePath.includes(skipSpec))) return; + + const hasMainTsp = await promises + .access(mainTspPath) + .then(() => true) + .catch(() => false); + const hasClientTsp = await promises + .access(clientTspPath) + .then(() => true) + .catch(() => false); + + if (mainTspRelativePath.toLowerCase().includes(flags.name || "")) { + if (mainTspRelativePath.includes("resiliency/srv-driven")) { + subdirectories.push(resolve(subDirPath, "old.tsp")); + } + if (hasClientTsp) { + subdirectories.push(resolve(subDirPath, "client.tsp")); + } else if (hasMainTsp) { + subdirectories.push(resolve(subDirPath, "main.tsp")); + } + } + + // Recursively search in the subdirectory + await searchDir(subDirPath); + } + }); + + await Promise.all(promisesArray); + } + + await searchDir(baseDir); + return subdirectories; +} + +export function defaultPackageName( + spec: string, + config: RegenerateConfig, +): string { + const specDir = spec.includes("azure") ? config.azureHttpSpecs : config.httpSpecs; + return toPosix(relative(specDir, dirname(spec))) + .replace(/\//g, "-") + .toLowerCase(); +} + +export function buildOptions( + spec: string, + generatedFolder: string, + flags: RegenerateFlags, + config: RegenerateConfig, +): ProcessedEmitterOption[] { + const results: ProcessedEmitterOption[] = []; + for (const emitterConfig of getEmitterOption(spec, flags.flavor, config)) { + const options: Record = { ...emitterConfig }; + if (flags.pyodide) { + options["use-pyodide"] = "true"; + } + options["flavor"] = flags.flavor; + for (const [k, v] of Object.entries(SpecialFlags[flags.flavor] ?? {})) { + options[k] = v; + } + if (options["emitter-output-dir"] === undefined) { + const packageName = options["package-name"] || defaultPackageName(spec, config); + options["emitter-output-dir"] = toPosix( + `${generatedFolder}/test/${flags.flavor}/generated/${packageName}`, + ); + } + if (flags.debug) { + options["debug"] = "true"; + } + options["examples-dir"] = toPosix(join(dirname(spec), "examples")); + results.push({ + options, + outputDir: options["emitter-output-dir"], + }); + } + return results; +} + +export async function runTaskPool( + tasks: Array<() => Promise>, + poolLimit: number, +): Promise { + async function worker(start: number, end: number) { + while (start < end) { + await tasks[start](); + start++; + } + } + + const workers = []; + let start = 0; + while (start < tasks.length) { + const end = Math.min(start + poolLimit, tasks.length); + workers.push((async () => await worker(start, end))()); + start = end; + } + await Promise.all(workers); +} + +export async function regenerate( + flags: RegenerateFlagsInput, + config: RegenerateConfig, +): Promise { + if (flags.flavor === undefined) { + await regenerate({ flavor: "azure", ...flags }, config); + await regenerate({ flavor: "unbranded", ...flags }, config); + } else { + await config.preprocess(flags); + + const flagsResolved: RegenerateFlags = { debug: false, flavor: flags.flavor, ...flags }; + const subdirectoriesForAzure = await getSubdirectories(config.azureHttpSpecs, flagsResolved); + const subdirectoriesForNonAzure = await getSubdirectories(config.httpSpecs, flagsResolved); + const subdirectories = + flags.flavor === "azure" + ? [...subdirectoriesForAzure, ...subdirectoriesForNonAzure] + : subdirectoriesForNonAzure; + const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) => + config.getCmdList(subdirectory, flagsResolved), + ); + + // Create tasks as functions for the pool + const tasks: Array<() => Promise> = cmdList.map((tspCommand) => { + return () => config.executeCommand(tspCommand); + }); + + // Run tasks with a concurrency limit + await runTaskPool(tasks, 30); + } +} diff --git a/packages/http-client-python/eng/scripts/ci/regenerate.ts b/packages/http-client-python/eng/scripts/ci/regenerate.ts index 631a6ad384b..84bc53727bd 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate.ts @@ -2,9 +2,20 @@ import chalk from "chalk"; import { execFile } from "child_process"; import { promises, rmSync } from "fs"; -import { dirname, join, relative, resolve } from "path"; +import { join, resolve } from "path"; import { fileURLToPath } from "url"; import { parseArgs, promisify } from "util"; +import { + BASE_AZURE_EMITTER_OPTIONS, + BASE_EMITTER_OPTIONS, + buildOptions, + regenerate, + toPosix, + type RegenerateConfig, + type RegenerateFlags, + type RegenerateFlagsInput, + type TspCommand, +} from "./regenerate-common.js"; // PARSE INPUT ARGUMENTS @@ -21,9 +32,6 @@ const argv = parseArgs({ }, }); -// Add this near the top with other constants -const SKIP_SPECS: string[] = ["type/file"]; - // Get the directory of the current file const PLUGIN_DIR = argv.values.pluginDir ? resolve(argv.values.pluginDir) @@ -33,290 +41,38 @@ const HTTP_SPECS = resolve(PLUGIN_DIR, "node_modules/@typespec/http-specs/specs" const GENERATED_FOLDER = argv.values.generatedFolder ? resolve(argv.values.generatedFolder) : resolve(PLUGIN_DIR, "generator"); - -interface TspCommand { - outputDir: string; - command: string[]; -} +const EMITTER_NAME = argv.values.emitterName || "@typespec/http-client-python"; const AZURE_EMITTER_OPTIONS: Record | Record[]> = { - "azure/client-generator-core/access": { - namespace: "specs.azure.clientgenerator.core.access", - }, - "azure/client-generator-core/alternate-type": { - namespace: "specs.azure.clientgenerator.core.alternatetype", - }, - "azure/client-generator-core/api-version": { - namespace: "specs.azure.clientgenerator.core.apiversion", - }, - "azure/client-generator-core/client-initialization/default": { - namespace: "specs.azure.clientgenerator.core.clientinitialization.default", - }, - "azure/client-generator-core/client-initialization/individually": { - namespace: "specs.azure.clientgenerator.core.clientinitialization.individually", - }, - "azure/client-generator-core/client-initialization/individuallyParent": { - namespace: "specs.azure.clientgenerator.core.clientinitialization.individuallyparent", - }, - "azure/client-generator-core/client-location": { - namespace: "specs.azure.clientgenerator.core.clientlocation", - }, - "azure/client-generator-core/deserialize-empty-string-as-null": { - namespace: "specs.azure.clientgenerator.core.emptystring", - }, - "azure/client-generator-core/flatten-property": { - namespace: "specs.azure.clientgenerator.core.flattenproperty", - }, - "azure/client-generator-core/usage": { - namespace: "specs.azure.clientgenerator.core.usage", - }, - "azure/client-generator-core/override": { - namespace: "specs.azure.clientgenerator.core.override", - }, - "azure/client-generator-core/hierarchy-building": { - namespace: "specs.azure.clientgenerator.core.hierarchybuilding", - }, - "azure/core/basic": { - namespace: "specs.azure.core.basic", - }, - "azure/core/lro/rpc": { - namespace: "specs.azure.core.lro.rpc", - }, - "azure/core/lro/standard": { - namespace: "specs.azure.core.lro.standard", - }, - "azure/core/model": { - namespace: "specs.azure.core.model", - }, - "azure/core/page": { - namespace: "specs.azure.core.page", - }, - "azure/core/scalar": { - namespace: "specs.azure.core.scalar", - }, - "azure/core/traits": { - namespace: "specs.azure.core.traits", - }, - "azure/encode/duration": { - namespace: "specs.azure.encode.duration", - }, - "azure/example/basic": { - namespace: "specs.azure.example.basic", - }, - "azure/payload/pageable": { - namespace: "specs.azure.payload.pageable", - }, - "azure/versioning/previewVersion": { - namespace: "specs.azure.versioning.previewversion", - }, - "client/structure/default": { - namespace: "client.structure.service", - }, + ...BASE_AZURE_EMITTER_OPTIONS, "client/structure/client-operation-group": { "package-name": "client-structure-clientoperationgroup", namespace: "client.structure.clientoperationgroup", }, - "client/structure/multi-client": { - "package-name": "client-structure-multiclient", - namespace: "client.structure.multiclient", - }, - "client/structure/renamed-operation": { - "package-name": "client-structure-renamedoperation", - namespace: "client.structure.renamedoperation", - }, - "client/structure/two-operation-group": { - "package-name": "client-structure-twooperationgroup", - namespace: "client.structure.twooperationgroup", - }, - "client/naming": { - namespace: "client.naming.main", - }, - "client/overload": { - namespace: "client.overload", - }, - "encode/duration": { - namespace: "encode.duration", - }, - "encode/numeric": { - namespace: "encode.numeric", - }, - "parameters/basic": { - namespace: "parameters.basic", - }, - "parameters/spread": { - namespace: "parameters.spread", - }, - "payload/content-negotiation": { - namespace: "payload.contentnegotiation", - }, - "payload/multipart": { - namespace: "payload.multipart", - }, - "serialization/encoded-name/json": { - namespace: "serialization.encodedname.json", - }, - "special-words": { - namespace: "specialwords", - }, - "service/multi-service": { - namespace: "service.multiservice", - }, }; const EMITTER_OPTIONS: Record | Record[]> = { - "resiliency/srv-driven/old.tsp": { - "package-name": "resiliency-srv-driven1", - namespace: "resiliency.srv.driven1", - "package-mode": "azure-dataplane", - "package-pprint-name": "ResiliencySrvDriven1", - }, - "resiliency/srv-driven": { - "package-name": "resiliency-srv-driven2", - namespace: "resiliency.srv.driven2", - "package-mode": "azure-dataplane", - "package-pprint-name": "ResiliencySrvDriven2", - }, - "authentication/api-key": { - "clear-output-folder": "true", - }, - "authentication/http/custom": { - "package-name": "authentication-http-custom", - namespace: "authentication.http.custom", - "package-pprint-name": "Authentication Http Custom", - }, - "authentication/union": [ - { - "package-name": "authentication-union", - namespace: "authentication.union", - }, - { - "package-name": "setuppy-authentication-union", - namespace: "setuppy.authentication.union", - "keep-setup-py": "true", - }, - ], + ...BASE_EMITTER_OPTIONS, "type/array": { "package-name": "typetest-array", namespace: "typetest.array", "use-pyodide": "true", }, - "type/dictionary": { - "package-name": "typetest-dictionary", - namespace: "typetest.dictionary", - }, - "type/enum/extensible": { - "package-name": "typetest-enum-extensible", - namespace: "typetest.enum.extensible", - }, - "type/enum/fixed": { - "package-name": "typetest-enum-fixed", - namespace: "typetest.enum.fixed", - }, - "type/model/empty": { - "package-name": "typetest-model-empty", - namespace: "typetest.model.empty", - }, - "type/model/inheritance/enum-discriminator": { - "package-name": "typetest-model-enumdiscriminator", - namespace: "typetest.model.enumdiscriminator", - }, - "type/model/inheritance/nested-discriminator": { - "package-name": "typetest-model-nesteddiscriminator", - namespace: "typetest.model.nesteddiscriminator", - }, - "type/model/inheritance/not-discriminated": { - "package-name": "typetest-model-notdiscriminated", - namespace: "typetest.model.notdiscriminated", - }, - "type/model/inheritance/single-discriminator": { - "package-name": "typetest-model-singlediscriminator", - namespace: "typetest.model.singlediscriminator", - }, "type/model/inheritance/recursive": { "package-name": "typetest-model-recursive", namespace: "typetest.model.recursive", "use-pyodide": "true", }, - "type/model/usage": { - "package-name": "typetest-model-usage", - namespace: "typetest.model.usage", - }, - "type/model/visibility": [ - { - "package-name": "typetest-model-visibility", - namespace: "typetest.model.visibility", - }, - { - "package-name": "headasbooleantrue", - namespace: "headasbooleantrue", - "head-as-boolean": "true", - }, - { - "package-name": "headasbooleanfalse", - namespace: "headasbooleanfalse", - "head-as-boolean": "false", - }, - ], - "type/property/nullable": { - "package-name": "typetest-property-nullable", - namespace: "typetest.property.nullable", - }, - "type/property/optionality": { - "package-name": "typetest-property-optional", - namespace: "typetest.property.optional", - }, - "type/property/additional-properties": { - "package-name": "typetest-property-additionalproperties", - namespace: "typetest.property.additionalproperties", - }, - "type/scalar": { - "package-name": "typetest-scalar", - namespace: "typetest.scalar", - }, - "type/property/value-types": { - "package-name": "typetest-property-valuetypes", - namespace: "typetest.property.valuetypes", - }, - "type/union": { - "package-name": "typetest-union", - namespace: "typetest.union", - }, - "type/union/discriminated": { - "package-name": "typetest-discriminatedunion", - namespace: "typetest.discriminatedunion", - }, - "type/file": { - "package-name": "typetest-file", - namespace: "typetest.file", - }, - documentation: { - "package-name": "specs-documentation", - namespace: "specs.documentation", - }, }; -function toPosix(dir: string): string { - return dir.replace(/\\/g, "/"); -} - -function getEmitterOption(spec: string, flavor: string): Record[] { - const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS; - const relativeSpec = toPosix(relative(specDir, spec)); - const key = relativeSpec.includes("resiliency/srv-driven/old.tsp") - ? relativeSpec - : dirname(relativeSpec); - const emitter_options = EMITTER_OPTIONS[key] || - (flavor === "azure" ? AZURE_EMITTER_OPTIONS[key] : [{}]) || [{}]; - return Array.isArray(emitter_options) ? emitter_options : [emitter_options]; -} - // Function to execute CLI commands asynchronously async function executeCommand(tspCommand: TspCommand): Promise { + const cmd = tspCommand.command as string[]; const execFileAsync = promisify(execFile); try { - console.log(chalk.green(`start tsp ${tspCommand.command.join(" ")}`)); - await execFileAsync("tsp", tspCommand.command, { shell: true }); - console.log(chalk.green(`tsp ${tspCommand.command.join(" ")} succeeded`)); + console.log(chalk.green(`start tsp ${cmd.join(" ")}`)); + await execFileAsync("tsp", cmd, { shell: true }); + console.log(chalk.green(`tsp ${cmd.join(" ")} succeeded`)); } catch (err) { rmSync(tspCommand.outputDir, { recursive: true, force: true }); console.error(chalk.red(`exec error: ${err}`)); @@ -324,153 +80,6 @@ async function executeCommand(tspCommand: TspCommand): Promise { } } -interface RegenerateFlagsInput { - flavor?: string; - debug?: boolean; - name?: string; - pyodide?: boolean; -} - -interface RegenerateFlags { - flavor: string; - debug: boolean; - name?: string; - pyodide?: boolean; -} - -const SpecialFlags: Record> = { - azure: { - "generate-test": true, - "generate-sample": true, - }, -}; - -async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promise { - const subdirectories: string[] = []; - - async function searchDir(currentDir: string) { - const items = await promises.readdir(currentDir, { withFileTypes: true }); - - const promisesArray = items.map(async (item) => { - const subDirPath = join(currentDir, item.name); - if (item.isDirectory()) { - const mainTspPath = join(subDirPath, "main.tsp"); - const clientTspPath = join(subDirPath, "client.tsp"); - - const mainTspRelativePath = toPosix(relative(baseDir, mainTspPath)); - - // Replace the individual skip checks with: - if (SKIP_SPECS.some((skipSpec) => mainTspRelativePath.includes(skipSpec))) return; - - const hasMainTsp = await promises - .access(mainTspPath) - .then(() => true) - .catch(() => false); - const hasClientTsp = await promises - .access(clientTspPath) - .then(() => true) - .catch(() => false); - - if (mainTspRelativePath.toLowerCase().includes(flags.name || "")) { - if (mainTspRelativePath.includes("resiliency/srv-driven")) { - subdirectories.push(resolve(subDirPath, "old.tsp")); - } - if (hasClientTsp) { - subdirectories.push(resolve(subDirPath, "client.tsp")); - } else if (hasMainTsp) { - subdirectories.push(resolve(subDirPath, "main.tsp")); - } - } - - // Recursively search in the subdirectory - await searchDir(subDirPath); - } - }); - - await Promise.all(promisesArray); - } - - await searchDir(baseDir); - return subdirectories; -} - -function defaultPackageName(spec: string): string { - const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS; - return toPosix(relative(specDir, dirname(spec))) - .replace(/\//g, "-") - .toLowerCase(); -} - -interface EmitterConfig { - options: string[]; - outputDir: string; -} - -function addOptions( - spec: string, - generatedFolder: string, - flags: RegenerateFlags, -): EmitterConfig[] { - const emitterConfigs: EmitterConfig[] = []; - for (const config of getEmitterOption(spec, flags.flavor)) { - const options: Record = { ...config }; - if (flags.pyodide) { - options["use-pyodide"] = "true"; - } - options["flavor"] = flags.flavor; - for (const [k, v] of Object.entries(SpecialFlags[flags.flavor] ?? {})) { - options[k] = v; - } - if (options["emitter-output-dir"] === undefined) { - const packageName = options["package-name"] || defaultPackageName(spec); - options["emitter-output-dir"] = toPosix( - `${generatedFolder}/test/${flags.flavor}/generated/${packageName}`, - ); - } - if (flags.debug) { - options["debug"] = "true"; - } - options["examples-dir"] = toPosix(join(dirname(spec), "examples")); - const configs = Object.entries(options).flatMap(([k, v]) => { - return [ - "--option", - `${argv.values.emitterName || "@typespec/http-client-python"}.${k}="${v}"`, - ]; - }); - emitterConfigs.push({ - options: configs, - outputDir: options["emitter-output-dir"], - }); - } - return emitterConfigs; -} -function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] { - return addOptions(spec, GENERATED_FOLDER, flags).map((option) => { - return { - outputDir: option.outputDir, - command: ["compile", spec, "--emit", toPosix(PLUGIN_DIR), ...option.options], - }; - }); -} - -async function runTaskPool(tasks: Array<() => Promise>, poolLimit: number): Promise { - async function worker(start: number, end: number) { - while (start < end) { - await tasks[start](); - start++; - } - } - - const workers = []; - let start = 0; - while (start < tasks.length) { - const end = Math.min(start + poolLimit, tasks.length); - workers.push((async () => await worker(start, end))()); - start = end; - } - await Promise.all(workers); -} - // create some files before regeneration. After regeneration, these files should be deleted and we will test it // in test case async function preprocess(flags: RegenerateFlagsInput): Promise { @@ -493,36 +102,31 @@ async function preprocess(flags: RegenerateFlagsInput): Promise { } } -async function regenerate(flags: RegenerateFlagsInput): Promise { - if (flags.flavor === undefined) { - await regenerate({ flavor: "azure", ...flags }); - await regenerate({ flavor: "unbranded", ...flags }); - } else { - await preprocess(flags); - - const flagsResolved = { debug: false, flavor: flags.flavor, ...flags }; - const subdirectoriesForAzure = await getSubdirectories(AZURE_HTTP_SPECS, flagsResolved); - const subdirectoriesForNonAzure = await getSubdirectories(HTTP_SPECS, flagsResolved); - const subdirectories = - flags.flavor === "azure" - ? [...subdirectoriesForAzure, ...subdirectoriesForNonAzure] - : subdirectoriesForNonAzure; - const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) => - _getCmdList(subdirectory, flagsResolved), - ); - - // Create tasks as functions for the pool - const tasks: Array<() => Promise> = cmdList.map((tspCommand) => { - return () => executeCommand(tspCommand); - }); - - // Run tasks with a concurrency limit - await runTaskPool(tasks, 30); - } +function _getCmdList(spec: string, flags: RegenerateFlags): TspCommand[] { + return buildOptions(spec, GENERATED_FOLDER, flags, config).map((po) => { + const optionArgs = Object.entries(po.options).flatMap(([k, v]) => [ + "--option", + `${EMITTER_NAME}.${k}="${v}"`, + ]); + return { + outputDir: po.outputDir, + command: ["compile", spec, "--emit", toPosix(PLUGIN_DIR), ...optionArgs], + }; + }); } +const config: RegenerateConfig = { + azureHttpSpecs: AZURE_HTTP_SPECS, + httpSpecs: HTTP_SPECS, + emitterOptions: EMITTER_OPTIONS, + azureEmitterOptions: AZURE_EMITTER_OPTIONS, + preprocess, + getCmdList: _getCmdList, + executeCommand, +}; + const start = performance.now(); -regenerate(argv.values) +regenerate(argv.values, config) .then(() => console.log( chalk.green( From f3c0350d6f9cd6e5e648171243f7060c52f2de38 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 13 Feb 2026 12:55:22 +0800 Subject: [PATCH 2/5] format --- .../http-client-python/eng/scripts/ci/regenerate-common.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts index 7543f464453..fc36c9382c6 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts @@ -379,10 +379,7 @@ export async function getSubdirectories( return subdirectories; } -export function defaultPackageName( - spec: string, - config: RegenerateConfig, -): string { +export function defaultPackageName(spec: string, config: RegenerateConfig): string { const specDir = spec.includes("azure") ? config.azureHttpSpecs : config.httpSpecs; return toPosix(relative(specDir, dirname(spec))) .replace(/\//g, "-") From 5840d4785194b2b89eec743a5dd47379fa264658 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 13 Feb 2026 12:59:37 +0800 Subject: [PATCH 3/5] fix lint --- packages/http-client-python/eng/scripts/ci/regenerate-common.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts index fc36c9382c6..9f9a91266d6 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import { promises } from "fs"; import { dirname, join, relative, resolve } from "path"; From ea6ec8cb99fe9dc08cd950ab8465d90b5d6fba6f Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 13 Feb 2026 13:28:55 +0800 Subject: [PATCH 4/5] [python] Add section markers to requirements.txt files for shared dependencies --- .../http-client-python/generator/test/azure/requirements.txt | 5 ++++- .../generator/test/unbranded/requirements.txt | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/http-client-python/generator/test/azure/requirements.txt b/packages/http-client-python/generator/test/azure/requirements.txt index 0a0439bdccb..996b8b767cb 100644 --- a/packages/http-client-python/generator/test/azure/requirements.txt +++ b/packages/http-client-python/generator/test/azure/requirements.txt @@ -2,6 +2,7 @@ -e ../../ azure-mgmt-core==1.6.0 +# === common azure dependencies across repos === # only for azure -e ./generated/azure-client-generator-core-access -e ./generated/azure-client-generator-core-api-version-header @@ -55,8 +56,9 @@ azure-mgmt-core==1.6.0 -e ./generated/resiliency-srv-driven1 -e ./generated/resiliency-srv-driven2 -e ./generated/service-multi-service +# === end common azure dependencies across repos === -# common test case +# === common test dependencies across repos === -e ./generated/authentication-api-key -e ./generated/authentication-http-custom -e ./generated/authentication-noauth-union @@ -121,3 +123,4 @@ azure-mgmt-core==1.6.0 -e ./generated/versioning-renamedfrom -e ./generated/versioning-returntypechangedfrom -e ./generated/versioning-typechangedfrom +# === end common test dependencies across repos === diff --git a/packages/http-client-python/generator/test/unbranded/requirements.txt b/packages/http-client-python/generator/test/unbranded/requirements.txt index 7dfecf1f78b..9fd6dd58cbc 100644 --- a/packages/http-client-python/generator/test/unbranded/requirements.txt +++ b/packages/http-client-python/generator/test/unbranded/requirements.txt @@ -1,7 +1,7 @@ -r ../dev_requirements.txt -e ../../ -# common test case +# === common test dependencies across repos === -e ./generated/authentication-api-key -e ./generated/authentication-http-custom -e ./generated/authentication-noauth-union @@ -66,3 +66,4 @@ -e ./generated/versioning-renamedfrom -e ./generated/versioning-returntypechangedfrom -e ./generated/versioning-typechangedfrom +# === end common test dependencies across repos === From 4005e5ab5b6dd423841b7e169fef00f5f87fee81 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 13 Feb 2026 14:49:56 +0800 Subject: [PATCH 5/5] [python] Add test data files and improve test coverage for encode bytes and clear output folder --- .../mock_api_tests/test_clear_output_folder.py | 9 +++++++++ .../asynctests/test_encode_bytes_async.py | 7 ++++++- .../test/generic_mock_api_tests/data/image.jpg | Bin 0 -> 4069 bytes .../test/generic_mock_api_tests/data/image.png | Bin 0 -> 2992 bytes .../test_encode_bytes.py | 6 ++++++ .../unbranded/mock_api_tests/test_unbranded.py | 17 +++++++++-------- 6 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/data/image.jpg create mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/data/image.png diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_clear_output_folder.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_clear_output_folder.py index 5c85955dbe0..c49c8bf1d94 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/test_clear_output_folder.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/test_clear_output_folder.py @@ -12,3 +12,12 @@ def test_clear_output_folder(): folder = GENERATED_PATH / "authentication-api-key/authentication/apikey/_operations" assert folder.exists(), "Operations folder should exist" assert not (folder / "to_be_deleted.py").exists(), "File to_be_deleted.py should be deleted after regeneration" + + if (GENERATED_PATH / "generation-subdir").exists(): + assert (GENERATED_PATH / "generation-subdir/generated_tests").exists() + assert not (GENERATED_PATH / "generation-subdir/generated_tests/to_be_deleted.py").exists() + + assert (GENERATED_PATH / "generation-subdir/generation/subdir/_generated").exists() + assert not (GENERATED_PATH / "generation-subdir/generation/subdir/_generated/to_be_deleted.py").exists() + + assert (GENERATED_PATH / "generation-subdir/generation/subdir/to_be_kept.py").exists() diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py index 93f8f62c68d..584b277edd9 100644 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py +++ b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py @@ -13,7 +13,6 @@ Base64urlArrayBytesProperty, ) - FILE_FOLDER = Path(__file__).parent.parent @@ -98,6 +97,12 @@ async def test_header(client: BytesClient): ) +@pytest.fixture +def png_data() -> bytes: + with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in: + return file_in.read() + + @pytest.mark.asyncio async def test_request_body(client: BytesClient, png_data: bytes): await client.request_body.default( diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/data/image.jpg b/packages/http-client-python/generator/test/generic_mock_api_tests/data/image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b95b3e7b58286ad3e665d98d48b345977f862403 GIT binary patch literal 4069 zcmeHJX;@QN8a_8Gn*#{~QJ4uNv1G6$BrHN6AVrn}mbL^3a4V7!OhA&51QRm!5kx@+ zTNcGZ6cC$Q+;~`GASla}wUxz{#c@GKXr)k4Y@<*!Hx%*D{OB`(hxgoj&v(xGzVDv* zyZ1cLYZx{>23FxAVIcs504RVPFpPlD9#xbBu1V2)YXM|gXB#0R#?0;vho@Ai`n{4K2Z_tc-vVNE8}_H8C|ahaEIl00AM92ow^HM!{MR`W#*d zC>$E^#0bDxN5*4GscV^8g=bC3n`_%`I5%f0?p)~sQ!`sT!n*Yv-gBn@)y2cpYm>JR zD=;WH4t_4#kAFVxjHXs&7-n{@yDwxhGFyQlZNTet7ry*D&GGCKBT{NGO}CV%+x+1&FN z^Dlq-RsZU>kryl_f2RdM|0^#X%nN}+AyHT(F9@M9633y?P7Dk_AQBs&YE5EhnXKJh zc(%6PlpPs~<`z2kKs1OmhoPzVGH-Zu)3MZ>_F zVvR60H(i4HGS)1?$_V@l3~&{b9rK09ND}!zi#oLh#Ro!~r%~ ztf@M>v0>6|AHFNXRdW{F2PwyE*zd{a+%36uhi4yu9aJ^ zpE7`9t8Rioz2KlN=S`ybbp-7ElQg->VN&I!l@n$S;9H_)yZXl$&PTX9ZObWvjhcE$f>gQt?~wSk)wt*@QfJ9e zFelD#>m0AB_sUj(c%Hr(E_yV;phB&=i9g9-)lO~OzQ2==_`u&bT{~<52lxK#Ow_NO zH{&-1-x&aQ;LQ0M(Zy$<1nTsq)xvVR{*&=ztX;IOz6|@z-F$Uf=(W0nyex6{P>FpW z4;0_dipualIew@$bH3M?aaJh~zSVba_s(ZYwY`7uX0rQ=C{sn1g*}wrL&Zt0cwal& z|(+)A&#XhLRoSPH3mt4Ji?-$~1F~yma)AnXu zRaaV$2SjEq$b{PVCY+v+iL;w8BOWVxgqdDst2gCLzog0=vM#q5L^ScNF_ipEjeb6n z1J0h4Y=S>iPa2P#Wgqq@^xWzm>-n^78z*$sXAucKo}EO|0uu3 zLs)^AUypvJF<+QUj|p5L&+NFzk0eJN%fi)?Gy8fd4jBz;gBAkjn_MPYks`G3a33&nP_o zg=l|nT>VF<@}|PZtIypU-TXbb#NA#UwTKA877jAo-sRoA;|O7M!oq~_ndaKA)cm{QH_jPuzCA+J zs!aHNWSYHBYfaj3>w14Gdb?$=t7cDh+;r%rP@Vlr;qGatS1nE0#?Fk+V2@G6gWq0G nRDbTJ{wDPH&YhvRw~$ZQH=nuD@w!Nwq+ZJbRY$2v!^nRCgjEVM literal 0 HcmV?d00001 diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/data/image.png b/packages/http-client-python/generator/test/generic_mock_api_tests/data/image.png new file mode 100644 index 0000000000000000000000000000000000000000..42fe8dc14560b0046bf0f3f00b7a471fa0346e36 GIT binary patch literal 2992 zcmaJ>2UJtr5=}ynfPe^6#i)oP2~A3b_#j9P<c=;9z@urf$wEd&r0Smmc~ z4b}n)eX~PAprkO6@Q)ZL0M}MJAZwiOD16}zNDSD?0g_k*{=o$NMUbCNY?07U9S+2S zEZop`b^yBJDZ#-+YAA`O;C(9uFi4PXy{I6N!uB-*+qrI=1#0z#xnpTqM+_2ABESQJ zNP)p{I)S{F2V_P^0xBVx7N9{V941ncbaU9Z2qd7dnGrCJZy~e@a~RgqMFUNu1Zx<< zb>X@&6jVb)!;BJi2rs64KWLg-BsIiteAdnPEGl#*}3jJK)-!qsV_Nx++`r}x@ z0TF8+gdSWM@iR9-HCwYHUBc+WhrO)A2tdz(8Yn{}vv1-5tZHzM{I(Zu9;;%|=s zCVEhVDQFS_C`d#7x~w1M-<>~*W{9LqLSH=UG`#0SvISvT&z^Cv#7@xJSx2aa-|9tm}-z6Hc>u#KDm+I4F>M3G9RmW+_?M2)1;gWo3xcVR@W8PHPH4h8*{++h z8}Y5F9`(=WPeZXH<+|Y0gJnwP5YL?0zo!3|^aN{T{s{OKE?O45QM0I0;1yDN`SND{ zyOg5mp)N5c(u0Esp-E=kfllR0C&k1s@i0GrZRfs5<7!+x0s^%ugM8%*ef;#PiEVR~ zk~180fRXw!|2qMhFy2QQNA)X#rKKLKFql@YS0DB+8Y~M0L6l6MBxAd5adGjcF9c8t zo3^yHG!i%{(t~?+_KjG%t?wg9W@hGn@>d^2zlX4eDsq69+{GOYhow*ZZ9YFY+;qgj z#AWZ^z2xho`YaYJ$mptuez>fhT&9eIf;49^mEC)&XN9ajcTsqPhD7C%d`TOUID=@6 zW~%vaGf31w{D~F5LO*H9Ul5b;M$_L~@5Rf{$YXmij@GSqZ($ztNsv;Z`i@;wgI)yL z`tVD3-D4YatT^h!2`{f7xgFBk(KVv6D=iyOe>q)Zxtu3f1vhZeoRRfQZ3s>DQ~|{c zhLZ7j^pqm{@Kbe|+)KiSAs)dZlW4Rb|0>x!mf7eaT?yRGZFm;h)5lP}0s z)MR+lRu=;7XofSxFZS5kB(Io?U<4$)=j+Ujv-f1z7}jT(U8oBF@c2?YjHZlX3}y?2 zB}I!j)%5LcxOt457x{YKwWQLqjkl*P!m*TD-H`cTuN{_G`e(Occ-dLa=;vA%@*AOg(a(z}6t_crT&EO-&+m4gF>N0h;BXG0?{Bi7 z`CMs0?IQEIN_yrvkTId}4tcQlLFDsm2){A5T)eb!$m;U*9bpNnS{u9Nur=c6{IY zKC28T*@~?E=+fvG1A<0jF;cm0Q(bSl;8d`tTUme#<>4g zLGy3~(+z4auzTu_$wj7=5_bmr4M3i>XprZ8-8A{ z^S%T(i(@^t7G<(wYTc~P^uFuDm}iOCg0RJbylL{6l)E9&xd*ipG|e`)b?b`n)|`3$ z>k`idS@_lp+*>nk7_W2qvLHrYsnN9VjcdkaYxRqWdf5!mZ8vsD^2e%lG>7`oaP1~( z91eF(@?7&4^jE^(0w>-(Xig#TL8J;KX+2YL&fdmGjCA1!I<+uYch0=ri`kM?G=Uz= zYe(%m$g6gpfYRA}M3Wh=PjV`BA|f`Ajz1QY-KfS$+mLC&=*M@CqU0@-843#@s!tp+ z`hXG_$T+w$%ZRc;oA!hozBo{U_AgR)cc2=ist%Tf1!goyZ`H}XSr9&UY zJ^9hCDY9E_U|L$j^3{t+O$rDP^WqxkQ)&F;Eh@Hsx^<};S#~>%t}R_YRkG7OjOT7s&BTd5F;H{&a{d!BS5Vz@RgwkT{dwhcQ zPGno6OlTdu0KU{d<)>5lyi9d5Rz$1ros^mpW_coXd{r;;5w~?!YUHbE$=hL2`F`si x55d?S>E1-idha0G3zgVNNXgr$|KG8qZJn`L2pQ~%2Sy6WZoiY&ZA<_7e*r@k8!Z3; literal 0 HcmV?d00001 diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_encode_bytes.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_encode_bytes.py index 615d4f050e0..2ca75a22c31 100644 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/test_encode_bytes.py +++ b/packages/http-client-python/generator/test/generic_mock_api_tests/test_encode_bytes.py @@ -95,6 +95,12 @@ def test_header(client: BytesClient): ) +@pytest.fixture +def png_data() -> bytes: + with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in: + return file_in.read() + + def test_request_body(client: BytesClient, png_data: bytes): client.request_body.default( value=png_data, diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py index a37c81ccef3..19d767860f8 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py @@ -54,11 +54,12 @@ def test_sensitive_word(): check_folder = (Path(os.path.dirname(__file__)) / "../generated").resolve() assert [] == check_sensitive_word(check_folder, "azure") # after update spector, it shall also equal to [] - assert sorted( - [ - "authentication-oauth2", - "authentication-noauth-union", - "authentication-union", - "setuppy-authentication-union", - ] - ) == sorted(check_sensitive_word(check_folder, "microsoft")) + expected = [ + "authentication-oauth2", + "authentication-noauth-union", + "authentication-union", + "setuppy-authentication-union", + ] + if (check_folder / "generation-subdir").exists(): + expected.append("generation-subdir") + assert sorted(expected) == sorted(check_sensitive_word(check_folder, "microsoft"))