Skip to content

Commit 769d204

Browse files
authored
[non-Azure] adjust test framework to prepare for unbranded test (#2209)
* prepare test framework * Fix * fix * fix ci * add unbranded test * fix unbranded test * inv reg * inv reg
1 parent 6b44a18 commit 769d204

File tree

3,601 files changed

+339222
-110814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,601 files changed

+339222
-110814
lines changed

eng/pipelines/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ jobs:
166166
- template: generated-code-checks-template.yml
167167
parameters:
168168
package: "typespec-python"
169+
folderName: "azure"
170+
171+
- template: generated-code-checks-template.yml
172+
parameters:
173+
package: "typespec-python"
174+
folderName: "unbranded"
169175

170176
- script: cadl-ranch check-coverage http/
171177
displayName: Check Coverage

eng/pipelines/publish-release.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ steps:
4646
displayName: Execute Autorest DPG Version Tolerant Tests
4747
workingDirectory: $(Build.SourcesDirectory)/packages/autorest.python/
4848
- script: |
49-
cd test
49+
cd test/azure
5050
tox run -e ci
51-
displayName: Execute Cadl Tests
51+
displayName: Execute Typespec Azure Tests
52+
workingDirectory: $(Build.SourcesDirectory)/packages/typespec-python/
53+
- script: |
54+
cd test/unbranded
55+
tox run -e ci
56+
displayName: Execute Typespec Unbranded Tests
5257
workingDirectory: $(Build.SourcesDirectory)/packages/typespec-python/
5358
5459
- script: |

packages/autorest.python/autorest/codegen/models/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
BooleanType,
2929
AnyObjectType,
3030
UnixTimeType,
31-
AzureCoreType,
31+
SdkCoreType,
3232
)
3333
from .enum_type import EnumType, EnumValue
3434
from .base import BaseType
@@ -67,15 +67,15 @@
6767
)
6868
from .credential_types import (
6969
TokenCredentialType,
70-
AzureKeyCredentialType,
70+
KeyCredentialType,
7171
ARMChallengeAuthenticationPolicyType,
7272
BearerTokenCredentialPolicyType,
73-
AzureKeyCredentialPolicyType,
73+
KeyCredentialPolicyType,
7474
CredentialType,
7575
)
7676

7777
__all__ = [
78-
"AzureKeyCredentialPolicyType",
78+
"KeyCredentialPolicyType",
7979
"AnyType",
8080
"BaseModel",
8181
"BaseType",
@@ -140,14 +140,14 @@
140140
"boolean": BooleanType,
141141
"combined": CombinedType,
142142
"OAuth2": TokenCredentialType,
143-
"Key": AzureKeyCredentialType,
143+
"Key": KeyCredentialType,
144144
"ARMChallengeAuthenticationPolicy": ARMChallengeAuthenticationPolicyType,
145145
"BearerTokenCredentialPolicy": BearerTokenCredentialPolicyType,
146-
"AzureKeyCredentialPolicy": AzureKeyCredentialPolicyType,
146+
"KeyCredentialPolicy": KeyCredentialPolicyType,
147147
"any-object": AnyObjectType,
148148
"unixtime": UnixTimeType,
149149
"credential": StringType,
150-
"azurecore": AzureCoreType,
150+
"sdkcore": SdkCoreType,
151151
}
152152
_LOGGER = logging.getLogger(__name__)
153153

packages/autorest.python/autorest/codegen/models/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def _imports_shared(self, async_mode: bool) -> FileImport:
205205
)
206206
else:
207207
file_import.add_submodule_import(
208-
file_import.import_core,
208+
file_import.import_core_pipeline_client,
209209
self.pipeline_class(async_mode),
210210
ImportType.SDKCORE,
211211
)
@@ -231,7 +231,7 @@ def _imports_shared(self, async_mode: bool) -> FileImport:
231231
typing_section=TypingSection.REGULAR,
232232
)
233233
file_import.add_submodule_import(
234-
file_import.import_core_pipeline, "policies", ImportType.SDKCORE
234+
file_import.import_core_policies, "policies", ImportType.SDKCORE
235235
)
236236
if self.code_model.options["azure_arm"]:
237237
async_prefix = "Async" if async_mode else ""
@@ -414,7 +414,7 @@ def name(self) -> str:
414414
def _imports_shared(self, async_mode: bool) -> FileImport:
415415
file_import = self.init_file_import()
416416
file_import.add_submodule_import(
417-
file_import.import_core_pipeline, "policies", ImportType.SDKCORE
417+
file_import.import_core_policies, "policies", ImportType.SDKCORE
418418
)
419419
file_import.add_submodule_import(
420420
"typing", "Any", ImportType.STDLIB, TypingSection.CONDITIONAL

packages/autorest.python/autorest/codegen/models/credential_types.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class _CredentialPolicyBaseType:
2727
"""Base class for our different credential policy types.
2828
29-
Inherited by our BearerTokenCredentialPolicy and AzureKeyCredentialPolicy types.
29+
Inherited by our BearerTokenCredentialPolicy and KeyCredentialPolicy types.
3030
"""
3131

3232
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
@@ -71,7 +71,7 @@ def call(self, async_mode: bool) -> str:
7171
return f"{policy_name}(self.credential, *self.credential_scopes, **kwargs)"
7272

7373

74-
class AzureKeyCredentialPolicyType(_CredentialPolicyBaseType):
74+
class KeyCredentialPolicyType(_CredentialPolicyBaseType):
7575
def __init__(
7676
self,
7777
yaml_data: Dict[str, Any],
@@ -83,16 +83,26 @@ def __init__(
8383
self.key = key
8484
self.scheme = scheme
8585

86+
@property
87+
def credential_name(self) -> str:
88+
return (
89+
"AzureKeyCredential"
90+
if not self.code_model.options["unbranded"]
91+
else "ServiceKeyCredential"
92+
)
93+
8694
def call(self, async_mode: bool) -> str:
8795
params = f'"{self.key}", '
8896
if self.scheme:
8997
params += f'prefix="{self.scheme}", '
90-
return f"policies.AzureKeyCredentialPolicy(self.credential, {params}**kwargs)"
98+
return (
99+
f"policies.{self.credential_name}Policy(self.credential, {params}**kwargs)"
100+
)
91101

92102
@classmethod
93103
def from_yaml(
94104
cls, yaml_data: Dict[str, Any], code_model: "CodeModel"
95-
) -> "AzureKeyCredentialPolicyType":
105+
) -> "KeyCredentialPolicyType":
96106
return cls(
97107
yaml_data, code_model, yaml_data["key"], yaml_data.get("scheme", None)
98108
)
@@ -103,15 +113,15 @@ def from_yaml(
103113
bound=Union[
104114
BearerTokenCredentialPolicyType,
105115
ARMChallengeAuthenticationPolicyType,
106-
AzureKeyCredentialPolicyType,
116+
KeyCredentialPolicyType,
107117
],
108118
)
109119

110120

111121
class CredentialType(
112122
Generic[CredentialPolicyType], BaseType
113123
): # pylint:disable=abstract-method
114-
"""Store info about the type of the credential. Can be either an AzureKeyCredential or a TokenCredential"""
124+
"""Store info about the type of the credential. Can be either an KeyCredential or a TokenCredential"""
115125

116126
def __init__(
117127
self,
@@ -204,27 +214,27 @@ def instance_check_template(self) -> str:
204214
return "hasattr({}, 'get_token')"
205215

206216

207-
class AzureKeyCredentialType(
217+
class KeyCredentialType(
208218
# pylint: disable=unsubscriptable-object
209-
CredentialType[AzureKeyCredentialPolicyType]
219+
CredentialType[KeyCredentialPolicyType]
210220
):
211-
"""Type for an AzureKeyCredential"""
221+
"""Type for an KeyCredential"""
212222

213223
def docstring_type(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
214-
return "~azure.core.credentials.AzureKeyCredential"
224+
return f"~{self.init_file_import().import_core}.credentials.{self.policy.credential_name}"
215225

216226
def type_annotation(self, **kwargs: Any) -> str: # pylint: disable=unused-argument
217-
return "AzureKeyCredential"
227+
return self.policy.credential_name
218228

219229
@property
220230
def instance_check_template(self) -> str:
221-
return "isinstance({}, AzureKeyCredential)"
231+
return "isinstance({}, " + f"{self.policy.credential_name})"
222232

223233
def imports(self, **kwargs: Any) -> FileImport: # pylint: disable=unused-argument
224234
file_import = self.init_file_import()
225235
file_import.add_submodule_import(
226-
"azure.core.credentials",
227-
"AzureKeyCredential",
236+
f"{file_import.import_core}.credentials",
237+
self.policy.credential_name,
228238
ImportType.SDKCORE,
229239
typing_section=TypingSection.CONDITIONAL,
230240
)

packages/autorest.python/autorest/codegen/models/imports.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(
8787
self.async_definition = async_definition
8888

8989

90-
class FileImport:
90+
class FileImport: # pylint: disable=too-many-public-methods
9191
def __init__(self, code_model: "CodeModel") -> None:
9292
self.imports: List[ImportModel] = []
9393
self.code_model = code_model
@@ -331,8 +331,8 @@ def import_core_credentials(self) -> str:
331331

332332
@property
333333
def import_core_credentials_async(self) -> str:
334-
return (
335-
self.import_core + ".credentials_async"
334+
return self.import_core + (
335+
".credentials_async"
336336
if not self.code_model.options["unbranded"]
337337
else ".credentials"
338338
)
@@ -343,10 +343,8 @@ def import_core_paging(self) -> str:
343343

344344
@property
345345
def import_core_paging_async(self) -> str:
346-
return (
347-
self.import_core + ".async_paging"
348-
if not self.code_model.options["unbranded"]
349-
else ".paging"
346+
return self.import_core + (
347+
".async_paging" if not self.code_model.options["unbranded"] else ".paging"
350348
)
351349

352350
@property
@@ -355,20 +353,30 @@ def import_core_utils(self) -> str:
355353

356354
@property
357355
def import_core_case_insensitive_enum(self) -> str:
358-
return (
359-
self.import_core + ""
360-
if not self.code_model.options["unbranded"]
361-
else ".utils"
356+
return self.import_core + (
357+
"" if not self.code_model.options["unbranded"] else ".utils"
362358
)
363359

364360
@property
365361
def import_core_pipeline(self) -> str:
366-
return (
367-
self.import_core + ".pipeline"
362+
return self.import_core + (
363+
".pipeline"
368364
if not self.code_model.options["unbranded"]
369-
else ".runtime"
365+
else ".runtime.pipeline"
366+
)
367+
368+
@property
369+
def import_core_policies(self) -> str:
370+
return self.import_core + (
371+
".pipeline" if not self.code_model.options["unbranded"] else ".runtime"
370372
)
371373

372374
@property
373375
def import_core_serialization(self) -> str:
374376
return f"{self.import_core}.serialization"
377+
378+
@property
379+
def import_core_pipeline_client(self) -> str:
380+
return self.import_core + (
381+
"" if not self.code_model.options["unbranded"] else ".runtime"
382+
)

packages/autorest.python/autorest/codegen/models/lro_operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
126126
file_import = super().imports(async_mode, **kwargs)
127127
if self.abstract:
128128
return file_import
129-
if async_mode:
129+
if async_mode and self.code_model.options["tracing"] and self.want_tracing:
130130
file_import.add_submodule_import(
131131
"azure.core.tracing.decorator_async",
132132
"distributed_trace_async",

packages/autorest.python/autorest/codegen/models/operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport:
560560
file_import = super().imports(async_mode, **kwargs)
561561
if self.abstract:
562562
return file_import
563-
if async_mode:
563+
if async_mode and self.code_model.options["tracing"] and self.want_tracing:
564564
file_import.add_submodule_import(
565565
"azure.core.tracing.decorator_async",
566566
"distributed_trace_async",

packages/autorest.python/autorest/codegen/models/primitive_types.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,20 +606,24 @@ def instance_check_template(self) -> str:
606606
return "isinstance({}, bytes)"
607607

608608

609-
class AzureCoreType(PrimitiveType):
609+
class SdkCoreType(PrimitiveType):
610610
def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
611611
super().__init__(yaml_data=yaml_data, code_model=code_model)
612612
self.name = yaml_data.get("name", "")
613613

614614
def docstring_type(self, **kwargs: Any) -> str:
615-
return "~azure.core." + self.type_annotation(**kwargs)
615+
return f"~{self.init_file_import().import_core}" + self.type_annotation(
616+
**kwargs
617+
)
616618

617619
def type_annotation(self, **kwargs: Any) -> str:
618620
return self.name
619621

620622
def imports(self, **kwargs: Any) -> FileImport:
621623
file_import = self.init_file_import()
622-
file_import.add_submodule_import("azure.core", self.name, ImportType.SDKCORE)
624+
file_import.add_submodule_import(
625+
file_import.import_core, self.name, ImportType.SDKCORE
626+
)
623627
return file_import
624628

625629
@property

packages/autorest.python/autorest/codegen/serializers/builder_serializer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ def serialize_path(self, builder: BuilderType) -> List[str]:
426426
builder.parameters.path, self.serializer_name
427427
)
428428

429+
@property
430+
def pipeline_name(self) -> str:
431+
if not self.code_model.options["unbranded"]:
432+
return "_pipeline"
433+
return "pipeline"
434+
429435

430436
############################## REQUEST BUILDERS ##############################
431437

@@ -644,7 +650,7 @@ def make_pipeline_call(self, builder: OperationType) -> List[str]:
644650
)
645651
return [
646652
f"_stream = {stream_value}",
647-
f"pipeline_response: PipelineResponse = {self._call_method}self._client._pipeline.run( "
653+
f"pipeline_response: PipelineResponse = {self._call_method}self._client.{self.pipeline_name}.run( "
648654
+ f"{'# type: ignore' if type_ignore else ''} # pylint: disable=protected-access",
649655
" _request,",
650656
" stream=_stream,",
@@ -1055,7 +1061,7 @@ def response_headers_and_deserialization(
10551061
"deserialized = {}".format(
10561062
"response.iter_bytes()"
10571063
if self.code_model.options["version_tolerant"]
1058-
else "response.stream_download(self._client._pipeline)"
1064+
else f"response.stream_download(self._client.{self.pipeline_name})"
10591065
)
10601066
)
10611067
elif response.type:

packages/autorest.python/autorest/codegen/serializers/client_serializer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ def should_init_super(self) -> bool:
111111
def initialize_pipeline_client(self, async_mode: bool) -> List[str]:
112112
result = []
113113
pipeline_client_name = self.client.pipeline_class(async_mode)
114+
endpoint_name = (
115+
"endpoint" if self.client.code_model.options["unbranded"] else "base_url"
116+
)
114117
params = {
115-
"base_url": self.host_variable_name,
118+
endpoint_name: self.host_variable_name,
116119
"policies": "_policies",
117120
}
118121
if not self.client.code_model.is_legacy and self.client.request_id_header_name:

packages/autorest.python/autorest/codegen/serializers/general_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def serialize_vendor_file(self, clients: List[Client]) -> str:
107107
ImportType.STDLIB,
108108
)
109109
file_import.add_submodule_import(
110-
file_import.import_core,
110+
file_import.import_core_pipeline_client,
111111
f"{'Async' if self.async_mode else ''}PipelineClient",
112112
ImportType.SDKCORE,
113113
TypingSection.TYPING,

0 commit comments

Comments
 (0)