diff --git a/.chronus/changes/add-lossy-duration-tests-2026-6-23-9-24-23.md b/.chronus/changes/add-lossy-duration-tests-2026-6-23-9-24-23.md new file mode 100644 index 00000000000..c7682bfa634 --- /dev/null +++ b/.chronus/changes/add-lossy-duration-tests-2026-6-23-9-24-23.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Add mock API test cases for encode/duration lossy scenarios (int32-seconds and int32-milliseconds) verifying that durations with fractional precision are serialized as integers diff --git a/packages/http-client-python/package-lock.json b/packages/http-client-python/package-lock.json index b8456ec4df4..01d5631147f 100644 --- a/packages/http-client-python/package-lock.json +++ b/packages/http-client-python/package-lock.json @@ -29,7 +29,7 @@ "@typespec/compiler": "^1.13.0", "@typespec/events": "~0.83.0", "@typespec/http": "^1.13.0", - "@typespec/http-specs": "0.1.0-alpha.39-dev.1", + "@typespec/http-specs": "0.1.0-alpha.39-dev.2", "@typespec/openapi": "^1.13.0", "@typespec/rest": "~0.83.0", "@typespec/spec-api": "0.1.0-alpha.14", @@ -2529,9 +2529,9 @@ } }, "node_modules/@typespec/http-specs": { - "version": "0.1.0-alpha.39-dev.1", - "resolved": "https://registry.npmjs.org/@typespec/http-specs/-/http-specs-0.1.0-alpha.39-dev.1.tgz", - "integrity": "sha512-m/e9UYChxZfOcdzD2rEywQYkTqPJDTA8p3gpzrHj5WenfXWU0XA0aKxTIOcm+mj0wvxTfdpP0wFVtcT/dinxbA==", + "version": "0.1.0-alpha.39-dev.2", + "resolved": "https://registry.npmjs.org/@typespec/http-specs/-/http-specs-0.1.0-alpha.39-dev.2.tgz", + "integrity": "sha512-NsxuimkS12gB6RF3j2yGf48bV/LzG0JQbtrZbiGy00RxOAZV59L7gYp852ij6fYN37Uv8P31KHcGM6wIAduAyg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index 2ff9151aefc..65f08273ff0 100644 --- a/packages/http-client-python/package.json +++ b/packages/http-client-python/package.json @@ -119,7 +119,7 @@ "@typespec/sse": "~0.83.0", "@typespec/streams": "~0.83.0", "@typespec/xml": "~0.83.0", - "@typespec/http-specs": "0.1.0-alpha.39-dev.1", + "@typespec/http-specs": "0.1.0-alpha.39-dev.2", "@types/js-yaml": "~4.0.5", "@types/node": "~25.0.2", "@types/semver": "7.5.8", diff --git a/packages/http-client-python/tests/mock_api/azure/asynctests/test_encode_duration_async.py b/packages/http-client-python/tests/mock_api/azure/asynctests/test_encode_duration_async.py index 6e2dd00b4b0..0e17bd7abc7 100644 --- a/packages/http-client-python/tests/mock_api/azure/asynctests/test_encode_duration_async.py +++ b/packages/http-client-python/tests/mock_api/azure/asynctests/test_encode_duration_async.py @@ -110,6 +110,12 @@ async def test_property(client: DurationClient): assert result.value == datetime.timedelta(milliseconds=210000) +@pytest.mark.asyncio +async def test_lossy(client: DurationClient): + await client.lossy.int_seconds(input=datetime.timedelta(seconds=36.25)) + await client.lossy.int_milliseconds(input=datetime.timedelta(milliseconds=36250.25)) + + @pytest.mark.asyncio async def test_header(client: DurationClient): await client.header.default(duration=datetime.timedelta(days=40)) diff --git a/packages/http-client-python/tests/mock_api/azure/test_encode_duration.py b/packages/http-client-python/tests/mock_api/azure/test_encode_duration.py index 78d5ae4f066..e7ef13f5085 100644 --- a/packages/http-client-python/tests/mock_api/azure/test_encode_duration.py +++ b/packages/http-client-python/tests/mock_api/azure/test_encode_duration.py @@ -105,6 +105,11 @@ def test_property(client: DurationClient): assert result.value == datetime.timedelta(milliseconds=210000) +def test_lossy(client: DurationClient): + client.lossy.int_seconds(input=datetime.timedelta(seconds=36.25)) + client.lossy.int_milliseconds(input=datetime.timedelta(milliseconds=36250.25)) + + def test_header(client: DurationClient): client.header.default(duration=datetime.timedelta(days=40)) client.header.iso8601(duration=datetime.timedelta(days=40)) diff --git a/packages/http-client-python/tests/mock_api/unbranded/asynctests/test_encode_duration_async.py b/packages/http-client-python/tests/mock_api/unbranded/asynctests/test_encode_duration_async.py index bb99138d88d..0171b5ffaec 100644 --- a/packages/http-client-python/tests/mock_api/unbranded/asynctests/test_encode_duration_async.py +++ b/packages/http-client-python/tests/mock_api/unbranded/asynctests/test_encode_duration_async.py @@ -110,6 +110,12 @@ async def test_property(client: DurationClient): assert result.value == datetime.timedelta(milliseconds=210000) +@pytest.mark.asyncio +async def test_lossy(client: DurationClient): + await client.lossy.int_seconds(input=datetime.timedelta(seconds=36.25)) + await client.lossy.int_milliseconds(input=datetime.timedelta(milliseconds=36250.25)) + + @pytest.mark.asyncio async def test_header(client: DurationClient): await client.header.default(duration=datetime.timedelta(days=40)) diff --git a/packages/http-client-python/tests/mock_api/unbranded/test_encode_duration.py b/packages/http-client-python/tests/mock_api/unbranded/test_encode_duration.py index 0f9e6a1a593..b1a1e0ec2fc 100644 --- a/packages/http-client-python/tests/mock_api/unbranded/test_encode_duration.py +++ b/packages/http-client-python/tests/mock_api/unbranded/test_encode_duration.py @@ -105,6 +105,11 @@ def test_property(client: DurationClient): assert result.value == datetime.timedelta(milliseconds=210000) +def test_lossy(client: DurationClient): + client.lossy.int_seconds(input=datetime.timedelta(seconds=36.25)) + client.lossy.int_milliseconds(input=datetime.timedelta(milliseconds=36250.25)) + + def test_header(client: DurationClient): client.header.default(duration=datetime.timedelta(days=40)) client.header.iso8601(duration=datetime.timedelta(days=40))