Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
msyyc committed May 22, 2024
1 parent 136e575 commit 80bae34
Show file tree
Hide file tree
Showing 658 changed files with 3,024 additions and 2,479 deletions.
6 changes: 3 additions & 3 deletions eng/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def main(package_name: str, version_suffix: str, output_dir: str, package_versio
if "typespec-python" in package_versions:
version = package_versions["typespec-python"]
if args.publish_internal:
overrides["@azure-tools/typespec-python"] = (
f"{feedUrl}/@azure-tools/typespec-python/-/typespec-python-{version}.tgz"
)
overrides[
"@azure-tools/typespec-python"
] = f"{feedUrl}/@azure-tools/typespec-python/-/typespec-python-{version}.tgz"

with open(output_dir / "overrides.json", "w") as fp:
json.dump(overrides, fp, indent=2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,16 @@ def pylint_disable(self) -> str:
return ""

@abstractmethod
def response_type_annotation(self, **kwargs) -> str: ...
def response_type_annotation(self, **kwargs) -> str:
...

@abstractmethod
def response_docstring_text(self, **kwargs) -> str: ...
def response_docstring_text(self, **kwargs) -> str:
...

@abstractmethod
def response_docstring_type(self, **kwargs) -> str: ...
def response_docstring_type(self, **kwargs) -> str:
...

@property
def description(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
return file_import


class LROOperation(LROOperationBase[LROResponse]): ...
class LROOperation(LROOperationBase[LROResponse]):
...
4 changes: 4 additions & 0 deletions packages/autorest.python/autorest/codegen/models/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def has_response_body(self) -> bool:
"""Tell if at least one response has a body."""
return any(response.type for response in self.responses)

@property
def has_stream_kwargs(self) -> bool:
return self.expose_stream_keyword and self.has_response_body

@property
def any_response_has_headers(self) -> bool:
return any(response.headers for response in self.responses)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
return file_import


class PagingOperation(PagingOperationBase[PagingResponse]): ...
class PagingOperation(PagingOperationBase[PagingResponse]):
...
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def docstring_type_keyword(self) -> str:

@property
@abc.abstractmethod
def in_method_signature(self) -> bool: ...
def in_method_signature(self) -> bool:
...

def method_signature(self, async_mode: bool) -> str:
type_annot = self.type_annotation(async_mode=async_mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def imports(self) -> FileImport:

@staticmethod
@abstractmethod
def parameter_list_type() -> Callable[[Dict[str, Any], "CodeModel"], ParameterListType]: ...
def parameter_list_type() -> Callable[[Dict[str, Any], "CodeModel"], ParameterListType]:
...

@classmethod
def get_name(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
)
from .parameter_serializer import ParameterSerializer, PopKwargType
from ..models.parameter_list import ParameterType
from ..models.response import LROResponse
from . import utils
from ..._utils import JSON_REGEXP

Expand Down Expand Up @@ -220,7 +221,8 @@ def __init__(self, code_model: CodeModel, async_mode: bool) -> None:

@property
@abstractmethod
def _need_self_param(self) -> bool: ...
def _need_self_param(self) -> bool:
...

@property
@abstractmethod
Expand Down Expand Up @@ -322,7 +324,8 @@ def param_description_and_response_docstring(self, builder: BuilderType) -> List

@property
@abstractmethod
def _json_response_template_name(self) -> str: ...
def _json_response_template_name(self) -> str:
...

def _json_input_example_template(self, builder: BuilderType) -> List[str]:
template: List[str] = []
Expand Down Expand Up @@ -562,7 +565,7 @@ def make_pipeline_call(self, builder: OperationType) -> List[str]:
type_ignore = self.async_mode and builder.group_name == "" # is in a mixin
stream_value = (
f'kwargs.pop("stream", {builder.has_stream_response})'
if builder.expose_stream_keyword and builder.has_response_body
if builder.has_stream_kwargs
else builder.has_stream_response
)
return [
Expand Down Expand Up @@ -897,11 +900,18 @@ def _call_request_builder_helper( # pylint: disable=too-many-statements
def call_request_builder(self, builder: OperationType, is_paging: bool = False) -> List[str]:
return self._call_request_builder_helper(builder, builder.request_builder, is_paging=is_paging)

@property
def deserialize_for_stream_res(self) -> str:
if self.code_model.options["version_tolerant"]:
return "response.iter_bytes()"
return f"response.stream_download(self._client.{self.pipeline_name})"

def response_headers_and_deserialization(
self,
builder: OperationType,
response: Response,
) -> List[str]:
# pylint: disable=too-many-statements
retval: List[str] = [
(
f"response_headers['{response_header.wire_name}']=self._deserialize("
Expand All @@ -918,19 +928,23 @@ def response_headers_and_deserialization(
deserialized = f"{'await ' if self.async_mode else ''}response.read()"
else:
stream_logic = False
if self.code_model.options["version_tolerant"]:
deserialized = "response.iter_bytes()"
else:
deserialized = f"response.stream_download(self._client.{self.pipeline_name})"
deserialized = self.deserialize_for_stream_res
deserialize_code.append(f"deserialized = {deserialized}")
elif response.type:
pylint_disable = ""
if isinstance(response.type, ModelType) and response.type.internal:
pylint_disable = " # pylint: disable=protected-access"
if self.code_model.options["models_mode"] == "msrest":
if isinstance(response, LROResponse) and builder.has_stream_kwargs:
response_name = "_response"
deserialize_code.append(
"_response = pipeline_response if getattr(pipeline_response, 'context', {}) else pipeline_response.http_response.internal_response" # pylint: disable=line-too-long
)
else:
response_name = "pipeline_response"
deserialize_code.append("deserialized = self._deserialize(")
deserialize_code.append(f" '{response.serialization_type}',{pylint_disable}")
deserialize_code.append(" pipeline_response")
deserialize_code.append(f" {response_name}")
deserialize_code.append(")")
elif self.code_model.options["models_mode"] == "dpg":
if builder.has_stream_response:
Expand Down Expand Up @@ -959,7 +973,7 @@ def response_headers_and_deserialization(
if len(deserialize_code) > 0:
if builder.expose_stream_keyword and stream_logic:
retval.append("if _stream:")
retval.append(" deserialized = response.iter_bytes()")
retval.append(f" deserialized = {self.deserialize_for_stream_res}")
retval.append("else:")
retval.extend([f" {dc}" for dc in deserialize_code])
else:
Expand Down Expand Up @@ -1120,7 +1134,8 @@ def _call_method(self) -> str:
return "await " if self.async_mode else ""


class OperationSerializer(_OperationSerializer[Operation]): ...
class OperationSerializer(_OperationSerializer[Operation]):
...


############################## PAGING OPERATIONS ##############################
Expand Down Expand Up @@ -1282,7 +1297,8 @@ def set_up_params_for_pager(self, builder: PagingOperationType) -> List[str]:
return retval


class PagingOperationSerializer(_PagingOperationSerializer[PagingOperation]): ...
class PagingOperationSerializer(_PagingOperationSerializer[PagingOperation]):
...


############################## LRO OPERATIONS ##############################
Expand Down Expand Up @@ -1320,7 +1336,8 @@ def initial_call(self, builder: LROOperationType) -> List[str]:
[f" {parameter.client_name}={parameter.client_name}," for parameter in builder.parameters.method]
)
retval.append(" cls=lambda x,y,z: x,")
retval.append(" stream=True,")
if builder.has_stream_kwargs:
retval.append(" stream=True,")
retval.append(" headers=_headers,")
retval.append(" params=_params,")
retval.append(" **kwargs")
Expand Down Expand Up @@ -1400,7 +1417,8 @@ def get_long_running_output(self, builder: LROOperationType) -> List[str]:
return retval


class LROOperationSerializer(_LROOperationSerializer[LROOperation]): ...
class LROOperationSerializer(_LROOperationSerializer[LROOperation]):
...


############################## LRO PAGING OPERATIONS ##############################
Expand Down Expand Up @@ -1439,12 +1457,7 @@ def get_operation_serializer(
builder: Operation,
code_model,
async_mode: bool,
) -> Union[
OperationSerializer,
PagingOperationSerializer,
LROOperationSerializer,
LROPagingOperationSerializer,
]:
) -> Union[OperationSerializer, PagingOperationSerializer, LROOperationSerializer, LROPagingOperationSerializer,]:
retcls: Union[
Type[OperationSerializer],
Type[PagingOperationSerializer],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def _json_serialize_imports(
key=lambda e: (
_to_string(e) # type: ignore
if isinstance(e, (list, tuple))
else e if isinstance(e, str) else ""
else e
if isinstance(e, str)
else ""
)
)
json_package_name_dictionary[package_name] = name_import_ordered_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def _documentation_string(prop: Property, description_keyword: str, docstring_ty

class _ModelSerializer(BaseSerializer, ABC):
@abstractmethod
def imports(self) -> FileImport: ...
def imports(self) -> FileImport:
...

def serialize(self) -> str:
# Generate the models
Expand All @@ -36,7 +37,8 @@ def serialize(self) -> str:
)

@abstractmethod
def declare_model(self, model: ModelType) -> str: ...
def declare_model(self, model: ModelType) -> str:
...

@staticmethod
def escape_dot(s: str):
Expand Down
12 changes: 6 additions & 6 deletions packages/autorest.python/autorest/preprocess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def add_overload(yaml_data: Dict[str, Any], body_type: Dict[str, Any], for_flatt
content_type_param["inOverload"] = True
content_type_param["inDocstring"] = True
body_type_description = get_body_type_for_description(overload["bodyParameter"])
content_type_param["description"] = (
f"Body Parameter content-type. Content type parameter for {body_type_description} body."
)
content_type_param[
"description"
] = f"Body Parameter content-type. Content type parameter for {body_type_description} body."
content_types = yaml_data["bodyParameter"]["contentTypes"]
if body_type["type"] == "binary" and len(content_types) > 1:
content_types = "'" + "', '".join(content_types) + "'"
Expand Down Expand Up @@ -93,9 +93,9 @@ def add_overloads_for_body_param(yaml_data: Dict[str, Any]) -> None:
content_type_param["inOverload"] = False
content_type_param["inOverriden"] = True
content_type_param["inDocstring"] = True
content_type_param["clientDefaultValue"] = (
None # make it none bc it will be overriden, we depend on default of overloads
)
content_type_param[
"clientDefaultValue"
] = None # make it none bc it will be overriden, we depend on default of overloads
content_type_param["optional"] = True


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def build_polling_paging_example_basic_paging_request(**kwargs: Any) -> HttpRequ


class PollingPagingExampleOperationsMixin(PollingPagingExampleMixinABC):

def _basic_polling_initial(self, product: Optional[Union[JSON, IO[bytes]]] = None, **kwargs: Any) -> Optional[JSON]:
error_map: MutableMapping[int, Type[HttpResponseError]] = {
401: ClientAuthenticationError,
Expand Down Expand Up @@ -244,7 +243,6 @@ def begin_basic_polling(
product=product,
content_type=content_type,
cls=lambda x, y, z: x,
stream=True,
headers=_headers,
params=_params,
**kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@


class PollingPagingExampleOperationsMixin(PollingPagingExampleMixinABC):

async def _basic_polling_initial(
self, product: Optional[Union[JSON, IO[bytes]]] = None, **kwargs: Any
) -> Optional[JSON]:
Expand Down Expand Up @@ -217,7 +216,6 @@ async def begin_basic_polling(
product=product,
content_type=content_type,
cls=lambda x, y, z: x,
stream=True,
headers=_headers,
params=_params,
**kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


class MultiapiServiceClientOperationsMixin(object):

def begin_test_lro(
self, product: Optional[Union[_models.Product, IO[bytes]]] = None, **kwargs: Any
) -> LROPoller[_models.Product]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


class MultiapiServiceClientOperationsMixin(object):

async def begin_test_lro(
self, product: Optional[Union[_models.Product, IO[bytes]]] = None, **kwargs: Any
) -> AsyncLROPoller[_models.Product]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def _test_lro_initial(
deserialized = None
if response.status_code == 200:
if _stream:
deserialized = response.iter_bytes()
deserialized = response.stream_download(self._client._pipeline)
else:
deserialized = self._deserialize("Product", pipeline_response)

Expand Down Expand Up @@ -233,7 +233,6 @@ async def begin_test_lro(
product=product,
content_type=content_type,
cls=lambda x, y, z: x,
stream=True,
headers=_headers,
params=_params,
**kwargs
Expand Down Expand Up @@ -310,7 +309,7 @@ async def _test_lro_and_paging_initial(
raise HttpResponseError(response=response, error_format=ARMErrorFormat)

if _stream:
deserialized = response.iter_bytes()
deserialized = response.stream_download(self._client._pipeline)
else:
deserialized = self._deserialize("PagingResult", pipeline_response)

Expand Down Expand Up @@ -418,7 +417,6 @@ async def get_next(next_link=None):
client_request_id=client_request_id,
test_lro_and_paging_options=test_lro_and_paging_options,
cls=lambda x, y, z: x,
stream=True,
headers=_headers,
params=_params,
**kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _test_lro_initial(
deserialized = None
if response.status_code == 200:
if _stream:
deserialized = response.iter_bytes()
deserialized = response.stream_download(self._client._pipeline)
else:
deserialized = self._deserialize("Product", pipeline_response)

Expand Down Expand Up @@ -307,7 +307,6 @@ def begin_test_lro(
product=product,
content_type=content_type,
cls=lambda x, y, z: x,
stream=True,
headers=_headers,
params=_params,
**kwargs
Expand Down Expand Up @@ -384,7 +383,7 @@ def _test_lro_and_paging_initial(
raise HttpResponseError(response=response, error_format=ARMErrorFormat)

if _stream:
deserialized = response.iter_bytes()
deserialized = response.stream_download(self._client._pipeline)
else:
deserialized = self._deserialize("PagingResult", pipeline_response)

Expand Down Expand Up @@ -492,7 +491,6 @@ def get_next(next_link=None):
client_request_id=client_request_id,
test_lro_and_paging_options=test_lro_and_paging_options,
cls=lambda x, y, z: x,
stream=True,
headers=_headers,
params=_params,
**kwargs
Expand Down
Loading

0 comments on commit 80bae34

Please sign in to comment.