Skip to content

Commit

Permalink
get cadl ranch coverage to 100% with latest cadl-ranch (#2571)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored May 6, 2024
1 parent 80c2eb5 commit 25bf66d
Show file tree
Hide file tree
Showing 70 changed files with 1,991 additions and 215 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/add_cadl_ranch_coverage-2024-4-6-12-43-56.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-python"
---

add tests for cadl-ranch and fix api version issue with multiple clients
2 changes: 1 addition & 1 deletion packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@azure-tools/typespec-azure-resource-manager": "~0.41.0",
"@azure-tools/typespec-autorest": "~0.41.0",
"@azure-tools/cadl-ranch-expect": "~0.13.3",
"@azure-tools/cadl-ranch-specs": "~0.33.1",
"@azure-tools/cadl-ranch-specs": "~0.33.2",
"@types/js-yaml": "~4.0.5",
"@types/mocha": "~10.0.1",
"@types/node": "^18.16.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"CrossLanguagePackageId": "Encode.Duration",
"CrossLanguageDefinitionId": {
"encode.duration.models.DefaultDurationProperty": "Encode.Duration.Property.DefaultDurationProperty",
"encode.duration.models.Float64SecondsDurationProperty": "Encode.Duration.Property.Float64SecondsDurationProperty",
"encode.duration.models.FloatSecondsDurationArrayProperty": "Encode.Duration.Property.FloatSecondsDurationArrayProperty",
"encode.duration.models.FloatSecondsDurationProperty": "Encode.Duration.Property.FloatSecondsDurationProperty",
"encode.duration.models.Int32SecondsDurationProperty": "Encode.Duration.Property.Int32SecondsDurationProperty",
Expand All @@ -10,16 +11,19 @@
"encode.duration.DurationClient.query.iso8601": "Encode.Duration.Query.iso8601",
"encode.duration.DurationClient.query.int32_seconds": "Encode.Duration.Query.int32Seconds",
"encode.duration.DurationClient.query.float_seconds": "Encode.Duration.Query.floatSeconds",
"encode.duration.DurationClient.query.float64_seconds": "Encode.Duration.Query.float64Seconds",
"encode.duration.DurationClient.query.int32_seconds_array": "Encode.Duration.Query.int32SecondsArray",
"encode.duration.DurationClient.property.default": "Encode.Duration.Property.default",
"encode.duration.DurationClient.property.iso8601": "Encode.Duration.Property.iso8601",
"encode.duration.DurationClient.property.int32_seconds": "Encode.Duration.Property.int32Seconds",
"encode.duration.DurationClient.property.float_seconds": "Encode.Duration.Property.floatSeconds",
"encode.duration.DurationClient.property.float64_seconds": "Encode.Duration.Property.float64Seconds",
"encode.duration.DurationClient.property.float_seconds_array": "Encode.Duration.Property.floatSecondsArray",
"encode.duration.DurationClient.header.default": "Encode.Duration.Header.default",
"encode.duration.DurationClient.header.iso8601": "Encode.Duration.Header.iso8601",
"encode.duration.DurationClient.header.iso8601_array": "Encode.Duration.Header.iso8601Array",
"encode.duration.DurationClient.header.int32_seconds": "Encode.Duration.Header.int32Seconds",
"encode.duration.DurationClient.header.float_seconds": "Encode.Duration.Header.floatSeconds"
"encode.duration.DurationClient.header.float_seconds": "Encode.Duration.Header.floatSeconds",
"encode.duration.DurationClient.header.float64_seconds": "Encode.Duration.Header.float64Seconds"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@
from ..._model_base import SdkJSONEncoder, _deserialize
from ...operations._operations import (
build_header_default_request,
build_header_float64_seconds_request,
build_header_float_seconds_request,
build_header_int32_seconds_request,
build_header_iso8601_array_request,
build_header_iso8601_request,
build_property_default_request,
build_property_float64_seconds_request,
build_property_float_seconds_array_request,
build_property_float_seconds_request,
build_property_int32_seconds_request,
build_property_iso8601_request,
build_query_default_request,
build_query_float64_seconds_request,
build_query_float_seconds_request,
build_query_int32_seconds_array_request,
build_query_int32_seconds_request,
Expand Down Expand Up @@ -263,6 +266,54 @@ async def float_seconds( # pylint: disable=inconsistent-return-statements
if cls:
return cls(pipeline_response, None, {}) # type: ignore

@distributed_trace_async
async def float64_seconds( # pylint: disable=inconsistent-return-statements
self, *, input: float, **kwargs: Any
) -> None:
"""float64_seconds.
:keyword input: Required.
:paramtype input: float
:return: None
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

_headers = kwargs.pop("headers", {}) or {}
_params = kwargs.pop("params", {}) or {}

cls: ClsType[None] = kwargs.pop("cls", None)

_request = build_query_float64_seconds_request(
input=input,
headers=_headers,
params=_params,
)
_request.url = self._client.format_url(_request.url)

_stream = False
pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
_request, stream=_stream, **kwargs
)

response = pipeline_response.http_response

if response.status_code not in [204]:
if _stream:
await response.read() # Load the body in memory and close the socket
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

if cls:
return cls(pipeline_response, None, {}) # type: ignore

@distributed_trace_async
async def int32_seconds_array( # pylint: disable=inconsistent-return-statements
self, *, input: List[int], **kwargs: Any
Expand Down Expand Up @@ -955,6 +1006,165 @@ async def float_seconds(

return deserialized # type: ignore

@overload
async def float64_seconds(
self, body: _models.Float64SecondsDurationProperty, *, content_type: str = "application/json", **kwargs: Any
) -> _models.Float64SecondsDurationProperty:
"""float64_seconds.
:param body: Required.
:type body: ~encode.duration.models.Float64SecondsDurationProperty
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: Float64SecondsDurationProperty. The Float64SecondsDurationProperty is compatible with
MutableMapping
:rtype: ~encode.duration.models.Float64SecondsDurationProperty
:raises ~azure.core.exceptions.HttpResponseError:
Example:
.. code-block:: python
# JSON input template you can fill out and use as your body input.
body = {
"value": 0.0 # Required.
}
# response body for status code(s): 200
response == {
"value": 0.0 # Required.
}
"""

@overload
async def float64_seconds(
self, body: JSON, *, content_type: str = "application/json", **kwargs: Any
) -> _models.Float64SecondsDurationProperty:
"""float64_seconds.
:param body: Required.
:type body: JSON
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
Default value is "application/json".
:paramtype content_type: str
:return: Float64SecondsDurationProperty. The Float64SecondsDurationProperty is compatible with
MutableMapping
:rtype: ~encode.duration.models.Float64SecondsDurationProperty
:raises ~azure.core.exceptions.HttpResponseError:
Example:
.. code-block:: python
# response body for status code(s): 200
response == {
"value": 0.0 # Required.
}
"""

@overload
async def float64_seconds(
self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
) -> _models.Float64SecondsDurationProperty:
"""float64_seconds.
:param body: Required.
:type body: IO[bytes]
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
Default value is "application/json".
:paramtype content_type: str
:return: Float64SecondsDurationProperty. The Float64SecondsDurationProperty is compatible with
MutableMapping
:rtype: ~encode.duration.models.Float64SecondsDurationProperty
:raises ~azure.core.exceptions.HttpResponseError:
Example:
.. code-block:: python
# response body for status code(s): 200
response == {
"value": 0.0 # Required.
}
"""

@distributed_trace_async
async def float64_seconds(
self, body: Union[_models.Float64SecondsDurationProperty, JSON, IO[bytes]], **kwargs: Any
) -> _models.Float64SecondsDurationProperty:
"""float64_seconds.
:param body: Is one of the following types: Float64SecondsDurationProperty, JSON, IO[bytes]
Required.
:type body: ~encode.duration.models.Float64SecondsDurationProperty or JSON or IO[bytes]
:return: Float64SecondsDurationProperty. The Float64SecondsDurationProperty is compatible with
MutableMapping
:rtype: ~encode.duration.models.Float64SecondsDurationProperty
:raises ~azure.core.exceptions.HttpResponseError:
Example:
.. code-block:: python
# JSON input template you can fill out and use as your body input.
body = {
"value": 0.0 # Required.
}
# response body for status code(s): 200
response == {
"value": 0.0 # Required.
}
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
_params = kwargs.pop("params", {}) or {}

content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
cls: ClsType[_models.Float64SecondsDurationProperty] = kwargs.pop("cls", None)

content_type = content_type or "application/json"
_content = None
if isinstance(body, (IOBase, bytes)):
_content = body
else:
_content = json.dumps(body, cls=SdkJSONEncoder, exclude_readonly=True) # type: ignore

_request = build_property_float64_seconds_request(
content_type=content_type,
content=_content,
headers=_headers,
params=_params,
)
_request.url = self._client.format_url(_request.url)

_stream = kwargs.pop("stream", False)
pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
_request, stream=_stream, **kwargs
)

response = pipeline_response.http_response

if response.status_code not in [200]:
if _stream:
await response.read() # Load the body in memory and close the socket
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

if _stream:
deserialized = response.iter_bytes()
else:
deserialized = _deserialize(_models.Float64SecondsDurationProperty, response.json())

if cls:
return cls(pipeline_response, deserialized, {}) # type: ignore

return deserialized # type: ignore

@overload
async def float_seconds_array(
self, body: _models.FloatSecondsDurationArrayProperty, *, content_type: str = "application/json", **kwargs: Any
Expand Down Expand Up @@ -1383,3 +1593,51 @@ async def float_seconds( # pylint: disable=inconsistent-return-statements

if cls:
return cls(pipeline_response, None, {}) # type: ignore

@distributed_trace_async
async def float64_seconds( # pylint: disable=inconsistent-return-statements
self, *, duration: float, **kwargs: Any
) -> None:
"""float64_seconds.
:keyword duration: Required.
:paramtype duration: float
:return: None
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
"""
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

_headers = kwargs.pop("headers", {}) or {}
_params = kwargs.pop("params", {}) or {}

cls: ClsType[None] = kwargs.pop("cls", None)

_request = build_header_float64_seconds_request(
duration=duration,
headers=_headers,
params=_params,
)
_request.url = self._client.format_url(_request.url)

_stream = False
pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
_request, stream=_stream, **kwargs
)

response = pipeline_response.http_response

if response.status_code not in [204]:
if _stream:
await response.read() # Load the body in memory and close the socket
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response)

if cls:
return cls(pipeline_response, None, {}) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# --------------------------------------------------------------------------

from ._models import DefaultDurationProperty
from ._models import Float64SecondsDurationProperty
from ._models import FloatSecondsDurationArrayProperty
from ._models import FloatSecondsDurationProperty
from ._models import ISO8601DurationProperty
Expand All @@ -17,6 +18,7 @@

__all__ = [
"DefaultDurationProperty",
"Float64SecondsDurationProperty",
"FloatSecondsDurationArrayProperty",
"FloatSecondsDurationProperty",
"ISO8601DurationProperty",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useles
super().__init__(*args, **kwargs)


class Float64SecondsDurationProperty(_model_base.Model):
"""Float64SecondsDurationProperty.
All required parameters must be populated in order to send to server.
:ivar value: Required.
:vartype value: float
"""

value: float = rest_field()
"""Required."""

@overload
def __init__(
self,
*,
value: float,
): ...

@overload
def __init__(self, mapping: Mapping[str, Any]):
"""
:param mapping: raw JSON to initialize the model.
:type mapping: Mapping[str, Any]
"""

def __init__(self, *args: Any, **kwargs: Any) -> None: # pylint: disable=useless-super-delegation
super().__init__(*args, **kwargs)


class FloatSecondsDurationArrayProperty(_model_base.Model):
"""FloatSecondsDurationArrayProperty.
Expand Down
Loading

0 comments on commit 25bf66d

Please sign in to comment.