-
Notifications
You must be signed in to change notification settings - Fork 61
Fix to get right response and exception #2756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5dd948e
add testcase for AzureCoreEmbeddingVector
ChenxiJiang333 5ef4e0e
fix format
ChenxiJiang333 e581f87
fix format
ChenxiJiang333 4211f31
fix
msyyc ffe33c5
Merge branch 'add-testcase-for-AzureCoreEmbeddingVector' of https://g…
msyyc 998531f
update
msyyc 580fac3
fix
msyyc bbad05f
changelog
msyyc e9db18f
Delete .chronus/changes/add-testcase-for-AzureCoreEmbeddingVector-202…
msyyc c7da4ad
Update add-test-2024-7-8-18-12-59.md
msyyc 28c2f65
revert
msyyc 33b2931
Merge branch 'add-test' of https://github.com/Azure/autorest.python i…
msyyc 2b12204
review
msyyc ac9a399
black
msyyc 969a61f
Merge branch 'main' into add-test
msyyc f637a40
Merge branch 'main' into add-test
msyyc e2bca93
Merge branch 'main' into add-test
msyyc 9fa5319
Merge branch 'main' into add-test
msyyc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: fix | ||
| packages: | ||
| - "@azure-tools/typespec-python" | ||
| --- | ||
|
|
||
| Fix to get right response and exception |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ import { | |
| getDescriptionAndSummary, | ||
| getImplementation, | ||
| isAbstract, | ||
| isAzureCoreModel, | ||
| isAzureCoreErrorResponse, | ||
| } from "./utils.js"; | ||
| import { KnownTypes, getType } from "./types.js"; | ||
| import { PythonSdkContext } from "./lib.js"; | ||
|
|
@@ -68,7 +68,7 @@ function emitInitialLroHttpMethod( | |
| operationGroupName: string, | ||
| ): Record<string, any> { | ||
| return { | ||
| ...emitHttpOperation(context, rootClient, operationGroupName, method.operation), | ||
| ...emitHttpOperation(context, rootClient, operationGroupName, method.operation, method), | ||
| name: `_${camelToSnakeCase(method.name)}_initial`, | ||
| isLroInitialOperation: true, | ||
| wantTracing: false, | ||
|
|
@@ -102,8 +102,8 @@ function addPagingInformation( | |
| operationGroupName: string, | ||
| ) { | ||
| for (const response of method.operation.responses.values()) { | ||
| if (response.type && !isAzureCoreModel(response.type)) { | ||
| getType(context, response.type)["pageResultModel"] = true; | ||
| if (response.type) { | ||
| getType(context, response.type)["usage"] = UsageFlags.None; | ||
| } | ||
| } | ||
| const itemType = getType(context, method.response.type!); | ||
|
|
@@ -168,7 +168,7 @@ function emitHttpOperation( | |
| responses.push(emitHttpResponse(context, statusCodes, response, method)!); | ||
| } | ||
| for (const [statusCodes, exception] of operation.exceptions) { | ||
| exceptions.push(emitHttpResponse(context, statusCodes, exception)!); | ||
| exceptions.push(emitHttpResponse(context, statusCodes, exception, undefined, true)!); | ||
| } | ||
| const result = { | ||
| url: operation.path, | ||
|
|
@@ -326,13 +326,20 @@ function emitHttpResponse( | |
| statusCodes: HttpStatusCodeRange | number | "*", | ||
| response: SdkHttpResponse, | ||
| method?: SdkServiceMethod<SdkHttpOperation>, | ||
| isException = false, | ||
| ): Record<string, any> | undefined { | ||
| if (!response) return undefined; | ||
| let type = undefined; | ||
| if (response.type && !isAzureCoreModel(response.type)) { | ||
| if (isException) { | ||
| if (response.type && !isAzureCoreErrorResponse(response.type)) { | ||
| type = getType(context, response.type); | ||
| } | ||
| } else if (method && !method.kind.includes("basic")) { | ||
| if (method.response.type) { | ||
| type = getType(context, method.response.type); | ||
| } | ||
| } else if (response.type) { | ||
|
Comment on lines
+333
to
+341
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| type = getType(context, response.type); | ||
| } else if (method && method.response.type && !isAzureCoreModel(method.response.type)) { | ||
| type = getType(context, method.response.type); | ||
| } | ||
| return { | ||
| headers: response.headers.map((x) => emitHttpResponseHeader(context, x)), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/typespec-python/test/azure/mock_api_tests/asynctests/test_azure_core_model_async.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| import pytest | ||
| from specs.azure.core.model.aio import ModelClient | ||
| from specs.azure.core.model.models import AzureEmbeddingModel | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def client(): | ||
| async with ModelClient() as client: | ||
| yield client | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_azure_core_embedding_vector_post(client: ModelClient): | ||
| embedding_model = AzureEmbeddingModel(embedding=[0, 1, 2, 3, 4]) | ||
| result = await client.azure_core_embedding_vector.post( | ||
| body=embedding_model, | ||
| ) | ||
| assert result == AzureEmbeddingModel(embedding=[5, 6, 7, 8, 9]) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_azure_core_embedding_vector_put(client: ModelClient): | ||
| await client.azure_core_embedding_vector.put(body=[0, 1, 2, 3, 4]) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_azure_core_embedding_vector_get(client: ModelClient): | ||
| assert [0, 1, 2, 3, 4] == (await client.azure_core_embedding_vector.get()) |
30 changes: 30 additions & 0 deletions
30
packages/typespec-python/test/azure/mock_api_tests/test_azure_core_model.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| import pytest | ||
| from specs.azure.core.model import ModelClient | ||
| from specs.azure.core.model.models import AzureEmbeddingModel | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(): | ||
| with ModelClient() as client: | ||
| yield client | ||
|
|
||
|
|
||
| def test_azure_core_embedding_vector_post(client: ModelClient): | ||
| embedding_model = AzureEmbeddingModel(embedding=[0, 1, 2, 3, 4]) | ||
| result = client.azure_core_embedding_vector.post( | ||
| body=embedding_model, | ||
| ) | ||
| assert result == AzureEmbeddingModel(embedding=[5, 6, 7, 8, 9]) | ||
|
|
||
|
|
||
| def test_azure_core_embedding_vector_put(client: ModelClient): | ||
| client.azure_core_embedding_vector.put(body=[0, 1, 2, 3, 4]) | ||
|
|
||
|
|
||
| def test_azure_core_embedding_vector_get(client: ModelClient): | ||
| assert [0, 1, 2, 3, 4] == client.azure_core_embedding_vector.get() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python SDK always set response type of initial operation as Binary type so just keep it same as
begin_xxxAPI.