diff --git a/.chronus/changes/python-exact-name-test-2026-5-26-6-12-0.md b/.chronus/changes/python-exact-name-test-2026-5-26-6-12-0.md new file mode 100644 index 00000000000..7067f2774e4 --- /dev/null +++ b/.chronus/changes/python-exact-name-test-2026-5-26-6-12-0.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Add mock_api tests for the `exact()` function used with `@clientName` to preserve exact naming. diff --git a/packages/http-client-python/eng/scripts/ci/run_pylint.py b/packages/http-client-python/eng/scripts/ci/run_pylint.py index c184c56a3de..d473b1e94e4 100644 --- a/packages/http-client-python/eng/scripts/ci/run_pylint.py +++ b/packages/http-client-python/eng/scripts/ci/run_pylint.py @@ -47,6 +47,15 @@ def _single_dir_pylint(mod): ] if is_azure: pylint_args.append("--load-plugins=pylint_guidelines_checker") + # Per-package suppressions for generated code where pylint's ignore-paths + # is not honored (pylint 4.x + recursive + plugin). Keep the scope as + # narrow as possible: only this package, only the offending check. + per_package_disables = { + "azure-client-generator-core-exact-name": ["client-incorrect-naming-convention"], + } + extra_disables = per_package_disables.get(mod.name) + if extra_disables: + pylint_args.append("--disable={}".format(",".join(extra_disables))) pylint_args.append(str(inner_class.absolute())) try: check_call(pylint_args) diff --git a/packages/http-client-python/package-lock.json b/packages/http-client-python/package-lock.json index 52118e4ce86..cc9078bf7e4 100644 --- a/packages/http-client-python/package-lock.json +++ b/packages/http-client-python/package-lock.json @@ -17,12 +17,12 @@ "tsx": "^4.21.0" }, "devDependencies": { - "@azure-tools/azure-http-specs": "0.1.0-alpha.40", + "@azure-tools/azure-http-specs": "0.1.0-alpha.41-dev.1", "@azure-tools/typespec-autorest": "~0.68.0", "@azure-tools/typespec-azure-core": "~0.68.0", "@azure-tools/typespec-azure-resource-manager": "~0.68.0", "@azure-tools/typespec-azure-rulesets": "~0.68.0", - "@azure-tools/typespec-client-generator-core": "~0.68.0", + "@azure-tools/typespec-client-generator-core": "~0.68.2", "@types/js-yaml": "~4.0.5", "@types/node": "~25.0.2", "@types/semver": "7.5.8", @@ -66,25 +66,25 @@ } }, "node_modules/@azure-tools/azure-http-specs": { - "version": "0.1.0-alpha.40", - "resolved": "https://registry.npmjs.org/@azure-tools/azure-http-specs/-/azure-http-specs-0.1.0-alpha.40.tgz", - "integrity": "sha512-1WhoWwV+SgpzLUHJdRPo+Ph5mQNe0FtDYHb0dVBhIzRMjWzBvYhdj1iK0yAkwYnm04WxLO5izz5sO6/Lq5KhnQ==", + "version": "0.1.0-alpha.41-dev.1", + "resolved": "https://registry.npmjs.org/@azure-tools/azure-http-specs/-/azure-http-specs-0.1.0-alpha.41-dev.1.tgz", + "integrity": "sha512-GaFmm7KP19YtxgdE2eyA37XusQCqoxo7UA6Lj9iLnXE77XPeDppE1pKstWFAbMcv/Jrc/EGqkl+TOGApej/JoA==", "dev": true, "license": "MIT", "dependencies": { - "@typespec/spec-api": "^0.1.0-alpha.14", - "@typespec/spector": "^0.1.0-alpha.25" + "@typespec/spec-api": "^0.1.0-alpha.14 || >=0.1.0-alpha.15-dev <0.1.0-alpha.15", + "@typespec/spector": "^0.1.0-alpha.25 || >=0.1.0-alpha.26-dev <0.1.0-alpha.26" }, "engines": { "node": ">=22.0.0" }, "peerDependencies": { - "@azure-tools/typespec-azure-core": "^0.68.0", + "@azure-tools/typespec-azure-core": "^0.68.0 || >=0.69.0-dev <0.69.0", "@typespec/compiler": "^1.12.0", "@typespec/http": "^1.12.0", - "@typespec/rest": "^0.82.0", - "@typespec/versioning": "^0.82.0", - "@typespec/xml": "^0.82.0" + "@typespec/rest": "^0.82.0 || >=0.83.0-dev <0.83.0", + "@typespec/versioning": "^0.82.0 || >=0.83.0-dev <0.83.0", + "@typespec/xml": "^0.82.0 || >=0.83.0-dev <0.83.0" } }, "node_modules/@azure-tools/typespec-autorest": { @@ -167,9 +167,9 @@ } }, "node_modules/@azure-tools/typespec-client-generator-core": { - "version": "0.68.0", - "resolved": "https://registry.npmjs.org/@azure-tools/typespec-client-generator-core/-/typespec-client-generator-core-0.68.0.tgz", - "integrity": "sha512-QDEAaT/9STiteTPH4qEKuwlIaLvWyAPf/+0XWyqj3vge6Zi7YdWBwB4PqaCMFptHRGAeWC2a14PDGY6kKyc2MQ==", + "version": "0.68.2", + "resolved": "https://registry.npmjs.org/@azure-tools/typespec-client-generator-core/-/typespec-client-generator-core-0.68.2.tgz", + "integrity": "sha512-i6McruyTzeP+CQ1klyEbFfz0gn/ERxkQf8qcrWASPz/ARMneUtZ1hCAmHcv22QuurA3eohn3QZI5r58BgwW87Q==", "dev": true, "license": "MIT", "dependencies": { diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index 3f8ab4a8d76..ef31a825df2 100644 --- a/packages/http-client-python/package.json +++ b/packages/http-client-python/package.json @@ -102,8 +102,8 @@ "@azure-tools/typespec-azure-core": "~0.68.0", "@azure-tools/typespec-azure-resource-manager": "~0.68.0", "@azure-tools/typespec-azure-rulesets": "~0.68.0", - "@azure-tools/typespec-client-generator-core": "~0.68.0", - "@azure-tools/azure-http-specs": "0.1.0-alpha.40", + "@azure-tools/typespec-client-generator-core": "~0.68.2", + "@azure-tools/azure-http-specs": "0.1.0-alpha.41-dev.1", "@typespec/compiler": "^1.12.0", "@typespec/http": "^1.12.0", "@typespec/openapi": "^1.12.0", diff --git a/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_client_generator_core_exact_name_async.py b/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_client_generator_core_exact_name_async.py new file mode 100644 index 00000000000..af984634d49 --- /dev/null +++ b/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_client_generator_core_exact_name_async.py @@ -0,0 +1,43 @@ +# ------------------------------------------------------------------------- +# 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.exactname.aio import ExactNameClient +from specs.azure.clientgenerator.core.exactname.model.models import My_model +from specs.azure.clientgenerator.core.exactname.property.models import ScopedModel + + +@pytest_asyncio.fixture +async def client(): + async with ExactNameClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_model(client: ExactNameClient): + body = My_model(name="test") + response = await client.model.send(body=body) + assert response.name == "test" + + +@pytest.mark.asyncio +async def test_property(client: ExactNameClient): + body = ScopedModel({"name": "test"}) + response = await client.property.send(body=body) + assert response._my_name == "test" + + +def test_model_class_name_preserved(): + # exact("my_model") should preserve the name as-is without casing transformation, + # so the generated class is `My_model` (only the first letter capitalized for class naming), + # not `MyModel`. + assert My_model.__name__ == "My_model" + + +def test_property_name_preserved(): + # exact("_my_name") scoped to python should preserve the property name exactly, + # including the leading underscore, instead of being stripped or having its case changed. + assert "_my_name" in ScopedModel.__annotations__ diff --git a/packages/http-client-python/tests/mock_api/azure/test_azure_client_generator_core_exact_name.py b/packages/http-client-python/tests/mock_api/azure/test_azure_client_generator_core_exact_name.py new file mode 100644 index 00000000000..90ae1d6ab9e --- /dev/null +++ b/packages/http-client-python/tests/mock_api/azure/test_azure_client_generator_core_exact_name.py @@ -0,0 +1,40 @@ +# ------------------------------------------------------------------------- +# 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.exactname import ExactNameClient +from specs.azure.clientgenerator.core.exactname.model.models import My_model +from specs.azure.clientgenerator.core.exactname.property.models import ScopedModel + + +@pytest.fixture +def client(): + with ExactNameClient() as client: + yield client + + +def test_model(client: ExactNameClient): + body = My_model(name="test") + response = client.model.send(body=body) + assert response.name == "test" + + +def test_property(client: ExactNameClient): + body = ScopedModel({"name": "test"}) + response = client.property.send(body=body) + assert response._my_name == "test" + + +def test_model_class_name_preserved(): + # exact("my_model") should preserve the name as-is without casing transformation, + # so the generated class is `My_model` (only the first letter capitalized for class naming), + # not `MyModel`. + assert My_model.__name__ == "My_model" + + +def test_property_name_preserved(): + # exact("_my_name") scoped to python should preserve the property name exactly, + # including the leading underscore, instead of being stripped or having its case changed. + assert "_my_name" in ScopedModel.__annotations__