Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/python-exact-name-test-2026-5-26-6-12-0.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions packages/http-client-python/eng/scripts/ci/run_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions packages/http-client-python/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/http-client-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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__
Original file line number Diff line number Diff line change
@@ -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__
Loading