@azure-tools/typespec-python 0.30.0 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scripts/eng/lint.js.map +1 -1
- package/dist/scripts/eng/regenerate.js +0 -6
- package/dist/scripts/eng/regenerate.js.map +1 -1
- package/dist/scripts/eng/run-tests.js +16 -7
- package/dist/scripts/eng/run-tests.js.map +1 -1
- package/dist/scripts/eng/utils.js.map +1 -1
- package/dist/scripts/system-requirements.d.ts.map +1 -1
- package/dist/scripts/system-requirements.js.map +1 -1
- package/dist/src/code-model.js.map +1 -1
- package/dist/src/emitter.d.ts.map +1 -1
- package/dist/src/emitter.js +3 -1
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/external-process.d.ts +0 -1
- package/dist/src/external-process.d.ts.map +1 -1
- package/dist/src/http.js.map +1 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +77 -4
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +60 -5
- package/dist/src/utils.js.map +1 -1
- package/generator/pygen/codegen/models/operation.py +13 -2
- package/generator/pygen/codegen/models/parameter.py +5 -1
- package/generator/pygen/codegen/models/primitive_types.py +2 -1
- package/generator/pygen/codegen/models/property.py +5 -1
- package/generator/pygen/codegen/serializers/builder_serializer.py +15 -10
- package/generator/pygen/codegen/serializers/model_serializer.py +14 -4
- package/generator/pygen/codegen/serializers/test_serializer.py +6 -0
- package/generator/pygen/codegen/templates/model_base.py.jinja2 +315 -69
- package/generator/pygen/codegen/templates/model_dpg.py.jinja2 +6 -1
- package/generator/pygen/codegen/templates/serialization.py.jinja2 +271 -162
- package/generator/pygen/codegen/templates/test.py.jinja2 +2 -2
- package/generator/pygen/utils.py +9 -0
- package/package.json +6 -5
- package/scripts/__pycache__/venvtools.cpython-310.pyc +0 -0
- package/scripts/eng/regenerate.ts +0 -6
- package/scripts/eng/run-tests.ts +17 -7
|
@@ -29,9 +29,9 @@ class {{ test.test_class_name }}({{ test.base_test_class_name }}):
|
|
|
29
29
|
{% endif %}
|
|
30
30
|
@recorded_by_proxy{{ async_suffix }}
|
|
31
31
|
{% if code_model.options["azure_arm"] %}
|
|
32
|
-
{{ async }}def test_{{ testcase.
|
|
32
|
+
{{ async }}def test_{{ testcase.name }}(self, resource_group):
|
|
33
33
|
{% else %}
|
|
34
|
-
{{ async }}def test_{{ testcase.
|
|
34
|
+
{{ async }}def test_{{ testcase.name }}(self, {{ prefix_lower }}_endpoint):
|
|
35
35
|
{{ client_var }} = self.{{ test.create_client_name }}(endpoint={{ prefix_lower }}_endpoint)
|
|
36
36
|
{% endif %}
|
|
37
37
|
{{testcase.response }}{{ client_var }}{{ testcase.operation_group_prefix }}.{{ testcase.operation.name }}(
|
package/generator/pygen/utils.py
CHANGED
|
@@ -105,6 +105,7 @@ KNOWN_TYPES: Dict[str, Dict[str, Any]] = {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
JSON_REGEXP = re.compile(r"^(application|text)/(.+\+)?json$")
|
|
108
|
+
XML_REGEXP = re.compile(r"^(application|text)/(.+\+)?xml$")
|
|
108
109
|
|
|
109
110
|
|
|
110
111
|
def build_policies(
|
|
@@ -149,3 +150,11 @@ def build_policies(
|
|
|
149
150
|
|
|
150
151
|
def extract_original_name(name: str) -> str:
|
|
151
152
|
return name[1 : -len("_initial")]
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def json_serializable(content_type: str) -> bool:
|
|
156
|
+
return bool(JSON_REGEXP.match(content_type.split(";")[0].strip().lower()))
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def xml_serializable(content_type: str) -> bool:
|
|
160
|
+
return bool(XML_REGEXP.match(content_type.split(";")[0].strip().lower()))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-python",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.1",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec emitter for Python SDKs",
|
|
6
6
|
"homepage": "https://github.com/Azure/autorest.python",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@azure-tools/typespec-azure-resource-manager": "~0.45.0",
|
|
55
55
|
"@azure-tools/typespec-autorest": "~0.45.0",
|
|
56
|
-
"@azure-tools/cadl-ranch-expect": "~0.15.
|
|
57
|
-
"@azure-tools/cadl-ranch-specs": "~0.
|
|
56
|
+
"@azure-tools/cadl-ranch-expect": "~0.15.3",
|
|
57
|
+
"@azure-tools/cadl-ranch-specs": "~0.37.1",
|
|
58
58
|
"@types/js-yaml": "~4.0.5",
|
|
59
59
|
"@types/node": "^18.16.3",
|
|
60
60
|
"@types/yargs": "17.0.32",
|
|
@@ -62,8 +62,9 @@
|
|
|
62
62
|
"@typespec/eslint-config-typespec": "~0.55.0",
|
|
63
63
|
"@typespec/openapi": "~0.59.0",
|
|
64
64
|
"c8": "~7.13.0",
|
|
65
|
+
"vitest": "^2.0.4",
|
|
65
66
|
"rimraf": "~5.0.0",
|
|
66
|
-
"typescript": "~5.
|
|
67
|
+
"typescript": "~5.5.4",
|
|
67
68
|
"@azure-tools/typespec-azure-core": "~0.45.0",
|
|
68
69
|
"@azure-tools/typespec-client-generator-core": "0.45.4",
|
|
69
70
|
"@typespec/compiler": "~0.59.1",
|
|
@@ -83,6 +84,6 @@
|
|
|
83
84
|
"format": "npx prettier **/*.ts --write && tsx ./scripts/eng/format.ts",
|
|
84
85
|
"install": "tsx ./scripts/run-python3.ts ./scripts/install.py",
|
|
85
86
|
"regenerate": "tsx ./scripts/eng/regenerate.ts",
|
|
86
|
-
"test": "tsx ./scripts/eng/run-tests.ts"
|
|
87
|
+
"test": "npx vitest run ./test && tsx ./scripts/eng/run-tests.ts"
|
|
87
88
|
}
|
|
88
89
|
}
|
|
Binary file
|
|
@@ -50,9 +50,6 @@ const EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, st
|
|
|
50
50
|
"type/model/empty": {
|
|
51
51
|
"package-name": "typetest-model-empty",
|
|
52
52
|
},
|
|
53
|
-
"type/model/flatten": {
|
|
54
|
-
"package-name": "typetest-model-flatten",
|
|
55
|
-
},
|
|
56
53
|
"type/model/inheritance/enum-discriminator": {
|
|
57
54
|
"package-name": "typetest-model-enumdiscriminator",
|
|
58
55
|
},
|
|
@@ -172,9 +169,6 @@ async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promi
|
|
|
172
169
|
const mainTspRelativePath = toPosix(relative(baseDir, mainTspPath));
|
|
173
170
|
if (flags.flavor === "unbranded" && mainTspRelativePath.includes("azure")) return;
|
|
174
171
|
|
|
175
|
-
// after xml support, remove this check
|
|
176
|
-
if (mainTspRelativePath.includes("xml")) return;
|
|
177
|
-
|
|
178
172
|
// after fix test generation for nested operation group, remove this check
|
|
179
173
|
if (mainTspRelativePath.includes("client-operation-group")) return;
|
|
180
174
|
|
package/scripts/eng/run-tests.ts
CHANGED
|
@@ -10,6 +10,7 @@ interface Arguments {
|
|
|
10
10
|
validFolders: string[];
|
|
11
11
|
folder?: string;
|
|
12
12
|
command?: string;
|
|
13
|
+
name?: string;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const validCommands = ["ci", "lint", "mypy", "pyright", "apiview"];
|
|
@@ -32,15 +33,24 @@ const argv = yargs(hideBin(process.argv))
|
|
|
32
33
|
describe: "Specify the command to run",
|
|
33
34
|
choices: validCommands,
|
|
34
35
|
type: "string",
|
|
36
|
+
})
|
|
37
|
+
.option("name", {
|
|
38
|
+
alias: "n",
|
|
39
|
+
describe: "Specify the name of the test",
|
|
40
|
+
type: "string",
|
|
35
41
|
}).argv as Arguments;
|
|
36
42
|
|
|
37
43
|
const foldersToProcess = argv.folder ? [argv.folder] : argv.validFolders;
|
|
38
44
|
|
|
39
45
|
const commandToRun = argv.command || "all";
|
|
40
46
|
|
|
41
|
-
function getCommand(command: string, folder: string) {
|
|
47
|
+
function getCommand(command: string, folder: string, name?: string): string {
|
|
42
48
|
if (!validCommands.includes(command)) throw new Error(`Unknown command '${command}'.`);
|
|
43
|
-
|
|
49
|
+
const retval = `FOLDER=${folder} tox -c ./test/${folder}/tox.ini -e ${command}`;
|
|
50
|
+
if (name) {
|
|
51
|
+
return `${retval} -- -f ${name}`;
|
|
52
|
+
}
|
|
53
|
+
return retval;
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
function sectionExistsInToxIni(command: string, folder: string): boolean {
|
|
@@ -50,12 +60,12 @@ function sectionExistsInToxIni(command: string, folder: string): boolean {
|
|
|
50
60
|
return toxIniContent.includes(sectionHeader);
|
|
51
61
|
}
|
|
52
62
|
|
|
53
|
-
function myExecSync(command: string, folder: string): void {
|
|
63
|
+
function myExecSync(command: string, folder: string, name?: string): void {
|
|
54
64
|
if (!sectionExistsInToxIni(command, folder)) {
|
|
55
65
|
console.log(`No section for ${command} in tox.ini for folder ${folder}. Skipping...`);
|
|
56
66
|
return;
|
|
57
67
|
}
|
|
58
|
-
execSync(getCommand(command, folder), { stdio: "inherit" });
|
|
68
|
+
execSync(getCommand(command, folder, name), { stdio: "inherit" });
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
foldersToProcess.forEach((folder) => {
|
|
@@ -63,11 +73,11 @@ foldersToProcess.forEach((folder) => {
|
|
|
63
73
|
if (commandToRun === "all") {
|
|
64
74
|
for (const key of validCommands) {
|
|
65
75
|
console.log(`Running ${key} for folder ${folder}...`);
|
|
66
|
-
myExecSync(key, folder);
|
|
76
|
+
myExecSync(key, folder, argv.name);
|
|
67
77
|
}
|
|
68
|
-
} else if (getCommand(commandToRun, folder)) {
|
|
78
|
+
} else if (getCommand(commandToRun, folder, argv.name)) {
|
|
69
79
|
console.log(`Running ${commandToRun} for folder ${folder}...`);
|
|
70
|
-
myExecSync(commandToRun, folder);
|
|
80
|
+
myExecSync(commandToRun, folder, argv.name);
|
|
71
81
|
} else {
|
|
72
82
|
console.error(`Error: Unknown command '${commandToRun}'.`);
|
|
73
83
|
process.exit(1);
|