Skip to content

Commit 57395b5

Browse files
authored
[python] add test case (#3330)
* Update dependencies * Add changelog * Update dependencies (2026-02-04 05:13:27) * Regenerate for typespec-python (2026-02-04 05:18:51) * Update dependencies * Add changelog * Update dependencies (2026-02-04 08:23:31) * Regenerate for typespec-python (2026-02-04 08:28:50) * Sync test changes from microsoft/typespec#9571 * Sync test changes from microsoft/typespec#9571 * Fix duplicate test functions * Update dependencies * Update dependencies (2026-02-04 09:38:50) * fix: resolve merge conflicts in package.json files * Update dependencies * Update dependencies (2026-02-05 13:39:57) --------- Co-authored-by: AutoPrFromHttpClientPython <AutoPrFromHttpClientPython>
1 parent f3e9398 commit 57395b5

67 files changed

Lines changed: 2640 additions & 33 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@autorest/python"
5+
- "@azure-tools/typespec-python"
6+
---
7+
8+
Add test case
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@autorest/python"
5+
- "@azure-tools/typespec-python"
6+
---
7+
8+
Fix import for xml paging

packages/autorest.python/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
3131
"dependencies": {
32-
"@typespec/http-client-python": "~0.27.0",
32+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTg0MjUxOC9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.0.tgz",
3333
"@autorest/system-requirements": "~1.0.2",
3434
"fs-extra": "~11.2.0",
3535
"tsx": "~4.19.1"
@@ -47,4 +47,4 @@
4747
"requirements.txt",
4848
"generator/"
4949
]
50-
}
50+
}

packages/typespec-python/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"js-yaml": "~4.1.0",
6868
"semver": "~7.6.2",
6969
"tsx": "~4.19.1",
70-
"@typespec/http-client-python": "~0.27.0",
70+
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTg0MjUxOC9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.0.tgz",
7171
"fs-extra": "~11.2.0"
7272
},
7373
"devDependencies": {
@@ -86,8 +86,8 @@
8686
"@azure-tools/typespec-azure-rulesets": "~0.64.0",
8787
"@azure-tools/typespec-autorest": "~0.64.1",
8888
"@azure-tools/typespec-client-generator-core": "~0.64.6",
89-
"@azure-tools/azure-http-specs": "0.1.0-alpha.36",
90-
"@typespec/http-specs": "0.1.0-alpha.32-dev.1",
89+
"@azure-tools/azure-http-specs": "0.1.0-alpha.37-dev.1",
90+
"@typespec/http-specs": "0.1.0-alpha.32-dev.5",
9191
"@typespec/spector": "0.1.0-alpha.22",
9292
"@typespec/spec-api": "0.1.0-alpha.12",
9393
"@types/js-yaml": "~4.0.5",
@@ -103,4 +103,4 @@
103103
"chalk": "5.3.0",
104104
"@types/fs-extra": "11.0.4"
105105
}
106-
}
106+
}

packages/typespec-python/test/azure/generated/azure-resource-manager-operation-templates/apiview-properties.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"azure.resourcemanager.operationtemplates.aio.operations.LroOperations.begin_export": "Azure.ResourceManager.OperationTemplates.Lro.export",
4040
"azure.resourcemanager.operationtemplates.operations.LroOperations.begin_delete": "Azure.ResourceManager.OperationTemplates.Lro.delete",
4141
"azure.resourcemanager.operationtemplates.aio.operations.LroOperations.begin_delete": "Azure.ResourceManager.OperationTemplates.Lro.delete",
42+
"azure.resourcemanager.operationtemplates.operations.LroOperations.begin_export_array": "Azure.ResourceManager.OperationTemplates.Lro.exportArray",
43+
"azure.resourcemanager.operationtemplates.aio.operations.LroOperations.begin_export_array": "Azure.ResourceManager.OperationTemplates.Lro.exportArray",
4244
"azure.resourcemanager.operationtemplates.operations.LroPagingOperations.begin_post_paging_lro": "Azure.ResourceManager.OperationTemplates.LroPaging.postPagingLro",
4345
"azure.resourcemanager.operationtemplates.aio.operations.LroPagingOperations.begin_post_paging_lro": "Azure.ResourceManager.OperationTemplates.LroPaging.postPagingLro",
4446
"azure.resourcemanager.operationtemplates.operations.OptionalBodyOperations.get": "Azure.ResourceManager.OperationTemplates.OptionalBody.get",

packages/typespec-python/test/azure/generated/azure-resource-manager-operation-templates/azure/resourcemanager/operationtemplates/aio/operations/_operations.py

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
build_check_name_availability_check_local_request,
4242
build_lro_create_or_replace_request,
4343
build_lro_delete_request,
44+
build_lro_export_array_request,
4445
build_lro_export_request,
4546
build_lro_paging_post_paging_lro_request,
4647
build_operations_list_request,
@@ -1064,6 +1065,194 @@ def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-
10641065
)
10651066
return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore
10661067

1068+
async def _export_array_initial(
1069+
self, body: Union[_models.ExportRequest, JSON, IO[bytes]], **kwargs: Any
1070+
) -> AsyncIterator[bytes]:
1071+
error_map: MutableMapping = {
1072+
401: ClientAuthenticationError,
1073+
404: ResourceNotFoundError,
1074+
409: ResourceExistsError,
1075+
304: ResourceNotModifiedError,
1076+
}
1077+
error_map.update(kwargs.pop("error_map", {}) or {})
1078+
1079+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
1080+
_params = kwargs.pop("params", {}) or {}
1081+
1082+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
1083+
cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None)
1084+
1085+
content_type = content_type or "application/json"
1086+
_content = None
1087+
if isinstance(body, (IOBase, bytes)):
1088+
_content = body
1089+
else:
1090+
_content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore
1091+
1092+
_request = build_lro_export_array_request(
1093+
subscription_id=self._config.subscription_id,
1094+
content_type=content_type,
1095+
api_version=self._config.api_version,
1096+
content=_content,
1097+
headers=_headers,
1098+
params=_params,
1099+
)
1100+
path_format_arguments = {
1101+
"endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True),
1102+
}
1103+
_request.url = self._client.format_url(_request.url, **path_format_arguments)
1104+
1105+
_stream = True
1106+
pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
1107+
_request, stream=_stream, **kwargs
1108+
)
1109+
1110+
response = pipeline_response.http_response
1111+
1112+
if response.status_code not in [200, 202]:
1113+
try:
1114+
await response.read() # Load the body in memory and close the socket
1115+
except (StreamConsumedError, StreamClosedError):
1116+
pass
1117+
map_error(status_code=response.status_code, response=response, error_map=error_map)
1118+
error = _failsafe_deserialize(
1119+
_models.ErrorResponse,
1120+
response,
1121+
)
1122+
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
1123+
1124+
response_headers = {}
1125+
if response.status_code == 202:
1126+
response_headers["Azure-AsyncOperation"] = self._deserialize(
1127+
"str", response.headers.get("Azure-AsyncOperation")
1128+
)
1129+
response_headers["Location"] = self._deserialize("str", response.headers.get("Location"))
1130+
response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After"))
1131+
1132+
deserialized = response.iter_bytes()
1133+
1134+
if cls:
1135+
return cls(pipeline_response, deserialized, response_headers) # type: ignore
1136+
1137+
return deserialized # type: ignore
1138+
1139+
@overload
1140+
async def begin_export_array(
1141+
self, body: _models.ExportRequest, *, content_type: str = "application/json", **kwargs: Any
1142+
) -> AsyncLROPoller[List[_models.ExportResult]]:
1143+
"""export_array.
1144+
1145+
:param body: The request body. Required.
1146+
:type body: ~azure.resourcemanager.operationtemplates.models.ExportRequest
1147+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1148+
Default value is "application/json".
1149+
:paramtype content_type: str
1150+
:return: An instance of AsyncLROPoller that returns list of ExportResult
1151+
:rtype:
1152+
~azure.core.polling.AsyncLROPoller[list[~azure.resourcemanager.operationtemplates.models.ExportResult]]
1153+
:raises ~azure.core.exceptions.HttpResponseError:
1154+
"""
1155+
1156+
@overload
1157+
async def begin_export_array(
1158+
self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
1159+
) -> AsyncLROPoller[List[_models.ExportResult]]:
1160+
"""export_array.
1161+
1162+
:param body: The request body. Required.
1163+
:type body: JSON
1164+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
1165+
Default value is "application/json".
1166+
:paramtype content_type: str
1167+
:return: An instance of AsyncLROPoller that returns list of ExportResult
1168+
:rtype:
1169+
~azure.core.polling.AsyncLROPoller[list[~azure.resourcemanager.operationtemplates.models.ExportResult]]
1170+
:raises ~azure.core.exceptions.HttpResponseError:
1171+
"""
1172+
1173+
@overload
1174+
async def begin_export_array(
1175+
self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
1176+
) -> AsyncLROPoller[List[_models.ExportResult]]:
1177+
"""export_array.
1178+
1179+
:param body: The request body. Required.
1180+
:type body: IO[bytes]
1181+
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
1182+
Default value is "application/json".
1183+
:paramtype content_type: str
1184+
:return: An instance of AsyncLROPoller that returns list of ExportResult
1185+
:rtype:
1186+
~azure.core.polling.AsyncLROPoller[list[~azure.resourcemanager.operationtemplates.models.ExportResult]]
1187+
:raises ~azure.core.exceptions.HttpResponseError:
1188+
"""
1189+
1190+
@distributed_trace_async
1191+
async def begin_export_array(
1192+
self, body: Union[_models.ExportRequest, JSON, IO[bytes]], **kwargs: Any
1193+
) -> AsyncLROPoller[List[_models.ExportResult]]:
1194+
"""export_array.
1195+
1196+
:param body: The request body. Is one of the following types: ExportRequest, JSON, IO[bytes]
1197+
Required.
1198+
:type body: ~azure.resourcemanager.operationtemplates.models.ExportRequest or JSON or IO[bytes]
1199+
:return: An instance of AsyncLROPoller that returns list of ExportResult
1200+
:rtype:
1201+
~azure.core.polling.AsyncLROPoller[list[~azure.resourcemanager.operationtemplates.models.ExportResult]]
1202+
:raises ~azure.core.exceptions.HttpResponseError:
1203+
"""
1204+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
1205+
_params = kwargs.pop("params", {}) or {}
1206+
1207+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
1208+
cls: ClsType[List[_models.ExportResult]] = kwargs.pop("cls", None)
1209+
polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True)
1210+
lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
1211+
cont_token: Optional[str] = kwargs.pop("continuation_token", None)
1212+
if cont_token is None:
1213+
raw_result = await self._export_array_initial(
1214+
body=body, content_type=content_type, cls=lambda x, y, z: x, headers=_headers, params=_params, **kwargs
1215+
)
1216+
await raw_result.http_response.read() # type: ignore
1217+
kwargs.pop("error_map", None)
1218+
1219+
def get_long_running_output(pipeline_response):
1220+
response_headers = {}
1221+
response = pipeline_response.http_response
1222+
response_headers["Azure-AsyncOperation"] = self._deserialize(
1223+
"str", response.headers.get("Azure-AsyncOperation")
1224+
)
1225+
response_headers["Location"] = self._deserialize("str", response.headers.get("Location"))
1226+
response_headers["Retry-After"] = self._deserialize("int", response.headers.get("Retry-After"))
1227+
1228+
deserialized = _deserialize(List[_models.ExportResult], response.json())
1229+
if cls:
1230+
return cls(pipeline_response, deserialized, response_headers) # type: ignore
1231+
return deserialized
1232+
1233+
path_format_arguments = {
1234+
"endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True),
1235+
}
1236+
1237+
if polling is True:
1238+
polling_method: AsyncPollingMethod = cast(
1239+
AsyncPollingMethod, AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs)
1240+
)
1241+
elif polling is False:
1242+
polling_method = cast(AsyncPollingMethod, AsyncNoPolling())
1243+
else:
1244+
polling_method = polling
1245+
if cont_token:
1246+
return AsyncLROPoller[List[_models.ExportResult]].from_continuation_token(
1247+
polling_method=polling_method,
1248+
continuation_token=cont_token,
1249+
client=self._client,
1250+
deserialization_callback=get_long_running_output,
1251+
)
1252+
return AsyncLROPoller[List[_models.ExportResult]](
1253+
self._client, raw_result, get_long_running_output, polling_method # type: ignore
1254+
)
1255+
10671256

10681257
class LroPagingOperations:
10691258
"""

0 commit comments

Comments
 (0)