-
Notifications
You must be signed in to change notification settings - Fork 372
[python] Add test for client-doc spector scenario (Azure typespec-azure #4268) #10888
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
+76
−0
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
952ccaf
Initial plan
Copilot 1d4e7b4
Plan: add python tests for client-doc and response-as-bool spector cases
Copilot 175dd91
Add python tests for client-doc spector case (Azure PR #4268)
Copilot add5d5e
Compare whole docstring instead of substrings in client-doc tests
Copilot 9a6d9ed
Document trailing docstring indentation in client-doc test assertions
Copilot 3e6e6b8
Merge remote-tracking branch 'origin/main' into copilot/add-test-case…
Copilot 983e991
Compare only method/model description in client-doc tests
Copilot af1b1fd
Merge branch 'main' into copilot/add-test-case-for-pull-4268
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: internal | ||
| packages: | ||
| - "@typespec/http-client-python" | ||
| --- | ||
|
|
||
| Add test for the `@clientDoc` decorator spector case (azure/client-generator-core/client-doc). |
36 changes: 36 additions & 0 deletions
36
...thon/tests/mock_api/azure/asynctests/test_azure_client_generator_core_client_doc_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,36 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| import pytest | ||
| import pytest_asyncio | ||
| from specs.azure.clientgenerator.core.clientdoc.aio import ClientDocClient | ||
| from specs.azure.clientgenerator.core.clientdoc import models | ||
|
|
||
|
|
||
| @pytest_asyncio.fixture | ||
| async def client(): | ||
| async with ClientDocClient() as client: | ||
| yield client | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_harvest(client: ClientDocClient): | ||
| body = models.Plant(name="Rose", species="Rosa") | ||
| assert await client.documentation.harvest(body) == body | ||
|
|
||
|
|
||
| def test_model_doc_appended(): | ||
| # @clientDoc in append mode keeps the base @doc and appends the client-specific text. | ||
| # Only the model description is compared, not the parameter docstrings. | ||
| doc = models.Plant.__doc__.split(":ivar")[0].strip() | ||
| assert doc == "A plant in the garden. This model is used to represent a plant in the client SDK." | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_operation_doc_replaced(client: ClientDocClient): | ||
| # @clientDoc in replace mode overrides the base @doc completely. | ||
| # Only the operation description is compared, not the parameter docstrings. | ||
| doc = client.documentation.harvest.__doc__.split(":param")[0].strip() | ||
| assert doc == "Retrieves a plant from the garden by submitting its name." |
33 changes: 33 additions & 0 deletions
33
...es/http-client-python/tests/mock_api/azure/test_azure_client_generator_core_client_doc.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.clientgenerator.core.clientdoc import ClientDocClient | ||
| from specs.azure.clientgenerator.core.clientdoc import models | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(): | ||
| with ClientDocClient() as client: | ||
| yield client | ||
|
|
||
|
|
||
| def test_harvest(client: ClientDocClient): | ||
| body = models.Plant(name="Rose", species="Rosa") | ||
| assert client.documentation.harvest(body) == body | ||
|
|
||
|
|
||
| def test_model_doc_appended(): | ||
| # @clientDoc in append mode keeps the base @doc and appends the client-specific text. | ||
| # Only the model description is compared, not the parameter docstrings. | ||
| doc = models.Plant.__doc__.split(":ivar")[0].strip() | ||
| assert doc == "A plant in the garden. This model is used to represent a plant in the client SDK." | ||
|
|
||
|
|
||
| def test_operation_doc_replaced(client: ClientDocClient): | ||
| # @clientDoc in replace mode overrides the base @doc completely. | ||
| # Only the operation description is compared, not the parameter docstrings. | ||
| doc = client.documentation.harvest.__doc__.split(":param")[0].strip() | ||
| assert doc == "Retrieves a plant from the garden by submitting its name." | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.