-
Notifications
You must be signed in to change notification settings - Fork 352
[python] Fix import for generation-subdir #10303
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
Open
msyyc
wants to merge
10
commits into
main
Choose a base branch
from
fix-import-generation-subdir
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
16f1659
update regenerate.ts
msyyc 939fa34
add basic test case
msyyc 04cf6fc
fix import for generation-subir
msyyc bdb0926
add changelog
msyyc 34539c7
fix ci and remove confusing log
msyyc be4b52c
Merge branch 'main' into fix-import-generation-subdir
msyyc 1c446d7
fix ci
msyyc bf9ecff
Update packages/http-client-python/eng/scripts/ci/regenerate-common.ts
msyyc cb38b8d
Merge branch 'main' into fix-import-generation-subdir
msyyc 601bba8
Update regenerate-common.ts
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
7 changes: 7 additions & 0 deletions
7
.chronus/changes/fix-import-generation-subdir-2026-3-8-12-7-49.md
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: | ||
| - "@typespec/http-client-python" | ||
| --- | ||
|
|
||
| fix import for _validation.py/_types.py when "generation-subdir" is configured |
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
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
37 changes: 37 additions & 0 deletions
37
...thon/tests/mock_api/shared/asynctests/test_generation_subdir2_for_generated_code_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,37 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # 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 generation.subdir2._generated.aio import AddedClient | ||
| from generation.subdir2._generated.models import ModelV1, ModelV2, EnumV1, EnumV2 | ||
|
|
||
|
|
||
| @pytest_asyncio.fixture | ||
| async def client(): | ||
| async with AddedClient(endpoint="http://localhost:3000", version="v2") as client: | ||
| yield client | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_v1(client: AddedClient): | ||
| assert await client.v1( | ||
| ModelV1(prop="foo", enum_prop=EnumV1.ENUM_MEMBER_V2, union_prop=10), | ||
| header_v2="bar", | ||
| ) == ModelV1(prop="foo", enum_prop=EnumV1.ENUM_MEMBER_V2, union_prop=10) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_v2(client: AddedClient): | ||
| assert await client.v2(ModelV2(prop="foo", enum_prop=EnumV2.ENUM_MEMBER, union_prop="bar")) == ModelV2( | ||
| prop="foo", enum_prop=EnumV2.ENUM_MEMBER, union_prop="bar" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_interface_v2(client: AddedClient): | ||
| assert await client.interface_v2.v2_in_interface( | ||
| ModelV2(prop="foo", enum_prop=EnumV2.ENUM_MEMBER, union_prop="bar") | ||
| ) == ModelV2(prop="foo", enum_prop=EnumV2.ENUM_MEMBER, union_prop="bar") |
25 changes: 25 additions & 0 deletions
25
...ython/tests/mock_api/shared/asynctests/test_generation_subdir_for_generated_code_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,25 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # 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 generation.subdir._generated.aio import RecursiveClient | ||
| from generation.subdir._generated.models import Extension | ||
|
|
||
|
|
||
| @pytest_asyncio.fixture | ||
| async def client(): | ||
| async with RecursiveClient() as client: | ||
| yield client | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_custom_method(client: RecursiveClient): | ||
| assert await client.get() == Extension( | ||
| { | ||
| "level": 0, | ||
| "extension": [{"level": 1, "extension": [{"level": 2}]}, {"level": 1}], | ||
| } | ||
| ) |
33 changes: 33 additions & 0 deletions
33
...es/http-client-python/tests/mock_api/shared/test_generation_subdir2_for_generated_code.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 generation.subdir2._generated import AddedClient | ||
| from generation.subdir2._generated.models import ModelV1, ModelV2, EnumV1, EnumV2 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(): | ||
| with AddedClient(endpoint="http://localhost:3000", version="v2") as client: | ||
| yield client | ||
|
|
||
|
|
||
| def test_v1(client: AddedClient): | ||
| assert client.v1( | ||
| ModelV1(prop="foo", enum_prop=EnumV1.ENUM_MEMBER_V2, union_prop=10), | ||
| header_v2="bar", | ||
| ) == ModelV1(prop="foo", enum_prop=EnumV1.ENUM_MEMBER_V2, union_prop=10) | ||
|
|
||
|
|
||
| def test_v2(client: AddedClient): | ||
| assert client.v2(ModelV2(prop="foo", enum_prop=EnumV2.ENUM_MEMBER, union_prop="bar")) == ModelV2( | ||
| prop="foo", enum_prop=EnumV2.ENUM_MEMBER, union_prop="bar" | ||
| ) | ||
|
|
||
|
|
||
| def test_interface_v2(client: AddedClient): | ||
| assert client.interface_v2.v2_in_interface( | ||
| ModelV2(prop="foo", enum_prop=EnumV2.ENUM_MEMBER, union_prop="bar") | ||
| ) == ModelV2(prop="foo", enum_prop=EnumV2.ENUM_MEMBER, union_prop="bar") |
17 changes: 17 additions & 0 deletions
17
...ges/http-client-python/tests/mock_api/shared/test_generation_subdir_for_generated_code.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,17 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| from generation.subdir._generated import RecursiveClient | ||
| from generation.subdir._generated.models import Extension | ||
|
|
||
|
|
||
| def test_custom_method(): | ||
| client = RecursiveClient() | ||
| assert client.get() == Extension( | ||
| { | ||
| "level": 0, | ||
| "extension": [{"level": 1, "extension": [{"level": 2}]}, {"level": 1}], | ||
| } | ||
| ) |
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
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.
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.
Suppressing the mock server’s stdout/stderr makes failures much harder to diagnose (e.g., if the process exits immediately, we only get an exit code without any error output). Consider redirecting output to a log file (and surfacing it on startup failures) rather than sending it to DEVNULL, so CI failures remain actionable while still keeping normal test output clean.
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.
I checked current log and confirm it is clean and could show enough error traceback