From 0176e7c1eca1c95ea8079042f2a6d0c84db3b4bb Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Thu, 16 Jan 2025 12:23:13 +0800 Subject: [PATCH 01/32] update root namespace --- packages/http-client-python/emitter/src/code-model.ts | 3 ++- packages/http-client-python/emitter/src/utils.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/http-client-python/emitter/src/code-model.ts b/packages/http-client-python/emitter/src/code-model.ts index 398fdc8f4ee..1a1641f4a1d 100644 --- a/packages/http-client-python/emitter/src/code-model.ts +++ b/packages/http-client-python/emitter/src/code-model.ts @@ -37,6 +37,7 @@ import { getClientNamespace, getImplementation, removeUnderscoresFromNamespace, + getRootNamespace, } from "./utils.js"; function emitBasicMethod( @@ -281,7 +282,7 @@ export function emitCodeModel( // Get types const sdkPackage = sdkContext.sdkPackage; const codeModel: Record = { - namespace: removeUnderscoresFromNamespace(sdkPackage.rootNamespace).toLowerCase(), + namespace: getRootNamespace(sdkContext), clients: [], }; for (const client of sdkPackage.clients) { diff --git a/packages/http-client-python/emitter/src/utils.ts b/packages/http-client-python/emitter/src/utils.ts index 4028a421fed..8fc045c4475 100644 --- a/packages/http-client-python/emitter/src/utils.ts +++ b/packages/http-client-python/emitter/src/utils.ts @@ -200,13 +200,17 @@ export function capitalize(name: string): string { return name[0].toUpperCase() + name.slice(1); } + +export function getRootNamespace(context: PythonSdkContext): string { + const rootNamespace = context.emitContext.options["enable-typespec-namespace"] ? context.sdkPackage.namespaces[0].fullName : context.sdkPackage.rootNamespace; + return removeUnderscoresFromNamespace(rootNamespace).toLowerCase(); +} + export function getClientNamespace( context: PythonSdkContext, clientNamespace: string, ) { - const rootNamespace = removeUnderscoresFromNamespace( - context.sdkPackage.rootNamespace, - ).toLowerCase(); + const rootNamespace = getRootNamespace(context); if (!context.emitContext.options["enable-typespec-namespace"]) { return rootNamespace; } From fba07810597d8ba70d30803547d99a5cd4e67932 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 17 Jan 2025 10:34:52 +0800 Subject: [PATCH 02/32] update regnerate.ts --- .../emitter/src/code-model.ts | 8 +----- .../http-client-python/emitter/src/utils.ts | 5 ++-- .../eng/scripts/ci/regenerate.ts | 26 +------------------ 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/packages/http-client-python/emitter/src/code-model.ts b/packages/http-client-python/emitter/src/code-model.ts index 1a1641f4a1d..6da74f43d8e 100644 --- a/packages/http-client-python/emitter/src/code-model.ts +++ b/packages/http-client-python/emitter/src/code-model.ts @@ -32,13 +32,7 @@ import { simpleTypesMap, typesMap, } from "./types.js"; -import { - emitParamBase, - getClientNamespace, - getImplementation, - removeUnderscoresFromNamespace, - getRootNamespace, -} from "./utils.js"; +import { emitParamBase, getClientNamespace, getImplementation, getRootNamespace } from "./utils.js"; function emitBasicMethod( context: PythonSdkContext, diff --git a/packages/http-client-python/emitter/src/utils.ts b/packages/http-client-python/emitter/src/utils.ts index 8fc045c4475..ec466608095 100644 --- a/packages/http-client-python/emitter/src/utils.ts +++ b/packages/http-client-python/emitter/src/utils.ts @@ -200,9 +200,10 @@ export function capitalize(name: string): string { return name[0].toUpperCase() + name.slice(1); } - export function getRootNamespace(context: PythonSdkContext): string { - const rootNamespace = context.emitContext.options["enable-typespec-namespace"] ? context.sdkPackage.namespaces[0].fullName : context.sdkPackage.rootNamespace; + const rootNamespace = context.emitContext.options["enable-typespec-namespace"] + ? context.sdkPackage.namespaces[0].fullName + : context.sdkPackage.rootNamespace; return removeUnderscoresFromNamespace(rootNamespace).toLowerCase(); } diff --git a/packages/http-client-python/eng/scripts/ci/regenerate.ts b/packages/http-client-python/eng/scripts/ci/regenerate.ts index b54b0492ce2..c86ad7423a9 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate.ts @@ -123,9 +123,6 @@ const EMITTER_OPTIONS: Record | Record[ ? relativeSpec : dirname(relativeSpec); const emitter_options = EMITTER_OPTIONS[key] || [{}]; - const result = Array.isArray(emitter_options) ? emitter_options : [emitter_options]; - - function updateOptions(options: Record): void { - if (options["package-name"] && options["enable-typespec-namespace"] === undefined) { - options["enable-typespec-namespace"] = "false"; - } - } - - // when package name is different with typespec namespace, disable typespec namespace - if (flavor !== "azure") { - for (const options of result) { - if (Array.isArray(options)) { - for (const option of options) { - updateOptions(option); - } - } else { - updateOptions(options); - } - } - } - - return result; + return Array.isArray(emitter_options) ? emitter_options : [emitter_options]; } // Function to execute CLI commands asynchronously From e81ec404f4bbbd99f94ba46a39908a3bfa062de9 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 17 Jan 2025 13:15:43 +0800 Subject: [PATCH 03/32] fix ci --- .../http-client-python/emitter/src/utils.ts | 41 ++++++++++++++----- .../pygen/codegen/serializers/__init__.py | 5 ++- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/packages/http-client-python/emitter/src/utils.ts b/packages/http-client-python/emitter/src/utils.ts index ec466608095..6dcd8289f9f 100644 --- a/packages/http-client-python/emitter/src/utils.ts +++ b/packages/http-client-python/emitter/src/utils.ts @@ -200,9 +200,37 @@ export function capitalize(name: string): string { return name[0].toUpperCase() + name.slice(1); } +const LIB_NAMESPACE = [ + "azure.core", + "azure.resourcemanager", + "azure.clientgenerator.core", + "typespec.rest", + "typespec.http", + "typespec.versioning", +]; + +function getRootTypespecNamespace(context: PythonSdkContext): string { + if (context.sdkPackage.clients.length > 0) { + return context.sdkPackage.clients[0].clientNamespace; + } + if (context.sdkPackage.models.length > 0) { + const result = context.sdkPackage.models + .map((model) => model.clientNamespace) + .filter((namespace) => !LIB_NAMESPACE.includes(namespace)); + if (result.length > 0) { + result.sort(); + return result[0]; + } + } + if (context.sdkPackage.namespaces.length > 0) { + return context.sdkPackage.namespaces[0].fullName; + } + return ""; +} + export function getRootNamespace(context: PythonSdkContext): string { const rootNamespace = context.emitContext.options["enable-typespec-namespace"] - ? context.sdkPackage.namespaces[0].fullName + ? getRootTypespecNamespace(context) : context.sdkPackage.rootNamespace; return removeUnderscoresFromNamespace(rootNamespace).toLowerCase(); } @@ -215,16 +243,7 @@ export function getClientNamespace clientNamespace.toLowerCase().startsWith(item)) - ) { + if (LIB_NAMESPACE.some((item) => clientNamespace.toLowerCase().startsWith(item))) { return rootNamespace; } return clientNamespace === "" diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py index 2ec9c2f49d9..62ad8cc0b18 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -465,7 +465,10 @@ def _namespace_from_package_name(self) -> str: return get_namespace_from_package_name(self.code_model.options["package_name"]) def _name_space(self) -> str: - if self.code_model.namespace.count(".") >= self._namespace_from_package_name.count("."): + if ( + self.code_model.namespace.count(".") >= self._namespace_from_package_name.count(".") + or self.code_model.options["enable_typespec_namespace"] + ): return self.code_model.namespace return self._namespace_from_package_name From 88e8473f33a1783ee75db4695a4620a5a1f4f7f7 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 17 Jan 2025 13:37:06 +0800 Subject: [PATCH 04/32] fix test --- .../unbranded/mock_api_tests/asynctests/test_unbranded_async.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py index 1ba8cc5750d..c5dda175a7e 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py @@ -4,7 +4,7 @@ # ------------------------------------ import traceback import pytest -from typetest.scalar.aio import ScalarClient +from type.scalar.aio import ScalarClient from corehttp.exceptions import HttpResponseError From 3c289919e5629b7058768d5b218d11b144646683 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 17 Jan 2025 14:49:30 +0800 Subject: [PATCH 05/32] fix ci --- .../pygen/codegen/serializers/__init__.py | 2 ++ .../packaging_templates/setup.py.jinja2 | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py index 62ad8cc0b18..58c6dd1d90f 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -197,6 +197,8 @@ def _serialize_and_write_package_files(self, client_namespace: str) -> None: env = Environment( loader=PackageLoader("pygen.codegen", "templates/packaging_templates"), undefined=StrictUndefined, + trim_blocks=True, + lstrip_blocks=True, ) package_files = _PACKAGE_FILES diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 index 45239f0dac5..6a1d6e5101d 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 @@ -2,19 +2,28 @@ {{ license_header }} # coding: utf-8 {% if package_mode %} + import os import re -{% endif -%} +{% endif %} from setuptools import setup, find_packages {% set package_name = package_name or code_model.clients[0].name %} PACKAGE_NAME = "{{ package_name|lower }}" -{% if package_mode -%} +{% if code_model.options["enable_typespec_namespace"] %} +PACKAGE_NAMESPACE = "{{ code_model.namespace|lower }}" +{% endif %} +{% if package_mode %} PACKAGE_PPRINT_NAME = "{{ package_pprint_name }}" +{% if code_model.options["enable_typespec_namespace"] %} +# a.b.c => a/b/c +package_folder_path = PACKAGE_NAMESPACE.replace(".", "/") +{% else %} # a-b-c => a/b/c package_folder_path = PACKAGE_NAME.replace("-", "/") +{% endif %} # Version extraction inspired from 'requests' with open(os.path.join(package_folder_path, "_version.py"), "r") as fd: @@ -33,7 +42,8 @@ version = "{{ package_version }}" {% set long_description = code_model.description %} {% set author_email = "" %} {% set url = "" %} -{% endif -%} +{% endif %} + setup( name=PACKAGE_NAME, @@ -70,9 +80,9 @@ setup( {% if pkgutil_names %} # Exclude packages that will be covered by PEP420 or nspkg {% endif %} - {%- for pkgutil_name in pkgutil_names %} + {% for pkgutil_name in pkgutil_names %} "{{ pkgutil_name }}", - {%- endfor %} + {% endfor %} ] ), include_package_data=True, From 4ac4d7390864677f52bb62cd404fe36280f2c371 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 17 Jan 2025 14:50:22 +0800 Subject: [PATCH 06/32] for debug --- packages/http-client-python/generator/test/unbranded/tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-python/generator/test/unbranded/tox.ini b/packages/http-client-python/generator/test/unbranded/tox.ini index 68ed962f131..079049da189 100644 --- a/packages/http-client-python/generator/test/unbranded/tox.ini +++ b/packages/http-client-python/generator/test/unbranded/tox.ini @@ -7,7 +7,7 @@ deps= -r requirements.txt commands = # pytest - pytest mock_api_tests ../generic_mock_api_tests + # pytest mock_api_tests ../generic_mock_api_tests # pylint pip install azure-pylint-guidelines-checker==0.5.0 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/" From 457f3851907cf6521c17f26e3742aa1376a9c543 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 17 Jan 2025 16:46:49 +0800 Subject: [PATCH 07/32] update test --- .../eng/scripts/ci/regenerate.ts | 4 +- .../asynctests/test_typetest_array_async.py | 118 ++++++ .../test_typetest_dictionary_async.py | 98 +++++ .../test_typetest_enum_extensible_async.py | 25 ++ .../test_typetest_enum_fixed_async.py | 27 ++ .../test_typetest_model_empty_async.py | 32 ++ ...el_inheritance_enum_discriminator_async.py | 70 ++++ ..._inheritance_nested_discriminator_async.py | 85 +++++ ...del_inheritance_not_discriminated_async.py | 34 ++ ...etest_model_inheritance_recursive_async.py | 34 ++ ..._inheritance_single_discriminator_async.py | 67 ++++ .../test_typetest_model_usage_async.py | 32 ++ .../test_typetest_model_visibility_async.py | 47 +++ ...est_property_additionalproperties_async.py | 352 ++++++++++++++++++ .../test_typetest_property_nullable_async.py | 110 ++++++ .../test_typetest_property_optional_async.py | 197 ++++++++++ ...test_typetest_property_valuetypes_async.py | 315 ++++++++++++++++ .../asynctests/test_typetest_scalar_async.py | 60 +++ .../asynctests/test_typetest_union_async.py | 90 +++++ .../mock_api_tests}/test_typetest_array.py | 0 .../test_typetest_dictionary.py | 0 .../test_typetest_enum_extensible.py | 0 .../test_typetest_enum_fixed.py | 0 .../test_typetest_model_empty.py | 0 ...st_model_inheritance_enum_discriminator.py | 0 ..._model_inheritance_nested_discriminator.py | 0 ...est_model_inheritance_not_discriminated.py | 0 ...st_typetest_model_inheritance_recursive.py | 0 ..._model_inheritance_single_discriminator.py | 0 .../test_typetest_model_usage.py | 0 .../test_typetest_model_visibility.py | 0 ..._typetest_property_additionalproperties.py | 0 .../test_typetest_property_nullable.py | 0 .../test_typetest_property_optional.py | 0 .../test_typetest_property_valuetypes.py | 0 .../mock_api_tests}/test_typetest_scalar.py | 0 .../mock_api_tests}/test_typetest_union.py | 0 .../asynctests/test_typetest_array_async.py | 118 ++++++ .../test_typetest_dictionary_async.py | 98 +++++ .../test_typetest_enum_extensible_async.py | 25 ++ .../test_typetest_enum_fixed_async.py | 27 ++ .../test_typetest_model_empty_async.py | 32 ++ ...el_inheritance_enum_discriminator_async.py | 70 ++++ ..._inheritance_nested_discriminator_async.py | 85 +++++ ...del_inheritance_not_discriminated_async.py | 34 ++ ...etest_model_inheritance_recursive_async.py | 34 ++ ..._inheritance_single_discriminator_async.py | 67 ++++ .../test_typetest_model_usage_async.py | 32 ++ .../test_typetest_model_visibility_async.py | 47 +++ ...est_property_additionalproperties_async.py | 352 ++++++++++++++++++ .../test_typetest_property_nullable_async.py | 110 ++++++ .../test_typetest_property_optional_async.py | 197 ++++++++++ ...test_typetest_property_valuetypes_async.py | 315 ++++++++++++++++ .../asynctests/test_typetest_scalar_async.py | 60 +++ .../asynctests/test_typetest_union_async.py | 90 +++++ .../mock_api_tests/test_typetest_array.py | 103 +++++ .../test_typetest_dictionary.py | 86 +++++ .../test_typetest_enum_extensible.py | 23 ++ .../test_typetest_enum_fixed.py | 25 ++ .../test_typetest_model_empty.py | 29 ++ ...st_model_inheritance_enum_discriminator.py | 58 +++ ..._model_inheritance_nested_discriminator.py | 79 ++++ ...est_model_inheritance_not_discriminated.py | 31 ++ ...st_typetest_model_inheritance_recursive.py | 32 ++ ..._model_inheritance_single_discriminator.py | 60 +++ .../test_typetest_model_usage.py | 28 ++ .../test_typetest_model_visibility.py | 40 ++ ..._typetest_property_additionalproperties.py | 313 ++++++++++++++++ .../test_typetest_property_nullable.py | 102 +++++ .../test_typetest_property_optional.py | 174 +++++++++ .../test_typetest_property_valuetypes.py | 286 ++++++++++++++ .../mock_api_tests/test_typetest_scalar.py | 53 +++ .../mock_api_tests/test_typetest_union.py | 80 ++++ .../mock_api_tests/test_unbranded.py | 2 +- .../generator/test/unbranded/tox.ini | 2 +- 75 files changed, 5192 insertions(+), 4 deletions(-) create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_array_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_dictionary_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_empty_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_usage_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_visibility_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_nullable_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_optional_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_scalar_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_union_async.py rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_array.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_dictionary.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_enum_extensible.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_enum_fixed.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_model_empty.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_model_inheritance_enum_discriminator.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_model_inheritance_nested_discriminator.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_model_inheritance_not_discriminated.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_model_inheritance_recursive.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_model_inheritance_single_discriminator.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_model_usage.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_model_visibility.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_property_additionalproperties.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_property_nullable.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_property_optional.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_property_valuetypes.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_scalar.py (100%) rename packages/http-client-python/generator/test/{generic_mock_api_tests => azure/mock_api_tests}/test_typetest_union.py (100%) create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_array_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_dictionary_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_empty_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_usage_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_visibility_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_nullable_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_optional_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_scalar_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_union_async.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_array.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_dictionary.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_extensible.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_empty.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_usage.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_visibility.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_additionalproperties.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_nullable.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_optional.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_valuetypes.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_scalar.py create mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_union.py diff --git a/packages/http-client-python/eng/scripts/ci/regenerate.ts b/packages/http-client-python/eng/scripts/ci/regenerate.ts index c86ad7423a9..599bbb3fa0e 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate.ts @@ -90,8 +90,8 @@ const EMITTER_OPTIONS: Record | Record Date: Fri, 17 Jan 2025 16:58:05 +0800 Subject: [PATCH 08/32] udpate test --- .../asynctests/test_typetest_enum_fixed_async.py | 5 +++-- .../test/azure/mock_api_tests/test_typetest_enum_fixed.py | 6 +++--- .../asynctests/test_typetest_enum_fixed_async.py | 5 +++-- ...t_typetest_model_inheritance_enum_discriminator_async.py | 4 ++-- ...typetest_model_inheritance_nested_discriminator_async.py | 4 ++-- ...st_typetest_model_inheritance_not_discriminated_async.py | 4 ++-- .../test_typetest_model_inheritance_recursive_async.py | 4 ++-- ...typetest_model_inheritance_single_discriminator_async.py | 4 ++-- .../unbranded/mock_api_tests/test_typetest_enum_fixed.py | 6 +++--- .../test_typetest_model_inheritance_enum_discriminator.py | 4 ++-- .../test_typetest_model_inheritance_nested_discriminator.py | 4 ++-- .../test_typetest_model_inheritance_not_discriminated.py | 4 ++-- .../test_typetest_model_inheritance_recursive.py | 4 ++-- .../test_typetest_model_inheritance_single_discriminator.py | 4 ++-- 14 files changed, 32 insertions(+), 30 deletions(-) diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py index de17f194b6d..c8f132319c6 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py @@ -5,6 +5,7 @@ # -------------------------------------------------------------------------- import pytest from typetest.enum.fixed import aio, models +from azure.core.exceptions import HttpResponseError @pytest.fixture @@ -20,8 +21,8 @@ async def test_known_value(client): @pytest.mark.asyncio -async def test_unknown_value(client: aio.FixedClient, core_library): +async def test_unknown_value(client: aio.FixedClient): try: await client.string.put_unknown_value("Weekend") - except core_library.exceptions.HttpResponseError as err: + except HttpResponseError as err: assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py index 0d085d02002..d94fcb89846 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py @@ -5,7 +5,7 @@ # -------------------------------------------------------------------------- import pytest from typetest.enum.fixed import FixedClient, models - +from azure.core.exceptions import HttpResponseError @pytest.fixture def client(): @@ -18,8 +18,8 @@ def test_known_value(client): client.string.put_known_value(models.DaysOfWeekEnum.MONDAY) -def test_unknown_value(client: FixedClient, core_library): +def test_unknown_value(client: FixedClient): try: client.string.put_unknown_value("Weekend") - except core_library.exceptions.HttpResponseError as err: + except HttpResponseError as err: assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py index d06a0611caf..2669fbf4884 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py @@ -5,6 +5,7 @@ # -------------------------------------------------------------------------- import pytest from type.enum.fixed import aio, models +from corehttp.exceptions import HttpResponseError @pytest.fixture @@ -20,8 +21,8 @@ async def test_known_value(client): @pytest.mark.asyncio -async def test_unknown_value(client: aio.FixedClient, core_library): +async def test_unknown_value(client: aio.FixedClient): try: await client.string.put_unknown_value("Weekend") - except core_library.exceptions.HttpResponseError as err: + except HttpResponseError as err: assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py index 3f4a69cdb34..6c24c89f1f2 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.enumdiscriminator.aio import EnumDiscriminatorClient -from type.model.enumdiscriminator import models +from type.model.inheritance.enumdiscriminator.aio import EnumDiscriminatorClient +from type.model.inheritance.enumdiscriminator import models @pytest.fixture diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py index 29ebb299aaa..a308164bc15 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.nesteddiscriminator.aio import NestedDiscriminatorClient -from type.model.nesteddiscriminator.models import GoblinShark, Salmon, Fish +from type.model.inheritance.nesteddiscriminator.aio import NestedDiscriminatorClient +from type.model.inheritance.nesteddiscriminator.models import GoblinShark, Salmon, Fish @pytest.fixture diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py index 117979fe7ce..bcb16b645ca 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.notdiscriminated.aio import NotDiscriminatedClient -from type.model.notdiscriminated.models import Siamese +from type.model.inheritance.notdiscriminated.aio import NotDiscriminatedClient +from type.model.inheritance.notdiscriminated.models import Siamese @pytest.fixture diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py index de612273fa3..0f8192ac76d 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.recursive.aio import RecursiveClient -from type.model.recursive.models import Extension +from type.model.inheritance.recursive.aio import RecursiveClient +from type.model.inheritance.recursive.models import Extension @pytest.fixture diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py index 291b3b104f8..9e6767e8611 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.singlediscriminator.aio import SingleDiscriminatorClient -from type.model.singlediscriminator.models import Sparrow, Eagle, Bird, Dinosaur +from type.model.inheritance.singlediscriminator.aio import SingleDiscriminatorClient +from type.model.inheritance.singlediscriminator.models import Sparrow, Eagle, Bird, Dinosaur @pytest.fixture diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py index 8d7c3da7d82..0aa03eb4938 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py @@ -5,7 +5,7 @@ # -------------------------------------------------------------------------- import pytest from type.enum.fixed import FixedClient, models - +from corehttp.exceptions import HttpResponseError @pytest.fixture def client(): @@ -18,8 +18,8 @@ def test_known_value(client): client.string.put_known_value(models.DaysOfWeekEnum.MONDAY) -def test_unknown_value(client: FixedClient, core_library): +def test_unknown_value(client: FixedClient): try: client.string.put_unknown_value("Weekend") - except core_library.exceptions.HttpResponseError as err: + except HttpResponseError as err: assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py index 5afa5726986..837fe1b4582 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.enumdiscriminator import EnumDiscriminatorClient -from type.model.enumdiscriminator import models +from type.model.inheritance.enumdiscriminator import EnumDiscriminatorClient +from type.model.inheritance.enumdiscriminator import models @pytest.fixture diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py index 65fafc79f2a..ba74713b7a5 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.nesteddiscriminator import NestedDiscriminatorClient -from type.model.nesteddiscriminator.models import GoblinShark, Salmon, Fish +from type.model.inheritance.nesteddiscriminator import NestedDiscriminatorClient +from type.model.inheritance.nesteddiscriminator.models import GoblinShark, Salmon, Fish @pytest.fixture diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py index 958b3528fe7..2bdbce464fc 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.notdiscriminated import NotDiscriminatedClient -from type.model.notdiscriminated.models import Siamese +from type.model.inheritance.notdiscriminated import NotDiscriminatedClient +from type.model.inheritance.notdiscriminated.models import Siamese @pytest.fixture diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py index 44fec962542..f014b8d08e5 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.recursive import RecursiveClient -from type.model.recursive.models import Extension +from type.model.inheritance.recursive import RecursiveClient +from type.model.inheritance.recursive.models import Extension @pytest.fixture diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py index ddd396f383e..d81729560cb 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py @@ -4,8 +4,8 @@ # license information. # -------------------------------------------------------------------------- import pytest -from type.model.singlediscriminator import SingleDiscriminatorClient -from type.model.singlediscriminator.models import Sparrow, Eagle, Bird, Dinosaur +from type.model.inheritance.singlediscriminator import SingleDiscriminatorClient +from type.model.inheritance.singlediscriminator.models import Sparrow, Eagle, Bird, Dinosaur @pytest.fixture From 117ec4101c14db369d62a467369564f8ce6b09fd Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 17 Jan 2025 17:02:03 +0800 Subject: [PATCH 09/32] udpate test --- .../asynctests/test_typetest_array_async.py | 118 ------ .../test_typetest_dictionary_async.py | 98 ----- .../test_typetest_enum_extensible_async.py | 25 -- .../test_typetest_enum_fixed_async.py | 27 -- .../test_typetest_model_empty_async.py | 32 -- ...el_inheritance_enum_discriminator_async.py | 70 ---- ..._inheritance_nested_discriminator_async.py | 85 ----- ...del_inheritance_not_discriminated_async.py | 34 -- ...etest_model_inheritance_recursive_async.py | 34 -- ..._inheritance_single_discriminator_async.py | 67 ---- .../test_typetest_model_usage_async.py | 32 -- .../test_typetest_model_visibility_async.py | 47 --- ...est_property_additionalproperties_async.py | 352 ------------------ .../test_typetest_property_nullable_async.py | 110 ------ .../test_typetest_property_optional_async.py | 197 ---------- ...test_typetest_property_valuetypes_async.py | 315 ---------------- .../asynctests/test_typetest_scalar_async.py | 60 --- .../asynctests/test_typetest_union_async.py | 90 ----- 18 files changed, 1793 deletions(-) delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py delete mode 100644 packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py deleted file mode 100644 index 26573428b29..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py +++ /dev/null @@ -1,118 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 isodate -from typetest.array.aio import ArrayClient -from typetest.array import models - - -@pytest.fixture -async def client(): - async with ArrayClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_boolean_value(client: ArrayClient): - assert await client.boolean_value.get() == [True, False] - await client.boolean_value.put([True, False]) - - -@pytest.mark.asyncio -async def test_datetime_value(client: ArrayClient): - assert await client.datetime_value.get() == [isodate.parse_datetime("2022-08-26T18:38:00Z")] - await client.datetime_value.put([isodate.parse_datetime("2022-08-26T18:38:00Z")]) - - -@pytest.mark.asyncio -async def test_duration_value(client: ArrayClient): - assert await client.duration_value.get() == [isodate.parse_duration("P123DT22H14M12.011S")] - await client.duration_value.put([isodate.parse_duration("P123DT22H14M12.011S")]) - - -@pytest.mark.asyncio -async def test_float32_value(client: ArrayClient): - assert await client.float32_value.get() == [43.125] - await client.float32_value.put([43.125]) - - -@pytest.mark.asyncio -async def test_int32_value(client: ArrayClient): - assert await client.int32_value.get() == [1, 2] - await client.int32_value.put([1, 2]) - - -@pytest.mark.asyncio -async def test_int64_value(client: ArrayClient): - assert await client.int64_value.get() == [2**53 - 1, -(2**53 - 1)] - await client.int64_value.put([2**53 - 1, -(2**53 - 1)]) - - -@pytest.mark.asyncio -async def test_model_value(client: ArrayClient): - assert await client.model_value.get() == [ - models.InnerModel(property="hello"), - models.InnerModel(property="world"), - ] - await client.model_value.put( - [ - models.InnerModel(property="hello"), - models.InnerModel(property="world"), - ] - ) - - -@pytest.mark.asyncio -async def test_nullable_boolean_value(client: ArrayClient): - assert await client.nullable_boolean_value.get() == [True, None, False] - await client.nullable_boolean_value.put([True, None, False]) - - -@pytest.mark.asyncio -async def test_nullable_float_value(client: ArrayClient): - assert await client.nullable_float_value.get() == [1.25, None, 3.0] - await client.nullable_float_value.put([1.25, None, 3.0]) - - -@pytest.mark.asyncio -async def test_nullable_int32_value(client: ArrayClient): - assert await client.nullable_int32_value.get() == [1, None, 3] - await client.nullable_int32_value.put([1, None, 3]) - - -@pytest.mark.asyncio -async def test_nullable_model_value(client: ArrayClient): - assert await client.nullable_model_value.get() == [ - models.InnerModel(property="hello"), - None, - models.InnerModel(property="world"), - ] - await client.nullable_model_value.put( - [ - models.InnerModel(property="hello"), - None, - models.InnerModel(property="world"), - ] - ) - - -@pytest.mark.asyncio -async def test_nullable_string_value(client: ArrayClient): - assert await client.nullable_string_value.get() == ["hello", None, "world"] - await client.nullable_string_value.put(["hello", None, "world"]) - - -@pytest.mark.asyncio -async def test_string_value(client: ArrayClient): - assert await client.string_value.get() == ["hello", ""] - await client.string_value.put(["hello", ""]) - - -@pytest.mark.asyncio -async def test_unknown_value(client: ArrayClient): - assert await client.unknown_value.get() == [1, "hello", None] - await client.unknown_value.put([1, "hello", None]) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py deleted file mode 100644 index 364868b2357..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py +++ /dev/null @@ -1,98 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.dictionary import models -from typetest.dictionary.aio import DictionaryClient -import isodate - - -@pytest.fixture -async def client(): - async with DictionaryClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_boolean_value(client: DictionaryClient): - value = {"k1": True, "k2": False} - assert await client.boolean_value.get() == value - await client.boolean_value.put(value) - - -@pytest.mark.asyncio -async def test_datetime_value(client: DictionaryClient): - value = {"k1": isodate.parse_datetime("2022-08-26T18:38:00Z")} - assert await client.datetime_value.get() == value - await client.datetime_value.put(value) - - -@pytest.mark.asyncio -async def test_duration_value(client: DictionaryClient): - value = {"k1": isodate.parse_duration("P123DT22H14M12.011S")} - assert await client.duration_value.get() == value - await client.duration_value.put(value) - - -@pytest.mark.asyncio -async def test_float32_value(client: DictionaryClient): - value = {"k1": 43.125} - assert await client.float32_value.get() == value - await client.float32_value.put(value) - - -@pytest.mark.asyncio -async def test_int32_value(client: DictionaryClient): - value = {"k1": 1, "k2": 2} - assert await client.int32_value.get() == value - await client.int32_value.put(value) - - -@pytest.mark.asyncio -async def test_int64_value(client: DictionaryClient): - value = {"k1": 2**53 - 1, "k2": -(2**53 - 1)} - assert await client.int64_value.get() == value - await client.int64_value.put(value) - - -@pytest.mark.asyncio -async def test_model_value(client: DictionaryClient): - value = { - "k1": models.InnerModel(property="hello"), - "k2": models.InnerModel(property="world"), - } - assert await client.model_value.get() == value - await client.model_value.put(value) - - -@pytest.mark.asyncio -async def test_nullable_float_value(client: DictionaryClient): - value = {"k1": 1.25, "k2": 0.5, "k3": None} - assert await client.nullable_float_value.get() == value - await client.nullable_float_value.put(value) - - -@pytest.mark.asyncio -async def test_recursive_model_value(client: DictionaryClient): - value = { - "k1": models.InnerModel(property="hello", children={}), - "k2": models.InnerModel(property="world", children={"k2.1": models.InnerModel(property="inner world")}), - } - assert await client.recursive_model_value.get() == value - await client.recursive_model_value.put(value) - - -@pytest.mark.asyncio -async def test_string_value(client: DictionaryClient): - value = {"k1": "hello", "k2": ""} - assert await client.string_value.get() == value - await client.string_value.put(value) - - -@pytest.mark.asyncio -async def test_unknown_value(client: DictionaryClient): - value = {"k1": 1, "k2": "hello", "k3": None} - assert await client.unknown_value.get() == value - await client.unknown_value.put(value) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py deleted file mode 100644 index 75fca822ddb..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py +++ /dev/null @@ -1,25 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.enum.extensible import models, aio - - -@pytest.fixture -async def client(): - async with aio.ExtensibleClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_known_value(client): - assert await client.string.get_known_value() == models.DaysOfWeekExtensibleEnum.MONDAY - await client.string.put_known_value(models.DaysOfWeekExtensibleEnum.MONDAY) - - -@pytest.mark.asyncio -async def test_unknown_value(client): - assert await client.string.get_unknown_value() == "Weekend" - await client.string.put_unknown_value("Weekend") diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py deleted file mode 100644 index de17f194b6d..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py +++ /dev/null @@ -1,27 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.enum.fixed import aio, models - - -@pytest.fixture -async def client(): - async with aio.FixedClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_known_value(client): - assert await client.string.get_known_value() == models.DaysOfWeekEnum.MONDAY - await client.string.put_known_value(models.DaysOfWeekEnum.MONDAY) - - -@pytest.mark.asyncio -async def test_unknown_value(client: aio.FixedClient, core_library): - try: - await client.string.put_unknown_value("Weekend") - except core_library.exceptions.HttpResponseError as err: - assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py deleted file mode 100644 index b5518c5e901..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py +++ /dev/null @@ -1,32 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.model.empty.aio import EmptyClient -from typetest.model.empty.models import EmptyInput, EmptyOutput, EmptyInputOutput - - -@pytest.fixture -async def client(): - async with EmptyClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_put(client: EmptyClient): - await client.put_empty(EmptyInput()) - await client.put_empty({}) - - -@pytest.mark.asyncio -async def test_get(client: EmptyClient): - assert await client.get_empty() == EmptyOutput() - assert await client.get_empty() == {} - - -@pytest.mark.asyncio -async def test_post_round(client: EmptyClient): - assert await client.post_round_trip_empty(EmptyInputOutput()) == EmptyInputOutput() - assert await client.post_round_trip_empty({}) == {} diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py deleted file mode 100644 index 0a72d5465e3..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py +++ /dev/null @@ -1,70 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.model.enumdiscriminator.aio import EnumDiscriminatorClient -from typetest.model.enumdiscriminator import models - - -@pytest.fixture -async def client(): - async with EnumDiscriminatorClient() as client: - yield client - - -@pytest.fixture -def valid_body(): - return models.Golden(weight=10) - - -@pytest.fixture -def valid_fixed_body(): - return models.Cobra(length=10) - - -@pytest.mark.asyncio -async def test_get_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): - assert await client.get_extensible_model() == valid_body - assert isinstance(await client.get_extensible_model(), models.Golden) - - -@pytest.mark.asyncio -async def test_put_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): - await client.put_extensible_model(valid_body) - - -@pytest.mark.asyncio -async def test_get_extensible_model_missing_discriminator( - client: EnumDiscriminatorClient, -): - assert await client.get_extensible_model_missing_discriminator() == models.Dog(weight=10) - - -@pytest.mark.asyncio -async def test_get_extensible_model_wrong_discriminator( - client: EnumDiscriminatorClient, -): - assert await client.get_extensible_model_wrong_discriminator() == models.Dog(weight=8, kind="wrongKind") - - -@pytest.mark.asyncio -async def test_get_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): - assert await client.get_fixed_model() == valid_fixed_body - assert isinstance(await client.get_fixed_model(), models.Cobra) - - -@pytest.mark.asyncio -async def test_put_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): - await client.put_fixed_model(valid_fixed_body) - - -@pytest.mark.asyncio -async def test_get_fixed_model_missing_discriminator(client: EnumDiscriminatorClient): - assert await client.get_fixed_model_missing_discriminator() == models.Snake(length=10) - - -@pytest.mark.asyncio -async def test_get_fixed_model_wrong_discriminator(client: EnumDiscriminatorClient): - assert await client.get_fixed_model_wrong_discriminator() == models.Snake(length=8, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py deleted file mode 100644 index c641f25eb88..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py +++ /dev/null @@ -1,85 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.model.nesteddiscriminator.aio import NestedDiscriminatorClient -from typetest.model.nesteddiscriminator.models import GoblinShark, Salmon, Fish - - -@pytest.fixture -async def client(): - async with NestedDiscriminatorClient() as client: - yield client - - -@pytest.fixture -async def valid_body(): - return GoblinShark(age=1) - - -@pytest.mark.asyncio -async def test_get_model(client, valid_body): - assert await client.get_model() == valid_body - assert isinstance(await client.get_model(), GoblinShark) - - -@pytest.mark.asyncio -async def test_put_model(client, valid_body): - await client.put_model(valid_body) - - -@pytest.fixture -async def valid_recursive_body(): - return Salmon( - { - "age": 1, - "kind": "salmon", - "partner": {"age": 2, "kind": "shark", "sharktype": "saw"}, - "friends": [ - { - "age": 2, - "kind": "salmon", - "partner": {"age": 3, "kind": "salmon"}, - "hate": { - "key1": {"age": 4, "kind": "salmon"}, - "key2": {"age": 2, "kind": "shark", "sharktype": "goblin"}, - }, - }, - {"age": 3, "kind": "shark", "sharktype": "goblin"}, - ], - "hate": { - "key3": {"age": 3, "kind": "shark", "sharktype": "saw"}, - "key4": { - "age": 2, - "kind": "salmon", - "friends": [ - {"age": 1, "kind": "salmon"}, - {"age": 4, "kind": "shark", "sharktype": "goblin"}, - ], - }, - }, - } - ) - - -@pytest.mark.asyncio -async def test_get_recursive_model(client, valid_recursive_body): - assert valid_recursive_body == await client.get_recursive_model() - assert isinstance(await client.get_recursive_model(), Salmon) - - -@pytest.mark.asyncio -async def test_put_recursive_model(client, valid_recursive_body): - await client.put_recursive_model(valid_recursive_body) - - -@pytest.mark.asyncio -async def test_get_missing_discriminator(client): - assert await client.get_missing_discriminator() == Fish(age=1) - - -@pytest.mark.asyncio -async def test_get_wrong_discriminator(client): - assert await client.get_wrong_discriminator() == Fish(age=1, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py deleted file mode 100644 index 7e7ce096956..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py +++ /dev/null @@ -1,34 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.model.notdiscriminated.aio import NotDiscriminatedClient -from typetest.model.notdiscriminated.models import Siamese - - -@pytest.fixture -async def client(): - async with NotDiscriminatedClient() as client: - yield client - - -@pytest.fixture -async def valid_body(): - return Siamese(name="abc", age=32, smart=True) - - -@pytest.mark.asyncio -async def test_get_valid(client, valid_body): - assert await client.get_valid() == valid_body - - -@pytest.mark.asyncio -async def test_post_valid(client, valid_body): - await client.post_valid(valid_body) - - -@pytest.mark.asyncio -async def test_put_valid(client, valid_body): - assert valid_body == await client.put_valid(valid_body) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py deleted file mode 100644 index aea6f1bb9e3..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py +++ /dev/null @@ -1,34 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.model.recursive.aio import RecursiveClient -from typetest.model.recursive.models import Extension - - -@pytest.fixture -async def client(): - async with RecursiveClient() as client: - yield client - - -@pytest.fixture -async def expected(): - return Extension( - { - "level": 0, - "extension": [{"level": 1, "extension": [{"level": 2}]}, {"level": 1}], - } - ) - - -@pytest.mark.asyncio -async def test_put(client: RecursiveClient, expected: Extension): - await client.put(expected) - - -@pytest.mark.asyncio -async def test_get(client: RecursiveClient, expected: Extension): - assert await client.get() == expected diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py deleted file mode 100644 index dc98cd81c9b..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py +++ /dev/null @@ -1,67 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.model.singlediscriminator.aio import SingleDiscriminatorClient -from typetest.model.singlediscriminator.models import Sparrow, Eagle, Bird, Dinosaur - - -@pytest.fixture -async def client(): - async with SingleDiscriminatorClient() as client: - yield client - - -@pytest.fixture -async def valid_body(): - return Sparrow(wingspan=1) - - -@pytest.mark.asyncio -async def test_get_model(client, valid_body): - assert await client.get_model() == valid_body - - -@pytest.mark.asyncio -async def test_put_model(client, valid_body): - await client.put_model(valid_body) - - -@pytest.fixture -async def recursive_body(): - return Eagle( - { - "wingspan": 5, - "kind": "eagle", - "partner": {"wingspan": 2, "kind": "goose"}, - "friends": [{"wingspan": 2, "kind": "seagull"}], - "hate": {"key3": {"wingspan": 1, "kind": "sparrow"}}, - } - ) - - -@pytest.mark.asyncio -async def test_get_recursive_model(client, recursive_body): - assert await client.get_recursive_model() == recursive_body - - -@pytest.mark.asyncio -async def test_put_recursive_model(client, recursive_body): - await client.put_recursive_model(recursive_body) - - -@pytest.mark.asyncio -async def test_get_missing_discriminator(client): - assert await client.get_missing_discriminator() == Bird(wingspan=1) - - -@pytest.mark.asyncio -async def test_get_wrong_discriminator(client): - assert await client.get_wrong_discriminator() == Bird(wingspan=1, kind="wrongKind") - - -@pytest.mark.asyncio -async def test_get_legacy_model(client): - assert await client.get_legacy_model() == Dinosaur(size=20, kind="t-rex") diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py deleted file mode 100644 index bcebeaec205..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py +++ /dev/null @@ -1,32 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.model.usage import models -from typetest.model.usage.aio import UsageClient - - -@pytest.fixture -async def client(): - async with UsageClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_input(client: UsageClient): - input = models.InputRecord(required_prop="example-value") - assert await client.input(input) is None - - -@pytest.mark.asyncio -async def test_output(client: UsageClient): - output = models.OutputRecord(required_prop="example-value") - assert output == await client.output() - - -@pytest.mark.asyncio -async def test_input_and_output(client: UsageClient): - input_output = models.InputOutputRecord(required_prop="example-value") - assert input_output == await client.input_and_output(input_output) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py deleted file mode 100644 index e73d7f3030d..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py +++ /dev/null @@ -1,47 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.model.visibility.aio import VisibilityClient -from typetest.model.visibility import models - - -@pytest.fixture -async def client(): - async with VisibilityClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_get_model(client): - result = await client.get_model(models.VisibilityModel(query_prop=123)) - assert result == models.VisibilityModel(read_prop="abc") - - -@pytest.mark.asyncio -async def test_put_model(client): - await client.put_model(models.VisibilityModel(create_prop=["foo", "bar"], update_prop=[1, 2])) - - -@pytest.mark.asyncio -async def test_patch_model(client): - await client.patch_model(models.VisibilityModel(update_prop=[1, 2])) - - -@pytest.mark.asyncio -async def test_post_model(client): - await client.post_model(models.VisibilityModel(create_prop=["foo", "bar"])) - - -@pytest.mark.asyncio -async def test_delete_model(client): - await client.delete_model(models.VisibilityModel(delete_prop=True)) - - -@pytest.mark.asyncio -async def test_put_read_only_model(client): - await client.put_read_only_model( - models.ReadOnlyModel(optional_nullable_int_list=[1, 2], optional_string_record={"foo", "bar"}) - ) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py deleted file mode 100644 index bd773f6a474..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py +++ /dev/null @@ -1,352 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.property.additionalproperties import models -from typetest.property.additionalproperties.aio import AdditionalPropertiesClient - - -@pytest.fixture -async def client(): - async with AdditionalPropertiesClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_extends_different_spread_float(client: AdditionalPropertiesClient): - body = models.DifferentSpreadFloatDerived({"name": "abc", "prop": 43.125, "derivedProp": 43.125}) - assert await client.extends_different_spread_float.get() == body - await client.extends_different_spread_float.put(body) - - -@pytest.mark.asyncio -async def test_extends_different_spread_model(client: AdditionalPropertiesClient): - body = models.DifferentSpreadModelDerived( - {"knownProp": "abc", "prop": {"state": "ok"}, "derivedProp": {"state": "ok"}} - ) - assert await client.extends_different_spread_model.get() == body - await client.extends_different_spread_model.put(body) - - -@pytest.mark.asyncio -async def test_extends_different_spread_model_array(client: AdditionalPropertiesClient): - body = models.DifferentSpreadModelArrayDerived( - { - "knownProp": "abc", - "prop": [{"state": "ok"}, {"state": "ok"}], - "derivedProp": [{"state": "ok"}, {"state": "ok"}], - } - ) - assert await client.extends_different_spread_model_array.get() == body - await client.extends_different_spread_model_array.put(body) - - -@pytest.mark.asyncio -async def test_extends_different_spread_string(client: AdditionalPropertiesClient): - body = models.DifferentSpreadStringDerived({"id": 43.125, "prop": "abc", "derivedProp": "abc"}) - assert await client.extends_different_spread_string.get() == body - await client.extends_different_spread_string.put(body) - - -@pytest.mark.asyncio -async def test_extends_float(client: AdditionalPropertiesClient): - body = models.ExtendsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) - assert await client.extends_float.get() == body - await client.extends_float.put(body) - - -@pytest.mark.asyncio -async def test_extends_model(client: AdditionalPropertiesClient): - body = models.ExtendsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) - assert await client.extends_model.get() == body - await client.extends_model.put(body) - - -@pytest.mark.asyncio -async def test_extends_model_array(client: AdditionalPropertiesClient): - body = models.ExtendsModelArrayAdditionalProperties( - { - "knownProp": [{"state": "ok"}, {"state": "ok"}], - "prop": [{"state": "ok"}, {"state": "ok"}], - } - ) - assert await client.extends_model_array.get() == body - await client.extends_model_array.put(body) - - -@pytest.mark.asyncio -async def test_extends_string(client: AdditionalPropertiesClient): - body = models.ExtendsStringAdditionalProperties({"name": "ExtendsStringAdditionalProperties", "prop": "abc"}) - assert await client.extends_string.get() == body - await client.extends_string.put(body) - - -@pytest.mark.asyncio -async def test_extends_unknown(client: AdditionalPropertiesClient): - body = models.ExtendsUnknownAdditionalProperties( - { - "name": "ExtendsUnknownAdditionalProperties", - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.extends_unknown.get() == body - await client.extends_unknown.put(body) - - -@pytest.mark.asyncio -async def test_extends_unknown_derived(client: AdditionalPropertiesClient): - body = models.ExtendsUnknownAdditionalPropertiesDerived( - { - "name": "ExtendsUnknownAdditionalProperties", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.extends_unknown_derived.get() == body - await client.extends_unknown_derived.put(body) - - -@pytest.mark.asyncio -async def test_extends_unknown_discriminated(client: AdditionalPropertiesClient): - body = models.ExtendsUnknownAdditionalPropertiesDiscriminatedDerived( - { - "kind": "derived", - "name": "Derived", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.extends_unknown_discriminated.get() == body - await client.extends_unknown_discriminated.put(body) - - -@pytest.mark.asyncio -async def test_is_float(client: AdditionalPropertiesClient): - body = models.IsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) - assert await client.is_float.get() == body - await client.is_float.put(body) - - -@pytest.mark.asyncio -async def test_is_model(client: AdditionalPropertiesClient): - body = models.IsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) - assert await client.is_model.get() == body - await client.is_model.put(body) - - -@pytest.mark.asyncio -async def test_is_model_array(client: AdditionalPropertiesClient): - body = models.IsModelArrayAdditionalProperties( - { - "knownProp": [{"state": "ok"}, {"state": "ok"}], - "prop": [{"state": "ok"}, {"state": "ok"}], - } - ) - assert await client.is_model_array.get() == body - await client.is_model_array.put(body) - - -@pytest.mark.asyncio -async def test_is_string(client: AdditionalPropertiesClient): - body = models.IsStringAdditionalProperties({"name": "IsStringAdditionalProperties", "prop": "abc"}) - assert await client.is_string.get() == body - await client.is_string.put(body) - - -@pytest.mark.asyncio -async def test_is_unknown(client: AdditionalPropertiesClient): - body = models.IsUnknownAdditionalProperties( - { - "name": "IsUnknownAdditionalProperties", - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.is_unknown.get() == body - await client.is_unknown.put(body) - - -@pytest.mark.asyncio -async def test_is_unknown_derived(client: AdditionalPropertiesClient): - body = models.IsUnknownAdditionalPropertiesDerived( - { - "name": "IsUnknownAdditionalProperties", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.is_unknown_derived.get() == body - await client.is_unknown_derived.put(body) - - -@pytest.mark.asyncio -async def test_is_unknown_discriminated(client: AdditionalPropertiesClient): - body = models.IsUnknownAdditionalPropertiesDiscriminatedDerived( - { - "kind": "derived", - "name": "Derived", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.is_unknown_discriminated.get() == body - await client.is_unknown_discriminated.put(body) - - -@pytest.mark.asyncio -async def test_multiple_spread(client: AdditionalPropertiesClient): - body = {"flag": True, "prop1": "abc", "prop2": 43.125} - assert await client.multiple_spread.get() == body - await client.multiple_spread.put(body) - - -@pytest.mark.asyncio -async def test_spread_different_float(client: AdditionalPropertiesClient): - body = {"name": "abc", "prop": 43.125} - assert await client.spread_different_float.get() == body - await client.spread_different_float.put(body) - - -@pytest.mark.asyncio -async def test_spread_different_model(client: AdditionalPropertiesClient): - body = {"knownProp": "abc", "prop": {"state": "ok"}} - assert await client.spread_different_model.get() == body - await client.spread_different_model.put(body) - - -@pytest.mark.asyncio -async def test_spread_different_model_array(client: AdditionalPropertiesClient): - body = {"knownProp": "abc", "prop": [{"state": "ok"}, {"state": "ok"}]} - assert await client.spread_different_model_array.get() == body - await client.spread_different_model_array.put(body) - - -@pytest.mark.asyncio -async def test_spread_different_string(client: AdditionalPropertiesClient): - body = {"id": 43.125, "prop": "abc"} - assert await client.spread_different_string.get() == body - await client.spread_different_string.put(body) - - -@pytest.mark.asyncio -async def test_spread_model(client: AdditionalPropertiesClient): - body = {"knownProp": {"state": "ok"}, "prop": {"state": "ok"}} - assert await client.spread_model.get() == body - await client.spread_model.put(body) - - -@pytest.mark.asyncio -async def test_spread_model_array(client: AdditionalPropertiesClient): - body = { - "knownProp": [{"state": "ok"}, {"state": "ok"}], - "prop": [{"state": "ok"}, {"state": "ok"}], - } - assert await client.spread_model_array.get() == body - await client.spread_model_array.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_discriminated_union(client: AdditionalPropertiesClient): - body = { - "name": "abc", - "prop1": {"fooProp": "abc", "kind": "kind0"}, - "prop2": { - "end": "2021-01-02T00:00:00Z", - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - }, - } - assert await client.spread_record_discriminated_union.get() == body - await client.spread_record_discriminated_union.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_non_discriminated_union( - client: AdditionalPropertiesClient, -): - body = { - "name": "abc", - "prop1": {"kind": "kind0", "fooProp": "abc"}, - "prop2": { - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - "end": "2021-01-02T00:00:00Z", - }, - } - assert await client.spread_record_non_discriminated_union.get() == body - await client.spread_record_non_discriminated_union.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_non_discriminated_union2( - client: AdditionalPropertiesClient, -): - body = { - "name": "abc", - "prop1": {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, - "prop2": { - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - "end": "2021-01-02T00:00:00Z", - }, - } - assert await client.spread_record_non_discriminated_union2.get() == body - await client.spread_record_non_discriminated_union2.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_non_discriminated_union3( - client: AdditionalPropertiesClient, -): - body = { - "name": "abc", - "prop1": [ - {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, - {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, - ], - "prop2": { - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - "end": "2021-01-02T00:00:00Z", - }, - } - assert await client.spread_record_non_discriminated_union3.get() == body - await client.spread_record_non_discriminated_union3.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_union(client: AdditionalPropertiesClient): - body = {"flag": True, "prop1": "abc", "prop2": 43.125} - assert await client.spread_record_union.get() == body - await client.spread_record_union.put(body) - - -@pytest.mark.asyncio -async def test_spread_string(client: AdditionalPropertiesClient): - body = {"name": "SpreadSpringRecord", "prop": "abc"} - assert await client.spread_string.get() == body - await client.spread_string.put(body) - - -@pytest.mark.asyncio -async def test_spread_float(client: AdditionalPropertiesClient): - body = {"id": 43.125, "prop": 43.125} - assert await client.spread_float.get() == body - await client.spread_float.put(body) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py deleted file mode 100644 index 77c6aed8b4a..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py +++ /dev/null @@ -1,110 +0,0 @@ -# cspell: ignore Hdvcmxk -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import json -import pytest -from typetest.property.nullable import models -from typetest.property.nullable.aio import NullableClient -from typetest.property.nullable._model_base import ( # pylint: disable=protected-access - SdkJSONEncoder, -) - -try: - from corehttp.serialization import NULL -except ImportError: - from azure.core.serialization import NULL - - -@pytest.fixture -async def client(): - async with NullableClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_bytes(client: NullableClient): - non_null_model = models.BytesProperty(required_property="foo", nullable_property="aGVsbG8sIHdvcmxkIQ==") - non_model = models.BytesProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.bytes.get_non_null() == non_null_model - assert (await client.bytes.get_null())["nullableProperty"] is None - await client.bytes.patch_non_null(body=non_null_model) - await client.bytes.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_collections_byte(client: NullableClient): - non_null_model = models.CollectionsByteProperty( - required_property="foo", - nullable_property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="], - ) - non_model = models.CollectionsByteProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.collections_byte.get_non_null() == non_null_model - assert (await client.collections_byte.get_null())["nullableProperty"] is None - await client.collections_byte.patch_non_null(body=non_null_model) - await client.collections_byte.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_collections_model(client: NullableClient): - non_null_model = models.CollectionsModelProperty( - required_property="foo", - nullable_property=[ - models.InnerModel(property="hello"), - models.InnerModel(property="world"), - ], - ) - non_model = models.CollectionsModelProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.collections_model.get_non_null() == non_null_model - assert (await client.collections_model.get_null())["nullableProperty"] is None - await client.collections_model.patch_non_null(body=non_null_model) - await client.collections_model.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_collections_string(client: NullableClient): - non_null_model = models.CollectionsStringProperty(required_property="foo", nullable_property=["hello", "world"]) - non_model = models.CollectionsStringProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.collections_string.get_non_null() == non_null_model - assert (await client.collections_string.get_null())["nullableProperty"] is None - await client.collections_string.patch_non_null(body=non_null_model) - await client.collections_string.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_datetime(client: NullableClient): - non_null_model = models.DatetimeProperty(required_property="foo", nullable_property="2022-08-26T18:38:00Z") - non_model = models.DatetimeProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.datetime.get_non_null() == non_null_model - assert (await client.datetime.get_null())["nullableProperty"] is None - await client.datetime.patch_non_null(body=non_null_model) - await client.datetime.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_duration(client: NullableClient): - non_null_model = models.DurationProperty(required_property="foo", nullable_property="P123DT22H14M12.011S") - non_model = models.DurationProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.duration.get_non_null() == non_null_model - assert (await client.duration.get_null())["nullableProperty"] is None - await client.duration.patch_non_null(body=non_null_model) - await client.duration.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_string(client: NullableClient): - non_null_model = models.StringProperty(required_property="foo", nullable_property="hello") - non_model = models.StringProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.string.get_non_null() == non_null_model - assert (await client.string.get_null())["nullableProperty"] is None - await client.string.patch_non_null(body=non_null_model) - await client.string.patch_null(body=non_model) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py deleted file mode 100644 index e7ec09d0059..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py +++ /dev/null @@ -1,197 +0,0 @@ -# cspell: ignore Hdvcmxk -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import Any -import pytest -from typetest.property.optional import models -from typetest.property.optional.aio import OptionalClient - - -@pytest.fixture -async def client(): - async with OptionalClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_boolean_literal(client): - body = models.BooleanLiteralProperty(property=True) - assert await client.boolean_literal.get_all() == body - assert await client.boolean_literal.get_default() == models.BooleanLiteralProperty() - await client.boolean_literal.put_all(body) - await client.boolean_literal.put_default(models.BooleanLiteralProperty()) - - -@pytest.mark.asyncio -async def test_bytes(client): - body = models.BytesProperty(property="aGVsbG8sIHdvcmxkIQ==") - assert await client.bytes.get_all() == body - assert await client.bytes.get_default() == models.BytesProperty() - await client.bytes.put_all(body) - await client.bytes.put_default(models.BytesProperty()) - - -@pytest.mark.asyncio -async def test_collections_byte(client): - body = models.CollectionsByteProperty(property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="]) - assert await client.collections_byte.get_all() == body - assert await client.collections_byte.get_default() == models.CollectionsByteProperty() - await client.collections_byte.put_all(body) - await client.collections_byte.put_default(models.CollectionsByteProperty()) - - -@pytest.mark.asyncio -async def test_collections_model(client): - body = models.CollectionsModelProperty( - property=[ - models.StringProperty(property="hello"), - models.StringProperty(property="world"), - ] - ) - assert await client.collections_model.get_all() == body - assert await client.collections_model.get_default() == models.CollectionsModelProperty() - await client.collections_model.put_all(body) - await client.collections_model.put_default(models.CollectionsModelProperty()) - - -@pytest.mark.asyncio -async def test_datetime(client): - body = models.DatetimeProperty(property="2022-08-26T18:38:00Z") - assert await client.datetime.get_all() == body - assert await client.datetime.get_default() == models.DatetimeProperty() - await client.datetime.put_all(body) - await client.datetime.put_default(models.DatetimeProperty()) - - -@pytest.mark.asyncio -async def test_duration(client): - body = models.DurationProperty(property="P123DT22H14M12.011S") - assert await client.duration.get_all() == body - assert await client.duration.get_default() == models.DurationProperty() - await client.duration.put_all(body) - await client.duration.put_default(models.DurationProperty()) - - -@pytest.mark.asyncio -async def test_float_literal(client): - body = models.FloatLiteralProperty(property=1.25) - assert await client.float_literal.get_all() == body - assert await client.float_literal.get_default() == models.FloatLiteralProperty() - await client.float_literal.put_all(body) - await client.float_literal.put_default(models.FloatLiteralProperty()) - - -@pytest.mark.asyncio -async def test_int_literal(client): - body = models.IntLiteralProperty(property=1) - assert await client.int_literal.get_all() == body - assert await client.int_literal.get_default() == models.IntLiteralProperty() - await client.int_literal.put_all(body) - await client.int_literal.put_default(models.IntLiteralProperty()) - - -@pytest.mark.asyncio -async def test_plaindate(client): - body = models.PlainDateProperty(property="2022-12-12") - assert await client.plain_date.get_all() == body - - -@pytest.mark.asyncio -async def test_plaindate(client): - assert await client.plain_date.get_default() == models.PlainDateProperty() - - -@pytest.mark.asyncio -async def test_plaindate(client): - body = models.PlainDateProperty(property="2022-12-12") - await client.plain_date.put_all(body) - - -@pytest.mark.asyncio -async def test_plaindate(client): - await client.plain_date.put_default(models.PlainDateProperty()) - - -@pytest.mark.asyncio -async def test_plaintime(client): - body = models.PlainTimeProperty(property="13:06:12") - assert await client.plain_time.get_all() == body - - -@pytest.mark.asyncio -async def test_plaintime(client): - assert await client.plain_time.get_default() == models.PlainTimeProperty() - - -@pytest.mark.asyncio -async def test_plaintime(client): - body = models.PlainTimeProperty(property="13:06:12") - await client.plain_time.put_all(body) - - -@pytest.mark.asyncio -async def test_plaintime(client): - await client.plain_time.put_default(models.PlainTimeProperty()) - - -@pytest.mark.asyncio -async def test_required_and_optional(client): - all_body = { - "optionalProperty": "hello", - "requiredProperty": 42, - } - required_only_body = { - "requiredProperty": 42, - } - assert await client.required_and_optional.get_all() == all_body - assert await client.required_and_optional.get_required_only() == required_only_body - await client.required_and_optional.put_all(all_body) - await client.required_and_optional.put_required_only(required_only_body) - - -@pytest.mark.asyncio -async def test_string(client): - body = models.StringProperty(property="hello") - assert await client.string.get_all() == body - assert await client.string.get_default() == models.StringProperty() - await client.string.put_all(body) - await client.string.put_default(models.StringProperty()) - - -@pytest.mark.asyncio -async def test_string_literal(client): - body = models.StringLiteralProperty(property="hello") - assert await client.string_literal.get_all() == body - assert await client.string_literal.get_default() == models.StringLiteralProperty() - await client.string_literal.put_all(body) - await client.string_literal.put_default(models.StringLiteralProperty()) - - -@pytest.mark.asyncio -async def test_union_float_literal(client): - body = models.UnionFloatLiteralProperty(property=2.375) - assert await client.union_float_literal.get_all() == body - assert await client.union_float_literal.get_default() == models.UnionFloatLiteralProperty() - await client.union_float_literal.put_all(body) - await client.union_float_literal.put_default(models.UnionFloatLiteralProperty()) - - -@pytest.mark.asyncio -async def test_union_int_literal(client): - body = models.UnionIntLiteralProperty(property=2) - assert await client.union_int_literal.get_all() == body - assert await client.union_int_literal.get_default() == models.UnionIntLiteralProperty() - await client.union_int_literal.put_all(body) - await client.union_int_literal.put_default(models.UnionIntLiteralProperty()) - - -@pytest.mark.asyncio -async def test_union_string_literal(client): - body = models.UnionStringLiteralProperty(property="world") - assert await client.union_string_literal.get_all() == body - assert await client.union_string_literal.get_default() == models.UnionStringLiteralProperty() - await client.union_string_literal.put_all(body) - await client.union_string_literal.put_default(models.UnionStringLiteralProperty()) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py deleted file mode 100644 index 1b7566c5739..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py +++ /dev/null @@ -1,315 +0,0 @@ -# cspell: ignore Hdvcmxk -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import decimal - -import pytest -import datetime -from typetest.property.valuetypes import models -from typetest.property.valuetypes.aio import ValueTypesClient - - -@pytest.fixture -async def client(): - async with ValueTypesClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_boolean(client: ValueTypesClient): - body = models.BooleanProperty(property=True) - assert body.property == body["property"] - await client.boolean.put(body) - - resp = await client.boolean.get() - assert resp.property == resp["property"] == True - - -@pytest.mark.asyncio -async def test_boolean_literal(client: ValueTypesClient): - body = models.BooleanLiteralProperty(property=True) - assert body.property == body["property"] - await client.boolean_literal.put(body) - - resp = await client.boolean_literal.get() - assert resp.property == resp["property"] == True - - -@pytest.mark.asyncio -async def test_bytes(client: ValueTypesClient): - body = models.BytesProperty(property=b"hello, world!") - assert body.property == b"hello, world!" - assert body["property"] == "aGVsbG8sIHdvcmxkIQ==" - await client.bytes.put(body) - - resp = await client.bytes.get() - assert resp.property == b"hello, world!" - assert resp["property"] == "aGVsbG8sIHdvcmxkIQ==" - - -@pytest.mark.asyncio -async def test_collections_int(client: ValueTypesClient): - body = models.CollectionsIntProperty(property=[1, 2]) - assert body.property == body["property"] - await client.collections_int.put(body) - - resp = await client.collections_int.get() - assert resp.property == resp["property"] == [1, 2] - - -@pytest.mark.asyncio -async def test_collections_model(client: ValueTypesClient): - body = models.CollectionsModelProperty(property=[{"property": "hello"}, {"property": "world"}]) - assert body.property[0].property == body["property"][0]["property"] - await client.collections_model.put(body) - - resp = await client.collections_model.get() - assert resp.property[1].property == resp["property"][1]["property"] - - -@pytest.mark.asyncio -async def test_collections_string(client: ValueTypesClient): - body = models.CollectionsStringProperty(property=["hello", "world"]) - assert body.property == body["property"] - await client.collections_string.put(body) - - resp = await client.collections_string.get() - assert resp.property == resp["property"] == ["hello", "world"] - - -@pytest.mark.asyncio -async def test_datetime(client): - received_body = await client.datetime.get() - assert received_body == {"property": "2022-08-26T18:38:00Z"} - assert received_body.property.year == 2022 - assert received_body.property.month == 8 - assert received_body.property.day == 26 - assert received_body.property.hour == 18 - assert received_body.property.minute == 38 - - await client.datetime.put(models.DatetimeProperty(property=datetime.datetime(2022, 8, 26, hour=18, minute=38))) - - -@pytest.mark.asyncio -async def test_decimal(client: ValueTypesClient): - body = models.DecimalProperty(property=decimal.Decimal("0.33333")) - assert body.property == decimal.Decimal("0.33333") - assert body["property"] == 0.33333 - await client.decimal.put(body) - - resp = await client.decimal.get() - assert resp.property == decimal.Decimal("0.33333") - assert resp["property"] == 0.33333 - - -@pytest.mark.asyncio -async def test_decimal128(client: ValueTypesClient): - body = models.Decimal128Property(property=decimal.Decimal("0.33333")) - assert body.property == decimal.Decimal("0.33333") - assert body["property"] == 0.33333 - await client.decimal128.put(body) - - resp = await client.decimal128.get() - assert resp.property == decimal.Decimal("0.33333") - assert resp["property"] == 0.33333 - - -@pytest.mark.asyncio -async def test_dictionary_string(client: ValueTypesClient): - body = models.DictionaryStringProperty(property={"k1": "hello", "k2": "world"}) - assert body.property == body["property"] - await client.dictionary_string.put(body) - - resp = await client.dictionary_string.get() - assert resp.property == resp["property"] == {"k1": "hello", "k2": "world"} - - -@pytest.mark.asyncio -async def test_duration(client: ValueTypesClient): - body = models.DurationProperty(property="P123DT22H14M12.011S") - assert body.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) - assert body["property"] == "P123DT22H14M12.011S" - await client.duration.put(body) - - resp = await client.duration.get() - assert resp.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) - assert resp["property"] == "P123DT22H14M12.011S" - - -@pytest.mark.asyncio -async def test_enum(client: ValueTypesClient): - body = models.EnumProperty(property=models.InnerEnum.VALUE_ONE) - assert body.property == body["property"] - await client.enum.put(body) - - resp = await client.enum.get() - assert resp.property == resp["property"] == "ValueOne" - - -@pytest.mark.asyncio -async def test_extensible_enum(client: ValueTypesClient): - body = models.ExtensibleEnumProperty(property="UnknownValue") - assert body.property == body["property"] - await client.extensible_enum.put(body) - - resp = await client.extensible_enum.get() - assert resp.property == resp["property"] == "UnknownValue" - - -@pytest.mark.asyncio -async def test_float(client: ValueTypesClient): - body = models.FloatProperty(property=43.125) - assert body.property == body["property"] - await client.float.put(body) - - resp = await client.float.get() - assert resp.property == resp["property"] == 43.125 - - -@pytest.mark.asyncio -async def test_float_literal(client: ValueTypesClient): - body = models.FloatLiteralProperty(property=43.125) - assert body.property == body["property"] - await client.float_literal.put(body) - - resp = await client.float_literal.get() - assert resp.property == resp["property"] == 43.125 - - -@pytest.mark.asyncio -async def test_int(client: ValueTypesClient): - body = models.IntProperty(property=42) - assert body.property == body["property"] - await client.int_operations.put(body) - - resp = await client.int_operations.get() - assert resp.property == resp["property"] == 42 - - -@pytest.mark.asyncio -async def test_int_literal(client: ValueTypesClient): - body = models.IntLiteralProperty(property=42) - assert body.property == body["property"] - await client.int_literal.put(body) - - resp = await client.int_literal.get() - assert resp.property == resp["property"] == 42 - - -@pytest.mark.asyncio -async def test_model(client: ValueTypesClient): - body = models.ModelProperty(property={"property": "hello"}) - assert body.property.property == body["property"]["property"] - await client.model.put(body) - - resp = await client.model.get() - assert resp.property.property == resp["property"]["property"] - - -@pytest.mark.asyncio -async def test_never(client: ValueTypesClient): - assert await client.never.get() == models.NeverProperty() - await client.never.put(models.NeverProperty()) - - -@pytest.mark.asyncio -async def test_string(client: ValueTypesClient): - body = models.StringProperty(property="hello") - assert body.property == body["property"] - await client.string.put(body) - - resp = await client.string.get() - assert resp.property == resp["property"] == "hello" - - -@pytest.mark.asyncio -async def test_string_literal(client: ValueTypesClient): - body = models.StringLiteralProperty(property="hello") - assert body.property == body["property"] - await client.string_literal.put(body) - - resp = await client.string_literal.get() - assert resp.property == resp["property"] == "hello" - - -@pytest.mark.asyncio -async def test_union_enum_value(client: ValueTypesClient): - body = models.UnionEnumValueProperty(property=models.ExtendedEnum.ENUM_VALUE2) - assert body.property == body["property"] - await client.union_enum_value.put(body) - - resp = await client.union_enum_value.get() - assert resp.property == resp["property"] == "value2" - - -@pytest.mark.asyncio -async def test_union_float_literal(client: ValueTypesClient): - body = models.UnionFloatLiteralProperty(property=46.875) - assert body.property == body["property"] - await client.union_float_literal.put(body) - - resp = await client.union_float_literal.get() - assert resp.property == resp["property"] == 46.875 - - -@pytest.mark.asyncio -async def test_union_int_literal(client: ValueTypesClient): - body = models.UnionIntLiteralProperty(property=42) - assert body.property == body["property"] - await client.union_int_literal.put(body) - - resp = await client.union_int_literal.get() - assert resp.property == resp["property"] == 42 - - -@pytest.mark.asyncio -async def test_union_string_literal(client: ValueTypesClient): - body = models.UnionStringLiteralProperty(property="world") - assert body.property == body["property"] - await client.union_string_literal.put(body) - - resp = await client.union_string_literal.get() - assert resp.property == resp["property"] == "world" - - -@pytest.mark.asyncio -async def test_unknown_array(client: ValueTypesClient): - body = models.UnknownArrayProperty(property=["hello", "world"]) - assert body.property == body["property"] - await client.unknown_array.put(body) - - resp = await client.unknown_array.get() - assert resp.property == resp["property"] == ["hello", "world"] - - -@pytest.mark.asyncio -async def test_unknown_dict(client: ValueTypesClient): - body = models.UnknownDictProperty(property={"k1": "hello", "k2": 42}) - assert body.property == body["property"] - await client.unknown_dict.put(body) - - resp = await client.unknown_dict.get() - assert resp.property == resp["property"] == {"k1": "hello", "k2": 42} - - -@pytest.mark.asyncio -async def test_unknown_int(client: ValueTypesClient): - body = models.UnknownIntProperty(property=42) - assert body.property == body["property"] - await client.unknown_int.put(body) - - resp = await client.unknown_int.get() - assert resp.property == resp["property"] == 42 - - -@pytest.mark.asyncio -async def test_unknown_string(client: ValueTypesClient): - body = models.UnknownStringProperty(property="hello") - assert body.property == body["property"] - await client.unknown_string.put(body) - - resp = await client.unknown_string.get() - assert resp.property == resp["property"] == "hello" diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py deleted file mode 100644 index 3e2b308f8ba..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py +++ /dev/null @@ -1,60 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import decimal -from functools import reduce - -import pytest -from typetest.scalar.aio import ScalarClient - - -@pytest.fixture -async def client(): - async with ScalarClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_scalar_string(client: ScalarClient): - assert await client.string.get() == "test" - await client.string.put("test") - - -@pytest.mark.asyncio -async def test_scalar_boolean(client: ScalarClient): - assert await client.boolean.get() == True - await client.boolean.put(True) - - -@pytest.mark.asyncio -async def test_scalar_unknown(client: ScalarClient): - assert await client.unknown.get() == "test" - await client.unknown.put("test") - - -@pytest.mark.asyncio -async def test_decimal128_type(client: ScalarClient): - assert await client.decimal128_type.response_body() == decimal.Decimal("0.33333") - await client.decimal128_type.request_body(decimal.Decimal("0.33333")) - await client.decimal128_type.request_parameter(value=decimal.Decimal("0.33333")) - - -@pytest.mark.asyncio -async def test_decimal_type(client: ScalarClient): - assert await client.decimal_type.response_body() == decimal.Decimal("0.33333") - await client.decimal_type.request_body(decimal.Decimal("0.33333")) - await client.decimal_type.request_parameter(value=decimal.Decimal("0.33333")) - - -@pytest.mark.asyncio -async def test_decimal128_verify(client: ScalarClient): - prepare = await client.decimal128_verify.prepare_verify() - await client.decimal128_verify.verify(reduce(lambda x, y: x + y, prepare)) - - -@pytest.mark.asyncio -async def test_decimal_verify(client: ScalarClient): - prepare = await client.decimal_verify.prepare_verify() - await client.decimal_verify.verify(reduce(lambda x, y: x + y, prepare)) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py deleted file mode 100644 index 9e738701f4f..00000000000 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py +++ /dev/null @@ -1,90 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 typetest.union.aio import UnionClient -from typetest.union import models - - -@pytest.fixture -async def client(): - async with UnionClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_enums_only(client: UnionClient): - value = models.EnumsOnlyCases(lr="right", ud="up") - assert (await client.enums_only.get()) == {"prop": value} - await client.enums_only.send(prop=value) - - -@pytest.mark.asyncio -async def test_floats_only(client: UnionClient): - value = 2.2 - assert (await client.floats_only.get()) == {"prop": value} - await client.floats_only.send(prop=value) - - -@pytest.mark.asyncio -async def test_ints_only(client: UnionClient): - value = 2 - assert (await client.ints_only.get()) == {"prop": value} - await client.ints_only.send(prop=value) - - -@pytest.mark.asyncio -async def test_mixed_literals(client: UnionClient): - value = models.MixedLiteralsCases(string_literal="a", int_literal=2, float_literal=3.3, boolean_literal=True) - assert (await client.mixed_literals.get()) == {"prop": value} - await client.mixed_literals.send(prop=value) - - -@pytest.mark.asyncio -async def test_mixed_types(client: UnionClient): - value = models.MixedTypesCases( - model=models.Cat(name="test"), - literal="a", - int_property=2, - boolean=True, - array=[models.Cat(name="test"), "a", 2, True], - ) - assert (await client.mixed_types.get()) == {"prop": value} - await client.mixed_types.send(prop=value) - - -@pytest.mark.asyncio -async def test_models_only(client: UnionClient): - value = models.Cat(name="test") - assert (await client.models_only.get()) == {"prop": value} - await client.models_only.send(prop=value) - - -@pytest.mark.asyncio -async def test_string_and_array(client: UnionClient): - value = models.StringAndArrayCases(string="test", array=["test1", "test2"]) - assert (await client.string_and_array.get()) == {"prop": value} - await client.string_and_array.send(prop=value) - - -@pytest.mark.asyncio -async def test_string_extensible(client: UnionClient): - value = "custom" - assert (await client.string_extensible.get()) == {"prop": value} - await client.string_extensible.send(prop=value) - - -@pytest.mark.asyncio -async def test_string_extensible_named(client: UnionClient): - value = "custom" - assert (await client.string_extensible_named.get()) == {"prop": value} - await client.string_extensible_named.send(prop=value) - - -@pytest.mark.asyncio -async def test_strings_only(client: UnionClient): - value = "b" - assert (await client.strings_only.get()) == {"prop": value} - await client.strings_only.send(prop=value) From c952ec6a283df2c169467e3a177d153a0cad414f Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 17 Jan 2025 17:15:47 +0800 Subject: [PATCH 10/32] update test --- .../http-client-python/eng/scripts/ci/regenerate.ts | 12 ++++++++++-- .../azure/mock_api_tests/test_typetest_enum_fixed.py | 1 + .../mock_api_tests/test_typetest_enum_fixed.py | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/http-client-python/eng/scripts/ci/regenerate.ts b/packages/http-client-python/eng/scripts/ci/regenerate.ts index 599bbb3fa0e..9bff24fb0c6 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate.ts @@ -90,8 +90,16 @@ const EMITTER_OPTIONS: Record | Record Date: Mon, 20 Jan 2025 11:59:40 +0800 Subject: [PATCH 11/32] fix ci --- packages/http-client-python/generator/test/unbranded/tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/http-client-python/generator/test/unbranded/tox.ini b/packages/http-client-python/generator/test/unbranded/tox.ini index 68ed962f131..ebbb9b7c33b 100644 --- a/packages/http-client-python/generator/test/unbranded/tox.ini +++ b/packages/http-client-python/generator/test/unbranded/tox.ini @@ -7,7 +7,7 @@ deps= -r requirements.txt commands = # pytest - pytest mock_api_tests ../generic_mock_api_tests + python -m pytest mock_api_tests ../generic_mock_api_tests # pylint pip install azure-pylint-guidelines-checker==0.5.0 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/" @@ -27,7 +27,7 @@ commands = deps= -r requirements.txt commands = - pytest mock_api_tests ../generic_mock_api_tests + python -m pytest mock_api_tests ../generic_mock_api_tests [testenv:lint] deps= From de09b5c74654b5a57d30c044818476a80a1eddd7 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 20 Jan 2025 14:29:26 +0800 Subject: [PATCH 12/32] update tox.ini --- packages/http-client-python/generator/test/unbranded/tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/http-client-python/generator/test/unbranded/tox.ini b/packages/http-client-python/generator/test/unbranded/tox.ini index ebbb9b7c33b..68ed962f131 100644 --- a/packages/http-client-python/generator/test/unbranded/tox.ini +++ b/packages/http-client-python/generator/test/unbranded/tox.ini @@ -7,7 +7,7 @@ deps= -r requirements.txt commands = # pytest - python -m pytest mock_api_tests ../generic_mock_api_tests + pytest mock_api_tests ../generic_mock_api_tests # pylint pip install azure-pylint-guidelines-checker==0.5.0 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/" @@ -27,7 +27,7 @@ commands = deps= -r requirements.txt commands = - python -m pytest mock_api_tests ../generic_mock_api_tests + pytest mock_api_tests ../generic_mock_api_tests [testenv:lint] deps= From 63c3dc764ca1ecd719c548b2d936d82015801501 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 20 Jan 2025 17:56:05 +0800 Subject: [PATCH 13/32] udpate status --- .../pygen/codegen/serializers/general_serializer.py | 6 +++++- .../templates/packaging_templates/MANIFEST.in.jinja2 | 4 ++-- .../templates/packaging_templates/README.md.jinja2 | 8 ++++---- .../packaging_templates/dev_requirements.txt.jinja2 | 6 +++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py index 57e774d99b0..d86d34710f0 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py @@ -28,7 +28,11 @@ def serialize_setup_file(self) -> str: def serialize_package_file(self, template_name: str, **kwargs: Any) -> str: template = self.env.get_template(template_name) - package_parts = (self.code_model.options["package_name"] or "").split("-")[:-1] + package_parts = ( + self.code_model.namespace.split(".")[:-1] + if self.code_model.options["enable_typespec_namespace"] + else (self.code_model.options["package_name"] or "").split("-")[:-1] + ) token_credential = any( c for c in self.code_model.clients if isinstance(getattr(c.credential, "type", None), TokenCredentialType) ) diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 index 454a9ad2717..7ab94fb8db3 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 @@ -3,6 +3,6 @@ include LICENSE include {{ package_name.replace('-', '/') }}/py.typed recursive-include tests *.py recursive-include samples *.py *.md -{%- for init_name in init_names %} +{% for init_name in init_names %} include {{ init_name }} -{%- endfor %} +{% endfor %} diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 index fbea5913604..88de4094d41 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 @@ -1,5 +1,5 @@ {% if code_model.is_azure_flavor %} -{% if package_mode == "mgmtplane" -%} +{% if package_mode == "mgmtplane" %} # Microsoft Azure SDK for Python This is the Microsoft {{package_pprint_name}} Client Library. @@ -11,7 +11,7 @@ For a more complete view of Azure libraries, see the [azure sdk python release]( To learn how to use this package, see the [quickstart guide](https://aka.ms/azsdk/python/mgmt) For docs and references, see [Python SDK References](https://docs.microsoft.com/python/api/overview/azure) -Code samples for this package can be found at [{{package_pprint_name}}](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com. +Code samples for this package can be found at [{{package_pprint_name}}](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20%20Managing&terms=Getting%20started%20%20Managing) on docs.microsoft.com. Additional code samples for different Azure services are available at [Samples Repo](https://aka.ms/azsdk/python/mgmt/samples) # Provide Feedback @@ -40,7 +40,7 @@ python -m pip install {{ package_name }} - You need an [Azure subscription][azure_sub] to use this package. - An existing {{ package_pprint_name }} instance. -{%- if token_credential %} +{% if token_credential %} #### Create with an Azure Active Directory Credential To use an [Azure Active Directory (AAD) token credential][authenticate_with_token], provide an instance of the desired credential type obtained from the @@ -76,7 +76,7 @@ Use the returned token credential to authenticate the client: print('service responds error: {}'.format(e.response.json())) ``` -{%- endif %} +{% endif %} ## Contributing diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 index a9782cabd58..2e01201bf96 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/dev_requirements.txt.jinja2 @@ -1,9 +1,9 @@ -e ../../../tools/azure-sdk-tools ../../core/azure-core -{% if token_credential -%} +{% if token_credential %} ../../identity/azure-identity {% endif -%} -{% if azure_arm -%} +{% if azure_arm %} ../../core/azure-mgmt-core -{% endif -%} +{% endif %} aiohttp From 3341ab28fdd4269a976e78947781e95806c831e1 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 21 Jan 2025 10:32:15 +0800 Subject: [PATCH 14/32] update test --- .../pygen/codegen/templates/packaging_templates/setup.py.jinja2 | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 index 6a1d6e5101d..aec2f299a5c 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 @@ -43,8 +43,6 @@ version = "{{ package_version }}" {% set author_email = "" %} {% set url = "" %} {% endif %} - - setup( name=PACKAGE_NAME, version=version, From 0b05d8a516dab90bc1840c9446c158ebfac5343e Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Thu, 13 Mar 2025 15:54:50 +0800 Subject: [PATCH 15/32] Create update-root-namespace-2025-2-12-6-11-5.md --- .../changes/update-root-namespace-2025-2-12-6-11-5.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/update-root-namespace-2025-2-12-6-11-5.md diff --git a/.chronus/changes/update-root-namespace-2025-2-12-6-11-5.md b/.chronus/changes/update-root-namespace-2025-2-12-6-11-5.md new file mode 100644 index 00000000000..8d0e04b9ec6 --- /dev/null +++ b/.chronus/changes/update-root-namespace-2025-2-12-6-11-5.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Always respect namesapce from TCGC From bec727aa0bbab2024e683e2b31332ac833e7f6a0 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Thu, 13 Mar 2025 16:50:49 +0800 Subject: [PATCH 16/32] update --- .../emitter/src/code-model.ts | 9 ++- .../http-client-python/emitter/src/emitter.ts | 3 - .../http-client-python/emitter/src/lib.ts | 6 +- .../http-client-python/emitter/src/utils.ts | 40 ++++------ .../eng/scripts/ci/regenerate.ts | 4 +- .../generator/pygen/preprocess/__init__.py | 4 +- packages/http-client-python/package-lock.json | 78 +++++++++++++++---- packages/http-client-python/package.json | 4 +- 8 files changed, 92 insertions(+), 56 deletions(-) diff --git a/packages/http-client-python/emitter/src/code-model.ts b/packages/http-client-python/emitter/src/code-model.ts index 6da74f43d8e..48eb3dd1ed5 100644 --- a/packages/http-client-python/emitter/src/code-model.ts +++ b/packages/http-client-python/emitter/src/code-model.ts @@ -1,4 +1,5 @@ import { + SdkApiVersionParameter, SdkBasicServiceMethod, SdkClientType, SdkCredentialParameter, @@ -100,7 +101,11 @@ function emitLroPagingMethod( function emitMethodParameter( context: PythonSdkContext, - parameter: SdkEndpointParameter | SdkCredentialParameter | SdkMethodParameter, + parameter: + | SdkEndpointParameter + | SdkCredentialParameter + | SdkMethodParameter + | SdkApiVersionParameter, ): Record[] { if (parameter.kind === "endpoint") { if (parameter.type.kind === "union") { @@ -139,7 +144,7 @@ function emitMethodParameter( clientDefaultValue: parameter.clientDefaultValue, location: parameter.kind, }; - if (parameter.isApiVersionParam) { + if (parameter.kind === "apiVersion") { return [ { ...base, diff --git a/packages/http-client-python/emitter/src/emitter.ts b/packages/http-client-python/emitter/src/emitter.ts index c7de08a2d8e..fd4a47d17f8 100644 --- a/packages/http-client-python/emitter/src/emitter.ts +++ b/packages/http-client-python/emitter/src/emitter.ts @@ -61,9 +61,6 @@ function addDefaultOptions(sdkContext: SdkContext) { if (!options.flavor && sdkContext.emitContext.emitterOutputDir.includes("azure")) { options.flavor = "azure"; } - if (options["enable-typespec-namespace"] === undefined) { - options["enable-typespec-namespace"] = options.flavor !== "azure"; - } } async function createPythonSdkContext( diff --git a/packages/http-client-python/emitter/src/lib.ts b/packages/http-client-python/emitter/src/lib.ts index 94408b0049d..8055243f8f4 100644 --- a/packages/http-client-python/emitter/src/lib.ts +++ b/packages/http-client-python/emitter/src/lib.ts @@ -17,9 +17,7 @@ export interface PythonEmitterOptions { debug?: boolean; flavor?: "azure"; "examples-dir"?: string; - // If true, package namespace will respect the typespec namespace. Otherwise, - // package namespace is always aligned with package name. - "enable-typespec-namespace"?: boolean; + namespace?: string; "use-pyodide"?: boolean; } @@ -47,7 +45,7 @@ const EmitterOptionsSchema: JSONSchemaType = { debug: { type: "boolean", nullable: true }, flavor: { type: "string", nullable: true }, "examples-dir": { type: "string", nullable: true, format: "absolute-path" }, - "enable-typespec-namespace": { type: "boolean", nullable: true }, + namespace: { type: "string", nullable: true }, "use-pyodide": { type: "boolean", nullable: true }, }, required: [], diff --git a/packages/http-client-python/emitter/src/utils.ts b/packages/http-client-python/emitter/src/utils.ts index 878ddd53780..4c13dec0ec8 100644 --- a/packages/http-client-python/emitter/src/utils.ts +++ b/packages/http-client-python/emitter/src/utils.ts @@ -216,29 +216,22 @@ const LIB_NAMESPACE = [ "typespec.versioning", ]; -function getRootTypespecNamespace(context: PythonSdkContext): string { - if (context.sdkPackage.clients.length > 0) { - return context.sdkPackage.clients[0].clientNamespace; - } - if (context.sdkPackage.models.length > 0) { +export function getRootNamespace(context: PythonSdkContext): string { + let rootNamespace = ""; + if (context.sdkPackage.namespaces.length > 0) { + rootNamespace = context.sdkPackage.namespaces[0].fullName; + } else if (context.sdkPackage.clients.length > 0) { + rootNamespace = context.sdkPackage.clients[0].namespace; + } else if (context.sdkPackage.models.length > 0) { const result = context.sdkPackage.models - .map((model) => model.clientNamespace) + .map((model) => model.namespace) .filter((namespace) => !LIB_NAMESPACE.includes(namespace)); if (result.length > 0) { result.sort(); - return result[0]; + rootNamespace = result[0]; } } - if (context.sdkPackage.namespaces.length > 0) { - return context.sdkPackage.namespaces[0].fullName; - } - return ""; -} -export function getRootNamespace(context: PythonSdkContext): string { - const rootNamespace = context.emitContext.options["enable-typespec-namespace"] - ? getRootTypespecNamespace(context) - : context.sdkPackage.rootNamespace; return removeUnderscoresFromNamespace(rootNamespace).toLowerCase(); } @@ -246,16 +239,13 @@ export function getClientNamespace, clientNamespace: string, ) { - const rootNamespace = getRootNamespace(context); - if (!context.emitContext.options["enable-typespec-namespace"]) { - return rootNamespace; - } - if (LIB_NAMESPACE.some((item) => clientNamespace.toLowerCase().startsWith(item))) { - return rootNamespace; + if ( + clientNamespace === "" || + LIB_NAMESPACE.some((item) => clientNamespace.toLowerCase().startsWith(item)) + ) { + return getRootNamespace(context); } - return clientNamespace === "" - ? rootNamespace - : removeUnderscoresFromNamespace(clientNamespace).toLowerCase(); + return removeUnderscoresFromNamespace(clientNamespace).toLowerCase(); } function parseToken(token: Token): string { diff --git a/packages/http-client-python/eng/scripts/ci/regenerate.ts b/packages/http-client-python/eng/scripts/ci/regenerate.ts index e662143b98b..23bcff99235 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate.ts @@ -95,13 +95,13 @@ const EMITTER_OPTIONS: Record | Record=0.52.0 <1.0.0", "@azure-tools/typespec-azure-resource-manager": ">=0.52.0 <1.0.0", "@azure-tools/typespec-azure-rulesets": ">=0.52.0 <3.0.0", - "@azure-tools/typespec-client-generator-core": ">=0.52.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": "0.53.0-dev.23", "@typespec/compiler": ">=0.66.0 <1.0.0", "@typespec/http": ">=0.66.0 <1.0.0", "@typespec/openapi": ">=0.66.0 <1.0.0", @@ -151,9 +151,9 @@ } }, "node_modules/@azure-tools/typespec-client-generator-core": { - "version": "0.52.0", - "resolved": "https://registry.npmjs.org/@azure-tools/typespec-client-generator-core/-/typespec-client-generator-core-0.52.0.tgz", - "integrity": "sha512-P1kh4mkqPmZY0JsJAtnTRDjzynI05TybgRTsaEnQtFwnlbfUzu1KtKDF4midQDMT6Ao8JEt/S2Nd4nQ1/qrHyQ==", + "version": "0.53.0-dev.23", + "resolved": "https://registry.npmjs.org/@azure-tools/typespec-client-generator-core/-/typespec-client-generator-core-0.53.0-dev.23.tgz", + "integrity": "sha512-GGCGwFuZt7eBpeM1G/l3jts4f9x4jKN20t8OpIiL9E+rHOckq+gjDmt9mz/se3eRcJSltxL53R6qGpmWto7mZA==", "dev": true, "license": "MIT", "dependencies": { @@ -162,16 +162,19 @@ "yaml": "~2.7.0" }, "engines": { - "node": ">=18.0.0" + "node": ">=20.0.0" }, "peerDependencies": { - "@azure-tools/typespec-azure-core": "~0.52.0", - "@typespec/compiler": "~0.66.0", - "@typespec/http": "~0.66.0", - "@typespec/openapi": "~0.66.0", - "@typespec/rest": "~0.66.0", - "@typespec/versioning": "~0.66.0", - "@typespec/xml": "~0.66.0" + "@azure-tools/typespec-azure-core": "^0.52.0 || >=0.53.0-dev <0.53.0", + "@typespec/compiler": "^0.66.0 || >=0.67.0-dev <0.67.0", + "@typespec/events": "^0.66.0 || >=0.67.0-dev <0.67.0", + "@typespec/http": "^0.66.0 || >=0.67.0-dev <0.67.0", + "@typespec/openapi": "^0.66.0 || >=0.67.0-dev <0.67.0", + "@typespec/rest": "^0.66.0 || >=0.67.0-dev <0.67.0", + "@typespec/sse": "^0.66.0 || >=0.67.0-dev <0.67.0", + "@typespec/streams": "^0.66.0 || >=0.67.0-dev <0.67.0", + "@typespec/versioning": "^0.66.0 || >=0.67.0-dev <0.67.0", + "@typespec/xml": "^0.66.0 || >=0.67.0-dev <0.67.0" } }, "node_modules/@azure/abort-controller": { @@ -3076,6 +3079,20 @@ "node": ">=18.0.0" } }, + "node_modules/@typespec/events": { + "version": "0.66.0", + "resolved": "https://registry.npmjs.org/@typespec/events/-/events-0.66.0.tgz", + "integrity": "sha512-I0FlzJhLxhxPKzp+qfjQECIoKQJwuS/GpR9SaArYsroyL6YUZmwpyDHHbYDQ7/VHU/sRFJGvgVfDPhpooghlqA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.66.0" + } + }, "node_modules/@typespec/http": { "version": "0.66.0", "resolved": "https://registry.npmjs.org/@typespec/http/-/http-0.66.0.tgz", @@ -3240,6 +3257,37 @@ "node": ">=16.0.0" } }, + "node_modules/@typespec/sse": { + "version": "0.66.0", + "resolved": "https://registry.npmjs.org/@typespec/sse/-/sse-0.66.0.tgz", + "integrity": "sha512-Aa/pLy9i/lIdPwpT7uv4aycap96LGQIZg5I/k2tc4kfU9cmEo0c3tDwAiu7rRBEobdjKh+neiY8ulwt/HS4x8Q==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.66.0", + "@typespec/events": "~0.66.0", + "@typespec/http": "~0.66.0", + "@typespec/streams": "~0.66.0" + } + }, + "node_modules/@typespec/streams": { + "version": "0.66.0", + "resolved": "https://registry.npmjs.org/@typespec/streams/-/streams-0.66.0.tgz", + "integrity": "sha512-W7qtcn+l6/eTkCS3ux7/BAjWBYebbCQ1K4dHtuhBYrjOJOkHWE27hzeTUWuNwY5YwKrIe0ln1Jmf9iPaUUw5tQ==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=18.0.0" + }, + "peerDependencies": { + "@typespec/compiler": "~0.66.0" + } + }, "node_modules/@typespec/versioning": { "version": "0.66.0", "resolved": "https://registry.npmjs.org/@typespec/versioning/-/versioning-0.66.0.tgz", diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index 6249b2113bf..cda92248023 100644 --- a/packages/http-client-python/package.json +++ b/packages/http-client-python/package.json @@ -57,7 +57,7 @@ "@azure-tools/typespec-azure-core": ">=0.52.0 <1.0.0", "@azure-tools/typespec-azure-resource-manager": ">=0.52.0 <1.0.0", "@azure-tools/typespec-azure-rulesets": ">=0.52.0 <3.0.0", - "@azure-tools/typespec-client-generator-core": ">=0.52.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": "0.53.0-dev.23", "@typespec/compiler": ">=0.66.0 <1.0.0", "@typespec/http": ">=0.66.0 <1.0.0", "@typespec/openapi": ">=0.66.0 <1.0.0", @@ -77,7 +77,7 @@ "@azure-tools/typespec-azure-core": "~0.52.0", "@azure-tools/typespec-azure-resource-manager": "~0.52.0", "@azure-tools/typespec-azure-rulesets": "~0.52.0", - "@azure-tools/typespec-client-generator-core": "~0.52.0", + "@azure-tools/typespec-client-generator-core": "0.53.0-dev.23", "@types/js-yaml": "~4.0.5", "@types/node": "~22.5.4", "@types/semver": "7.5.8", From 35705ac66e2605638fe7861405f503f7d6d64d19 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 14 Mar 2025 15:47:47 +0800 Subject: [PATCH 17/32] update --- .../http-client-python/emitter/src/emitter.ts | 10 ++++-- .../http-client-python/emitter/src/lib.ts | 7 ++++ .../generator/pygen/codegen/__init__.py | 1 - .../pygen/codegen/serializers/__init__.py | 33 +++++++++---------- .../codegen/serializers/general_serializer.py | 7 +--- .../codegen/serializers/test_serializer.py | 2 +- .../packaging_templates/MANIFEST.in.jinja2 | 2 +- .../packaging_templates/README.md.jinja2 | 4 +-- .../packaging_templates/setup.py.jinja2 | 7 ---- 9 files changed, 35 insertions(+), 38 deletions(-) diff --git a/packages/http-client-python/emitter/src/emitter.ts b/packages/http-client-python/emitter/src/emitter.ts index fd4a47d17f8..75cdd4c09c7 100644 --- a/packages/http-client-python/emitter/src/emitter.ts +++ b/packages/http-client-python/emitter/src/emitter.ts @@ -16,7 +16,7 @@ import { saveCodeModelAsYaml } from "./external-process.js"; import { PythonEmitterOptions, PythonSdkContext, reportDiagnostic } from "./lib.js"; import { runPython3 } from "./run-python3.js"; import { disableGenerationMap, simpleTypesMap, typesMap } from "./types.js"; -import { md2Rst, removeUnderscoresFromNamespace } from "./utils.js"; +import { getRootNamespace, md2Rst } from "./utils.js"; export function getModelsMode(context: SdkContext): "dpg" | "none" { const specifiedModelsMode = context.emitContext.options["models-mode"]; @@ -50,8 +50,12 @@ function addDefaultOptions(sdkContext: SdkContext) { options["package-mode"] = sdkContext.arm ? "azure-mgmt" : "azure-dataplane"; } if (!options["package-name"]) { - options["package-name"] = removeUnderscoresFromNamespace( - (sdkContext.sdkPackage.rootNamespace ?? "").toLowerCase(), + reportDiagnostic(sdkContext.program, { + code: "no-package-name", + target: NoTarget, + }); + options["package-name"] = getRootNamespace( + sdkContext as PythonSdkContext, ).replace(/\./g, "-"); } if (options.flavor !== "azure") { diff --git a/packages/http-client-python/emitter/src/lib.ts b/packages/http-client-python/emitter/src/lib.ts index 8055243f8f4..2608341c2ae 100644 --- a/packages/http-client-python/emitter/src/lib.ts +++ b/packages/http-client-python/emitter/src/lib.ts @@ -75,6 +75,13 @@ const libDef = { }, }, // warning + "no-package-name": { + severity: "warning", + messages: { + default: + "No 'package-name' configured in tspconfig.yaml and will infer pacakge-name from namespace.", + }, + }, "no-valid-client": { severity: "warning", messages: { diff --git a/packages/http-client-python/generator/pygen/codegen/__init__.py b/packages/http-client-python/generator/pygen/codegen/__init__.py index c48ba50ee21..2cf10f3fac0 100644 --- a/packages/http-client-python/generator/pygen/codegen/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/__init__.py @@ -40,7 +40,6 @@ class OptionsRetriever: "generate-test": False, "from-typespec": False, "emit-cross-language-definition-file": False, - "enable-typespec-namespace": False, } @property diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py index 3c3d1e344ed..c473f478d45 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -462,24 +462,11 @@ def _serialize_and_write_metadata(self, env: Environment, namespace: str) -> Non metadata_serializer = MetadataSerializer(self.code_model, env, client_namespace=namespace) self.write_file(self.exec_path(namespace) / Path("_metadata.json"), metadata_serializer.serialize()) - @property - def _namespace_from_package_name(self) -> str: - return get_namespace_from_package_name(self.code_model.options["package_name"]) - - def _name_space(self) -> str: - if ( - self.code_model.namespace.count(".") >= self._namespace_from_package_name.count(".") - or self.code_model.options["enable_typespec_namespace"] - ): - return self.code_model.namespace - - return self._namespace_from_package_name - @property def exec_path_compensation(self) -> Path: """Assume the process is running in the root folder of the package. If not, we need the path compensation.""" return ( - Path("../" * (self._name_space().count(".") + 1)) + Path("../" * (self.code_model.namespace.count(".") + 1)) if self.code_model.options["no_namespace_folders"] else Path(".") ) @@ -487,16 +474,28 @@ def exec_path_compensation(self) -> Path: def exec_path_for_test_sample(self, namespace: str) -> Path: return self.exec_path_compensation / Path(*namespace.split(".")) + # pylint: disable=line-too-long def exec_path(self, namespace: str) -> Path: if self.code_model.options["no_namespace_folders"] and not self.code_model.options["multiapi"]: + # when output folder contains parts different from the namespace, we fall back to current folder directly. + # (e.g. https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/communication/azure-communication-callautomation/swagger/SWAGGER.md) return Path(".") return self.exec_path_compensation / Path(*namespace.split(".")) + # pylint: disable=line-too-long @property - def _additional_folder(self) -> Path: + def sample_additional_folder(self) -> Path: + # For special package, we need to addtional folder when generate sampoles. + # For example, azure-mgmt-resource is commbied by multiple modules, and each module is multiapi package. + # one of namespace is "azure.mgmt.resource.resources.v2020_01_01", then additional folder is "resources" + # so that we could avoid conflict when generate samples. + # python config: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/resources/resource-manager/readme.python.md + # generated SDK: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/resources/azure-mgmt-resource/generated_samples namespace_config = get_namespace_config(self.code_model.namespace, self.code_model.options["multiapi"]) num_of_namespace = namespace_config.count(".") + 1 - num_of_package_namespace = self._namespace_from_package_name.count(".") + 1 + num_of_package_namespace = ( + get_namespace_from_package_name(self.code_model.options["package_name"]).count(".") + 1 + ) if num_of_namespace > num_of_package_namespace: return Path("/".join(namespace_config.split(".")[num_of_package_namespace:])) return Path("") @@ -519,7 +518,7 @@ def _serialize_and_write_sample(self, env: Environment, namespace: str): file_name = to_snake_case(extract_sample_name(file)) + ".py" try: self.write_file( - out_path / self._additional_folder / _sample_output_path(file) / file_name, + out_path / self.sample_additional_folder / _sample_output_path(file) / file_name, SampleSerializer( code_model=self.code_model, env=env, diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py index d86d34710f0..e4586b733c7 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py @@ -28,11 +28,7 @@ def serialize_setup_file(self) -> str: def serialize_package_file(self, template_name: str, **kwargs: Any) -> str: template = self.env.get_template(template_name) - package_parts = ( - self.code_model.namespace.split(".")[:-1] - if self.code_model.options["enable_typespec_namespace"] - else (self.code_model.options["package_name"] or "").split("-")[:-1] - ) + package_parts = self.code_model.namespace.split(".")[:-1] token_credential = any( c for c in self.code_model.clients if isinstance(getattr(c.credential, "type", None), TokenCredentialType) ) @@ -48,7 +44,6 @@ def serialize_package_file(self, template_name: str, **kwargs: Any) -> str: "pkgutil_names": [".".join(package_parts[: i + 1]) for i in range(len(package_parts))], "init_names": ["/".join(package_parts[: i + 1]) + "/__init__.py" for i in range(len(package_parts))], "client_name": self.code_model.clients[0].name, - "namespace": self.code_model.namespace, } params.update(self.code_model.options) params.update(kwargs) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/test_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/test_serializer.py index 3925f341178..444b67455bc 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/test_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/test_serializer.py @@ -19,7 +19,7 @@ CombinedType, FileImport, ) -from .utils import get_namespace_from_package_name, json_dumps_template +from .utils import json_dumps_template def is_lro(operation_type: str) -> bool: diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 index 7ab94fb8db3..df76124de2b 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 @@ -1,6 +1,6 @@ include *.md include LICENSE -include {{ package_name.replace('-', '/') }}/py.typed +include {{ code_model.namespace.replace('.', '/') }}/py.typed recursive-include tests *.py recursive-include samples *.py *.md {% for init_name in init_names %} diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 index 88de4094d41..cb221597bb4 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 @@ -57,7 +57,7 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica Use the returned token credential to authenticate the client: ```python ->>> from {{ namespace }} import {{ client_name }} +>>> from {{ code_model.namespace }} import {{ client_name }} >>> from azure.identity import DefaultAzureCredential >>> client = {{ client_name }}(endpoint='', credential=DefaultAzureCredential()) ``` @@ -65,7 +65,7 @@ Use the returned token credential to authenticate the client: ## Examples ```python ->>> from {{ namespace }} import {{ client_name }} +>>> from {{ code_model.namespace }} import {{ client_name }} >>> from azure.identity import DefaultAzureCredential >>> from {{ code_model.core_library }}.exceptions import HttpResponseError diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 index aec2f299a5c..f5b3b882f5a 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 @@ -11,19 +11,12 @@ from setuptools import setup, find_packages {% set package_name = package_name or code_model.clients[0].name %} PACKAGE_NAME = "{{ package_name|lower }}" -{% if code_model.options["enable_typespec_namespace"] %} PACKAGE_NAMESPACE = "{{ code_model.namespace|lower }}" -{% endif %} {% if package_mode %} PACKAGE_PPRINT_NAME = "{{ package_pprint_name }}" -{% if code_model.options["enable_typespec_namespace"] %} # a.b.c => a/b/c package_folder_path = PACKAGE_NAMESPACE.replace(".", "/") -{% else %} -# a-b-c => a/b/c -package_folder_path = PACKAGE_NAME.replace("-", "/") -{% endif %} # Version extraction inspired from 'requests' with open(os.path.join(package_folder_path, "_version.py"), "r") as fd: From 1fb6dbf47fb942d35abc3fb714273a417ec5fcde Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 14 Mar 2025 16:35:13 +0800 Subject: [PATCH 18/32] update --- .../http-client-python/emitter/src/lib.ts | 2 +- .../eng/scripts/ci/regenerate.ts | 30 ++++++++++++++++++- .../pygen/codegen/serializers/__init__.py | 4 +-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/http-client-python/emitter/src/lib.ts b/packages/http-client-python/emitter/src/lib.ts index 2608341c2ae..9ae89444d3a 100644 --- a/packages/http-client-python/emitter/src/lib.ts +++ b/packages/http-client-python/emitter/src/lib.ts @@ -79,7 +79,7 @@ const libDef = { severity: "warning", messages: { default: - "No 'package-name' configured in tspconfig.yaml and will infer pacakge-name from namespace.", + "No 'package-name' configured in tspconfig.yaml and will infer 'package-name' from namespace.", }, }, "no-valid-client": { diff --git a/packages/http-client-python/eng/scripts/ci/regenerate.ts b/packages/http-client-python/eng/scripts/ci/regenerate.ts index 23bcff99235..6293c757762 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate.ts @@ -41,58 +41,76 @@ interface TspCommand { const EMITTER_OPTIONS: Record | Record[]> = { "resiliency/srv-driven/old.tsp": { "package-name": "resiliency-srv-driven1", + namespace: "resiliency.srv.driven1", "package-mode": "azure-dataplane", "package-pprint-name": "ResiliencySrvDriven1", }, "resiliency/srv-driven": { "package-name": "resiliency-srv-driven2", + namespace: "resiliency.srv.driven2", "package-mode": "azure-dataplane", "package-pprint-name": "ResiliencySrvDriven2", }, "authentication/http/custom": { "package-name": "authentication-http-custom", + namespace: "authentication.http.custom", "package-pprint-name": "Authentication Http Custom", }, "authentication/union": { "package-name": "authentication-union", + namespace: "authentication.union", }, "type/array": { "package-name": "typetest-array", + namespace: "typetest.array", "use-pyodide": "true", }, "type/dictionary": { "package-name": "typetest-dictionary", + namespace: "typetest.dictionary", }, "type/enum/extensible": { "package-name": "typetest-enum-extensible", + namespace: "typetest.enum.extensible", }, "type/enum/fixed": { "package-name": "typetest-enum-fixed", + namespace: "typetest.enum.fixed", }, "type/model/empty": { "package-name": "typetest-model-empty", + namespace: "typetest.model.empty", }, "type/model/inheritance/enum-discriminator": { "package-name": "typetest-model-enumdiscriminator", + namespace: "typetest.model.enumdiscriminator", }, "type/model/inheritance/nested-discriminator": { "package-name": "typetest-model-nesteddiscriminator", + namespace: "typetest.model.nesteddiscriminator", }, "type/model/inheritance/not-discriminated": { "package-name": "typetest-model-notdiscriminated", + namespace: "typetest.model.notdiscriminated", }, "type/model/inheritance/single-discriminator": { "package-name": "typetest-model-singlediscriminator", + namespace: "typetest.model.singlediscriminator", }, "type/model/inheritance/recursive": { "package-name": "typetest-model-recursive", + namespace: "typetest.model.recursive", "use-pyodide": "true", }, "type/model/usage": { "package-name": "typetest-model-usage", + namespace: "typetest.model.usage", }, "type/model/visibility": [ - { "package-name": "typetest-model-visibility" }, + { + "package-name": "typetest-model-visibility", + namespace: "typetest.model.visibility", + }, { "package-name": "headasbooleantrue", namespace: "headasbooleantrue", @@ -106,33 +124,43 @@ const EMITTER_OPTIONS: Record | Record Path: # pylint: disable=line-too-long @property def sample_additional_folder(self) -> Path: - # For special package, we need to addtional folder when generate sampoles. - # For example, azure-mgmt-resource is commbied by multiple modules, and each module is multiapi package. + # For special package, we need to additional folder when generate sampoles. + # For example, azure-mgmt-resource is combined by multiple modules, and each module is multiapi package. # one of namespace is "azure.mgmt.resource.resources.v2020_01_01", then additional folder is "resources" # so that we could avoid conflict when generate samples. # python config: https://github.com/Azure/azure-rest-api-specs/blob/main/specification/resources/resource-manager/readme.python.md From 8067b7142228809f14b3c6ee425473bd6ec98a6b Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 14 Mar 2025 16:41:42 +0800 Subject: [PATCH 19/32] udpate --- .../asynctests/test_typetest_array_async.py | 0 .../test_typetest_dictionary_async.py | 0 .../test_typetest_enum_extensible_async.py | 0 .../test_typetest_enum_fixed_async.py | 5 +- .../test_typetest_model_empty_async.py | 0 ...el_inheritance_enum_discriminator_async.py | 0 ..._inheritance_nested_discriminator_async.py | 0 ...del_inheritance_not_discriminated_async.py | 0 ...etest_model_inheritance_recursive_async.py | 0 ..._inheritance_single_discriminator_async.py | 0 .../test_typetest_model_usage_async.py | 0 .../test_typetest_model_visibility_async.py | 0 ...est_property_additionalproperties_async.py | 0 .../test_typetest_property_nullable_async.py | 0 .../test_typetest_property_optional_async.py | 0 ...test_typetest_property_valuetypes_async.py | 0 .../asynctests/test_typetest_scalar_async.py | 0 .../asynctests/test_typetest_union_async.py | 0 .../test_typetest_array.py | 0 .../test_typetest_dictionary.py | 0 .../test_typetest_enum_extensible.py | 0 .../test_typetest_enum_fixed.py | 5 +- .../test_typetest_model_empty.py | 0 ...st_model_inheritance_enum_discriminator.py | 0 ..._model_inheritance_nested_discriminator.py | 0 ...est_model_inheritance_not_discriminated.py | 0 ...st_typetest_model_inheritance_recursive.py | 0 ..._model_inheritance_single_discriminator.py | 0 .../test_typetest_model_usage.py | 0 .../test_typetest_model_visibility.py | 0 ..._typetest_property_additionalproperties.py | 0 .../test_typetest_property_nullable.py | 0 .../test_typetest_property_optional.py | 0 .../test_typetest_property_valuetypes.py | 0 .../test_typetest_scalar.py | 0 .../test_typetest_union.py | 0 .../asynctests/test_typetest_array_async.py | 118 ------ .../test_typetest_dictionary_async.py | 98 ----- .../test_typetest_enum_extensible_async.py | 25 -- .../test_typetest_enum_fixed_async.py | 28 -- .../test_typetest_model_empty_async.py | 32 -- ...el_inheritance_enum_discriminator_async.py | 70 ---- ..._inheritance_nested_discriminator_async.py | 85 ----- ...del_inheritance_not_discriminated_async.py | 34 -- ...etest_model_inheritance_recursive_async.py | 34 -- ..._inheritance_single_discriminator_async.py | 67 ---- .../test_typetest_model_usage_async.py | 32 -- .../test_typetest_model_visibility_async.py | 47 --- ...est_property_additionalproperties_async.py | 352 ------------------ .../test_typetest_property_nullable_async.py | 110 ------ .../test_typetest_property_optional_async.py | 197 ---------- ...test_typetest_property_valuetypes_async.py | 315 ---------------- .../asynctests/test_typetest_scalar_async.py | 60 --- .../asynctests/test_typetest_union_async.py | 90 ----- .../asynctests/test_unbranded_async.py | 2 +- .../mock_api_tests/test_typetest_array.py | 103 ----- .../test_typetest_dictionary.py | 86 ----- .../test_typetest_enum_extensible.py | 23 -- .../test_typetest_enum_fixed.py | 26 -- .../test_typetest_model_empty.py | 29 -- ...st_model_inheritance_enum_discriminator.py | 58 --- ..._model_inheritance_nested_discriminator.py | 79 ---- ...est_model_inheritance_not_discriminated.py | 31 -- ...st_typetest_model_inheritance_recursive.py | 32 -- ..._model_inheritance_single_discriminator.py | 60 --- .../test_typetest_model_usage.py | 28 -- .../test_typetest_model_visibility.py | 40 -- ..._typetest_property_additionalproperties.py | 313 ---------------- .../test_typetest_property_nullable.py | 102 ----- .../test_typetest_property_optional.py | 174 --------- .../test_typetest_property_valuetypes.py | 286 -------------- .../mock_api_tests/test_typetest_scalar.py | 53 --- .../mock_api_tests/test_typetest_union.py | 80 ---- .../mock_api_tests/test_unbranded.py | 2 +- 74 files changed, 6 insertions(+), 3405 deletions(-) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_array_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_dictionary_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_enum_extensible_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_enum_fixed_async.py (84%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_model_empty_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_model_inheritance_not_discriminated_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_model_inheritance_recursive_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_model_inheritance_single_discriminator_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_model_usage_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_model_visibility_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_property_additionalproperties_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_property_nullable_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_property_optional_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_property_valuetypes_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_scalar_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/asynctests/test_typetest_union_async.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_array.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_dictionary.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_enum_extensible.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_enum_fixed.py (84%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_model_empty.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_model_inheritance_enum_discriminator.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_model_inheritance_nested_discriminator.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_model_inheritance_not_discriminated.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_model_inheritance_recursive.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_model_inheritance_single_discriminator.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_model_usage.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_model_visibility.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_property_additionalproperties.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_property_nullable.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_property_optional.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_property_valuetypes.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_scalar.py (100%) rename packages/http-client-python/generator/test/{azure/mock_api_tests => generic_mock_api_tests}/test_typetest_union.py (100%) delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_array_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_dictionary_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_empty_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_usage_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_visibility_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_nullable_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_optional_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_scalar_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_union_async.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_array.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_dictionary.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_extensible.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_empty.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_usage.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_visibility.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_additionalproperties.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_nullable.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_optional.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_valuetypes.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_scalar.py delete mode 100644 packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_union.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_array_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_array_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_array_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_dictionary_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_dictionary_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_dictionary_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_extensible_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py similarity index 84% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py index c8f132319c6..de17f194b6d 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py +++ b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_enum_fixed_async.py @@ -5,7 +5,6 @@ # -------------------------------------------------------------------------- import pytest from typetest.enum.fixed import aio, models -from azure.core.exceptions import HttpResponseError @pytest.fixture @@ -21,8 +20,8 @@ async def test_known_value(client): @pytest.mark.asyncio -async def test_unknown_value(client: aio.FixedClient): +async def test_unknown_value(client: aio.FixedClient, core_library): try: await client.string.put_unknown_value("Weekend") - except HttpResponseError as err: + except core_library.exceptions.HttpResponseError as err: assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_empty_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_empty_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_empty_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_usage_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_usage_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_usage_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_visibility_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_model_visibility_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_model_visibility_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_nullable_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_nullable_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_nullable_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_optional_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_optional_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_optional_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_scalar_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_scalar_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_scalar_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_union_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_typetest_union_async.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_typetest_union_async.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_array.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_array.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_array.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_array.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_dictionary.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_dictionary.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_dictionary.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_dictionary.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_extensible.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_extensible.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_extensible.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_extensible.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_fixed.py similarity index 84% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_fixed.py index a2a7ca11a6b..0d085d02002 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_enum_fixed.py +++ b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_enum_fixed.py @@ -5,7 +5,6 @@ # -------------------------------------------------------------------------- import pytest from typetest.enum.fixed import FixedClient, models -from azure.core.exceptions import HttpResponseError @pytest.fixture @@ -19,8 +18,8 @@ def test_known_value(client): client.string.put_known_value(models.DaysOfWeekEnum.MONDAY) -def test_unknown_value(client: FixedClient): +def test_unknown_value(client: FixedClient, core_library): try: client.string.put_unknown_value("Weekend") - except HttpResponseError as err: + except core_library.exceptions.HttpResponseError as err: assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_empty.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_empty.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_empty.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_empty.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_not_discriminated.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_not_discriminated.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_recursive.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_recursive.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_recursive.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_recursive.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_single_discriminator.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_inheritance_single_discriminator.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_usage.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_usage.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_usage.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_usage.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_visibility.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_visibility.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_model_visibility.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_model_visibility.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_additionalproperties.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_additionalproperties.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_additionalproperties.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_additionalproperties.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_nullable.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_nullable.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_nullable.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_nullable.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_optional.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_optional.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_optional.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_optional.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_valuetypes.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_valuetypes.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_property_valuetypes.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_property_valuetypes.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_scalar.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_scalar.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_scalar.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_scalar.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_union.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_union.py similarity index 100% rename from packages/http-client-python/generator/test/azure/mock_api_tests/test_typetest_union.py rename to packages/http-client-python/generator/test/generic_mock_api_tests/test_typetest_union.py diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_array_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_array_async.py deleted file mode 100644 index 7eef2728053..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_array_async.py +++ /dev/null @@ -1,118 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 isodate -from type.array.aio import ArrayClient -from type.array import models - - -@pytest.fixture -async def client(): - async with ArrayClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_boolean_value(client: ArrayClient): - assert await client.boolean_value.get() == [True, False] - await client.boolean_value.put([True, False]) - - -@pytest.mark.asyncio -async def test_datetime_value(client: ArrayClient): - assert await client.datetime_value.get() == [isodate.parse_datetime("2022-08-26T18:38:00Z")] - await client.datetime_value.put([isodate.parse_datetime("2022-08-26T18:38:00Z")]) - - -@pytest.mark.asyncio -async def test_duration_value(client: ArrayClient): - assert await client.duration_value.get() == [isodate.parse_duration("P123DT22H14M12.011S")] - await client.duration_value.put([isodate.parse_duration("P123DT22H14M12.011S")]) - - -@pytest.mark.asyncio -async def test_float32_value(client: ArrayClient): - assert await client.float32_value.get() == [43.125] - await client.float32_value.put([43.125]) - - -@pytest.mark.asyncio -async def test_int32_value(client: ArrayClient): - assert await client.int32_value.get() == [1, 2] - await client.int32_value.put([1, 2]) - - -@pytest.mark.asyncio -async def test_int64_value(client: ArrayClient): - assert await client.int64_value.get() == [2**53 - 1, -(2**53 - 1)] - await client.int64_value.put([2**53 - 1, -(2**53 - 1)]) - - -@pytest.mark.asyncio -async def test_model_value(client: ArrayClient): - assert await client.model_value.get() == [ - models.InnerModel(property="hello"), - models.InnerModel(property="world"), - ] - await client.model_value.put( - [ - models.InnerModel(property="hello"), - models.InnerModel(property="world"), - ] - ) - - -@pytest.mark.asyncio -async def test_nullable_boolean_value(client: ArrayClient): - assert await client.nullable_boolean_value.get() == [True, None, False] - await client.nullable_boolean_value.put([True, None, False]) - - -@pytest.mark.asyncio -async def test_nullable_float_value(client: ArrayClient): - assert await client.nullable_float_value.get() == [1.25, None, 3.0] - await client.nullable_float_value.put([1.25, None, 3.0]) - - -@pytest.mark.asyncio -async def test_nullable_int32_value(client: ArrayClient): - assert await client.nullable_int32_value.get() == [1, None, 3] - await client.nullable_int32_value.put([1, None, 3]) - - -@pytest.mark.asyncio -async def test_nullable_model_value(client: ArrayClient): - assert await client.nullable_model_value.get() == [ - models.InnerModel(property="hello"), - None, - models.InnerModel(property="world"), - ] - await client.nullable_model_value.put( - [ - models.InnerModel(property="hello"), - None, - models.InnerModel(property="world"), - ] - ) - - -@pytest.mark.asyncio -async def test_nullable_string_value(client: ArrayClient): - assert await client.nullable_string_value.get() == ["hello", None, "world"] - await client.nullable_string_value.put(["hello", None, "world"]) - - -@pytest.mark.asyncio -async def test_string_value(client: ArrayClient): - assert await client.string_value.get() == ["hello", ""] - await client.string_value.put(["hello", ""]) - - -@pytest.mark.asyncio -async def test_unknown_value(client: ArrayClient): - assert await client.unknown_value.get() == [1, "hello", None] - await client.unknown_value.put([1, "hello", None]) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_dictionary_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_dictionary_async.py deleted file mode 100644 index 337334315b8..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_dictionary_async.py +++ /dev/null @@ -1,98 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.dictionary import models -from type.dictionary.aio import DictionaryClient -import isodate - - -@pytest.fixture -async def client(): - async with DictionaryClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_boolean_value(client: DictionaryClient): - value = {"k1": True, "k2": False} - assert await client.boolean_value.get() == value - await client.boolean_value.put(value) - - -@pytest.mark.asyncio -async def test_datetime_value(client: DictionaryClient): - value = {"k1": isodate.parse_datetime("2022-08-26T18:38:00Z")} - assert await client.datetime_value.get() == value - await client.datetime_value.put(value) - - -@pytest.mark.asyncio -async def test_duration_value(client: DictionaryClient): - value = {"k1": isodate.parse_duration("P123DT22H14M12.011S")} - assert await client.duration_value.get() == value - await client.duration_value.put(value) - - -@pytest.mark.asyncio -async def test_float32_value(client: DictionaryClient): - value = {"k1": 43.125} - assert await client.float32_value.get() == value - await client.float32_value.put(value) - - -@pytest.mark.asyncio -async def test_int32_value(client: DictionaryClient): - value = {"k1": 1, "k2": 2} - assert await client.int32_value.get() == value - await client.int32_value.put(value) - - -@pytest.mark.asyncio -async def test_int64_value(client: DictionaryClient): - value = {"k1": 2**53 - 1, "k2": -(2**53 - 1)} - assert await client.int64_value.get() == value - await client.int64_value.put(value) - - -@pytest.mark.asyncio -async def test_model_value(client: DictionaryClient): - value = { - "k1": models.InnerModel(property="hello"), - "k2": models.InnerModel(property="world"), - } - assert await client.model_value.get() == value - await client.model_value.put(value) - - -@pytest.mark.asyncio -async def test_nullable_float_value(client: DictionaryClient): - value = {"k1": 1.25, "k2": 0.5, "k3": None} - assert await client.nullable_float_value.get() == value - await client.nullable_float_value.put(value) - - -@pytest.mark.asyncio -async def test_recursive_model_value(client: DictionaryClient): - value = { - "k1": models.InnerModel(property="hello", children={}), - "k2": models.InnerModel(property="world", children={"k2.1": models.InnerModel(property="inner world")}), - } - assert await client.recursive_model_value.get() == value - await client.recursive_model_value.put(value) - - -@pytest.mark.asyncio -async def test_string_value(client: DictionaryClient): - value = {"k1": "hello", "k2": ""} - assert await client.string_value.get() == value - await client.string_value.put(value) - - -@pytest.mark.asyncio -async def test_unknown_value(client: DictionaryClient): - value = {"k1": 1, "k2": "hello", "k3": None} - assert await client.unknown_value.get() == value - await client.unknown_value.put(value) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py deleted file mode 100644 index 7fdbb6794d3..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_extensible_async.py +++ /dev/null @@ -1,25 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.enum.extensible import models, aio - - -@pytest.fixture -async def client(): - async with aio.ExtensibleClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_known_value(client): - assert await client.string.get_known_value() == models.DaysOfWeekExtensibleEnum.MONDAY - await client.string.put_known_value(models.DaysOfWeekExtensibleEnum.MONDAY) - - -@pytest.mark.asyncio -async def test_unknown_value(client): - assert await client.string.get_unknown_value() == "Weekend" - await client.string.put_unknown_value("Weekend") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py deleted file mode 100644 index 2669fbf4884..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_enum_fixed_async.py +++ /dev/null @@ -1,28 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.enum.fixed import aio, models -from corehttp.exceptions import HttpResponseError - - -@pytest.fixture -async def client(): - async with aio.FixedClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_known_value(client): - assert await client.string.get_known_value() == models.DaysOfWeekEnum.MONDAY - await client.string.put_known_value(models.DaysOfWeekEnum.MONDAY) - - -@pytest.mark.asyncio -async def test_unknown_value(client: aio.FixedClient): - try: - await client.string.put_unknown_value("Weekend") - except HttpResponseError as err: - assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_empty_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_empty_async.py deleted file mode 100644 index f954d70fe8f..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_empty_async.py +++ /dev/null @@ -1,32 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.empty.aio import EmptyClient -from type.model.empty.models import EmptyInput, EmptyOutput, EmptyInputOutput - - -@pytest.fixture -async def client(): - async with EmptyClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_put(client: EmptyClient): - await client.put_empty(EmptyInput()) - await client.put_empty({}) - - -@pytest.mark.asyncio -async def test_get(client: EmptyClient): - assert await client.get_empty() == EmptyOutput() - assert await client.get_empty() == {} - - -@pytest.mark.asyncio -async def test_post_round(client: EmptyClient): - assert await client.post_round_trip_empty(EmptyInputOutput()) == EmptyInputOutput() - assert await client.post_round_trip_empty({}) == {} diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py deleted file mode 100644 index 6c24c89f1f2..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_enum_discriminator_async.py +++ /dev/null @@ -1,70 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.enumdiscriminator.aio import EnumDiscriminatorClient -from type.model.inheritance.enumdiscriminator import models - - -@pytest.fixture -async def client(): - async with EnumDiscriminatorClient() as client: - yield client - - -@pytest.fixture -def valid_body(): - return models.Golden(weight=10) - - -@pytest.fixture -def valid_fixed_body(): - return models.Cobra(length=10) - - -@pytest.mark.asyncio -async def test_get_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): - assert await client.get_extensible_model() == valid_body - assert isinstance(await client.get_extensible_model(), models.Golden) - - -@pytest.mark.asyncio -async def test_put_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): - await client.put_extensible_model(valid_body) - - -@pytest.mark.asyncio -async def test_get_extensible_model_missing_discriminator( - client: EnumDiscriminatorClient, -): - assert await client.get_extensible_model_missing_discriminator() == models.Dog(weight=10) - - -@pytest.mark.asyncio -async def test_get_extensible_model_wrong_discriminator( - client: EnumDiscriminatorClient, -): - assert await client.get_extensible_model_wrong_discriminator() == models.Dog(weight=8, kind="wrongKind") - - -@pytest.mark.asyncio -async def test_get_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): - assert await client.get_fixed_model() == valid_fixed_body - assert isinstance(await client.get_fixed_model(), models.Cobra) - - -@pytest.mark.asyncio -async def test_put_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): - await client.put_fixed_model(valid_fixed_body) - - -@pytest.mark.asyncio -async def test_get_fixed_model_missing_discriminator(client: EnumDiscriminatorClient): - assert await client.get_fixed_model_missing_discriminator() == models.Snake(length=10) - - -@pytest.mark.asyncio -async def test_get_fixed_model_wrong_discriminator(client: EnumDiscriminatorClient): - assert await client.get_fixed_model_wrong_discriminator() == models.Snake(length=8, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py deleted file mode 100644 index a308164bc15..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_nested_discriminator_async.py +++ /dev/null @@ -1,85 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.nesteddiscriminator.aio import NestedDiscriminatorClient -from type.model.inheritance.nesteddiscriminator.models import GoblinShark, Salmon, Fish - - -@pytest.fixture -async def client(): - async with NestedDiscriminatorClient() as client: - yield client - - -@pytest.fixture -async def valid_body(): - return GoblinShark(age=1) - - -@pytest.mark.asyncio -async def test_get_model(client, valid_body): - assert await client.get_model() == valid_body - assert isinstance(await client.get_model(), GoblinShark) - - -@pytest.mark.asyncio -async def test_put_model(client, valid_body): - await client.put_model(valid_body) - - -@pytest.fixture -async def valid_recursive_body(): - return Salmon( - { - "age": 1, - "kind": "salmon", - "partner": {"age": 2, "kind": "shark", "sharktype": "saw"}, - "friends": [ - { - "age": 2, - "kind": "salmon", - "partner": {"age": 3, "kind": "salmon"}, - "hate": { - "key1": {"age": 4, "kind": "salmon"}, - "key2": {"age": 2, "kind": "shark", "sharktype": "goblin"}, - }, - }, - {"age": 3, "kind": "shark", "sharktype": "goblin"}, - ], - "hate": { - "key3": {"age": 3, "kind": "shark", "sharktype": "saw"}, - "key4": { - "age": 2, - "kind": "salmon", - "friends": [ - {"age": 1, "kind": "salmon"}, - {"age": 4, "kind": "shark", "sharktype": "goblin"}, - ], - }, - }, - } - ) - - -@pytest.mark.asyncio -async def test_get_recursive_model(client, valid_recursive_body): - assert valid_recursive_body == await client.get_recursive_model() - assert isinstance(await client.get_recursive_model(), Salmon) - - -@pytest.mark.asyncio -async def test_put_recursive_model(client, valid_recursive_body): - await client.put_recursive_model(valid_recursive_body) - - -@pytest.mark.asyncio -async def test_get_missing_discriminator(client): - assert await client.get_missing_discriminator() == Fish(age=1) - - -@pytest.mark.asyncio -async def test_get_wrong_discriminator(client): - assert await client.get_wrong_discriminator() == Fish(age=1, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py deleted file mode 100644 index bcb16b645ca..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_not_discriminated_async.py +++ /dev/null @@ -1,34 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.notdiscriminated.aio import NotDiscriminatedClient -from type.model.inheritance.notdiscriminated.models import Siamese - - -@pytest.fixture -async def client(): - async with NotDiscriminatedClient() as client: - yield client - - -@pytest.fixture -async def valid_body(): - return Siamese(name="abc", age=32, smart=True) - - -@pytest.mark.asyncio -async def test_get_valid(client, valid_body): - assert await client.get_valid() == valid_body - - -@pytest.mark.asyncio -async def test_post_valid(client, valid_body): - await client.post_valid(valid_body) - - -@pytest.mark.asyncio -async def test_put_valid(client, valid_body): - assert valid_body == await client.put_valid(valid_body) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py deleted file mode 100644 index 0f8192ac76d..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_recursive_async.py +++ /dev/null @@ -1,34 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.recursive.aio import RecursiveClient -from type.model.inheritance.recursive.models import Extension - - -@pytest.fixture -async def client(): - async with RecursiveClient() as client: - yield client - - -@pytest.fixture -async def expected(): - return Extension( - { - "level": 0, - "extension": [{"level": 1, "extension": [{"level": 2}]}, {"level": 1}], - } - ) - - -@pytest.mark.asyncio -async def test_put(client: RecursiveClient, expected: Extension): - await client.put(expected) - - -@pytest.mark.asyncio -async def test_get(client: RecursiveClient, expected: Extension): - assert await client.get() == expected diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py deleted file mode 100644 index 9e6767e8611..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_inheritance_single_discriminator_async.py +++ /dev/null @@ -1,67 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.singlediscriminator.aio import SingleDiscriminatorClient -from type.model.inheritance.singlediscriminator.models import Sparrow, Eagle, Bird, Dinosaur - - -@pytest.fixture -async def client(): - async with SingleDiscriminatorClient() as client: - yield client - - -@pytest.fixture -async def valid_body(): - return Sparrow(wingspan=1) - - -@pytest.mark.asyncio -async def test_get_model(client, valid_body): - assert await client.get_model() == valid_body - - -@pytest.mark.asyncio -async def test_put_model(client, valid_body): - await client.put_model(valid_body) - - -@pytest.fixture -async def recursive_body(): - return Eagle( - { - "wingspan": 5, - "kind": "eagle", - "partner": {"wingspan": 2, "kind": "goose"}, - "friends": [{"wingspan": 2, "kind": "seagull"}], - "hate": {"key3": {"wingspan": 1, "kind": "sparrow"}}, - } - ) - - -@pytest.mark.asyncio -async def test_get_recursive_model(client, recursive_body): - assert await client.get_recursive_model() == recursive_body - - -@pytest.mark.asyncio -async def test_put_recursive_model(client, recursive_body): - await client.put_recursive_model(recursive_body) - - -@pytest.mark.asyncio -async def test_get_missing_discriminator(client): - assert await client.get_missing_discriminator() == Bird(wingspan=1) - - -@pytest.mark.asyncio -async def test_get_wrong_discriminator(client): - assert await client.get_wrong_discriminator() == Bird(wingspan=1, kind="wrongKind") - - -@pytest.mark.asyncio -async def test_get_legacy_model(client): - assert await client.get_legacy_model() == Dinosaur(size=20, kind="t-rex") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_usage_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_usage_async.py deleted file mode 100644 index 342dea20f28..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_usage_async.py +++ /dev/null @@ -1,32 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.usage import models -from type.model.usage.aio import UsageClient - - -@pytest.fixture -async def client(): - async with UsageClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_input(client: UsageClient): - input = models.InputRecord(required_prop="example-value") - assert await client.input(input) is None - - -@pytest.mark.asyncio -async def test_output(client: UsageClient): - output = models.OutputRecord(required_prop="example-value") - assert output == await client.output() - - -@pytest.mark.asyncio -async def test_input_and_output(client: UsageClient): - input_output = models.InputOutputRecord(required_prop="example-value") - assert input_output == await client.input_and_output(input_output) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_visibility_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_visibility_async.py deleted file mode 100644 index 5d5162b806e..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_model_visibility_async.py +++ /dev/null @@ -1,47 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.visibility.aio import VisibilityClient -from type.model.visibility import models - - -@pytest.fixture -async def client(): - async with VisibilityClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_get_model(client): - result = await client.get_model(models.VisibilityModel(query_prop=123)) - assert result == models.VisibilityModel(read_prop="abc") - - -@pytest.mark.asyncio -async def test_put_model(client): - await client.put_model(models.VisibilityModel(create_prop=["foo", "bar"], update_prop=[1, 2])) - - -@pytest.mark.asyncio -async def test_patch_model(client): - await client.patch_model(models.VisibilityModel(update_prop=[1, 2])) - - -@pytest.mark.asyncio -async def test_post_model(client): - await client.post_model(models.VisibilityModel(create_prop=["foo", "bar"])) - - -@pytest.mark.asyncio -async def test_delete_model(client): - await client.delete_model(models.VisibilityModel(delete_prop=True)) - - -@pytest.mark.asyncio -async def test_put_read_only_model(client): - await client.put_read_only_model( - models.ReadOnlyModel(optional_nullable_int_list=[1, 2], optional_string_record={"foo", "bar"}) - ) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py deleted file mode 100644 index 3c8638c0a14..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_additionalproperties_async.py +++ /dev/null @@ -1,352 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.property.additionalproperties import models -from type.property.additionalproperties.aio import AdditionalPropertiesClient - - -@pytest.fixture -async def client(): - async with AdditionalPropertiesClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_extends_different_spread_float(client: AdditionalPropertiesClient): - body = models.DifferentSpreadFloatDerived({"name": "abc", "prop": 43.125, "derivedProp": 43.125}) - assert await client.extends_different_spread_float.get() == body - await client.extends_different_spread_float.put(body) - - -@pytest.mark.asyncio -async def test_extends_different_spread_model(client: AdditionalPropertiesClient): - body = models.DifferentSpreadModelDerived( - {"knownProp": "abc", "prop": {"state": "ok"}, "derivedProp": {"state": "ok"}} - ) - assert await client.extends_different_spread_model.get() == body - await client.extends_different_spread_model.put(body) - - -@pytest.mark.asyncio -async def test_extends_different_spread_model_array(client: AdditionalPropertiesClient): - body = models.DifferentSpreadModelArrayDerived( - { - "knownProp": "abc", - "prop": [{"state": "ok"}, {"state": "ok"}], - "derivedProp": [{"state": "ok"}, {"state": "ok"}], - } - ) - assert await client.extends_different_spread_model_array.get() == body - await client.extends_different_spread_model_array.put(body) - - -@pytest.mark.asyncio -async def test_extends_different_spread_string(client: AdditionalPropertiesClient): - body = models.DifferentSpreadStringDerived({"id": 43.125, "prop": "abc", "derivedProp": "abc"}) - assert await client.extends_different_spread_string.get() == body - await client.extends_different_spread_string.put(body) - - -@pytest.mark.asyncio -async def test_extends_float(client: AdditionalPropertiesClient): - body = models.ExtendsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) - assert await client.extends_float.get() == body - await client.extends_float.put(body) - - -@pytest.mark.asyncio -async def test_extends_model(client: AdditionalPropertiesClient): - body = models.ExtendsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) - assert await client.extends_model.get() == body - await client.extends_model.put(body) - - -@pytest.mark.asyncio -async def test_extends_model_array(client: AdditionalPropertiesClient): - body = models.ExtendsModelArrayAdditionalProperties( - { - "knownProp": [{"state": "ok"}, {"state": "ok"}], - "prop": [{"state": "ok"}, {"state": "ok"}], - } - ) - assert await client.extends_model_array.get() == body - await client.extends_model_array.put(body) - - -@pytest.mark.asyncio -async def test_extends_string(client: AdditionalPropertiesClient): - body = models.ExtendsStringAdditionalProperties({"name": "ExtendsStringAdditionalProperties", "prop": "abc"}) - assert await client.extends_string.get() == body - await client.extends_string.put(body) - - -@pytest.mark.asyncio -async def test_extends_unknown(client: AdditionalPropertiesClient): - body = models.ExtendsUnknownAdditionalProperties( - { - "name": "ExtendsUnknownAdditionalProperties", - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.extends_unknown.get() == body - await client.extends_unknown.put(body) - - -@pytest.mark.asyncio -async def test_extends_unknown_derived(client: AdditionalPropertiesClient): - body = models.ExtendsUnknownAdditionalPropertiesDerived( - { - "name": "ExtendsUnknownAdditionalProperties", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.extends_unknown_derived.get() == body - await client.extends_unknown_derived.put(body) - - -@pytest.mark.asyncio -async def test_extends_unknown_discriminated(client: AdditionalPropertiesClient): - body = models.ExtendsUnknownAdditionalPropertiesDiscriminatedDerived( - { - "kind": "derived", - "name": "Derived", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.extends_unknown_discriminated.get() == body - await client.extends_unknown_discriminated.put(body) - - -@pytest.mark.asyncio -async def test_is_float(client: AdditionalPropertiesClient): - body = models.IsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) - assert await client.is_float.get() == body - await client.is_float.put(body) - - -@pytest.mark.asyncio -async def test_is_model(client: AdditionalPropertiesClient): - body = models.IsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) - assert await client.is_model.get() == body - await client.is_model.put(body) - - -@pytest.mark.asyncio -async def test_is_model_array(client: AdditionalPropertiesClient): - body = models.IsModelArrayAdditionalProperties( - { - "knownProp": [{"state": "ok"}, {"state": "ok"}], - "prop": [{"state": "ok"}, {"state": "ok"}], - } - ) - assert await client.is_model_array.get() == body - await client.is_model_array.put(body) - - -@pytest.mark.asyncio -async def test_is_string(client: AdditionalPropertiesClient): - body = models.IsStringAdditionalProperties({"name": "IsStringAdditionalProperties", "prop": "abc"}) - assert await client.is_string.get() == body - await client.is_string.put(body) - - -@pytest.mark.asyncio -async def test_is_unknown(client: AdditionalPropertiesClient): - body = models.IsUnknownAdditionalProperties( - { - "name": "IsUnknownAdditionalProperties", - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.is_unknown.get() == body - await client.is_unknown.put(body) - - -@pytest.mark.asyncio -async def test_is_unknown_derived(client: AdditionalPropertiesClient): - body = models.IsUnknownAdditionalPropertiesDerived( - { - "name": "IsUnknownAdditionalProperties", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.is_unknown_derived.get() == body - await client.is_unknown_derived.put(body) - - -@pytest.mark.asyncio -async def test_is_unknown_discriminated(client: AdditionalPropertiesClient): - body = models.IsUnknownAdditionalPropertiesDiscriminatedDerived( - { - "kind": "derived", - "name": "Derived", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert await client.is_unknown_discriminated.get() == body - await client.is_unknown_discriminated.put(body) - - -@pytest.mark.asyncio -async def test_multiple_spread(client: AdditionalPropertiesClient): - body = {"flag": True, "prop1": "abc", "prop2": 43.125} - assert await client.multiple_spread.get() == body - await client.multiple_spread.put(body) - - -@pytest.mark.asyncio -async def test_spread_different_float(client: AdditionalPropertiesClient): - body = {"name": "abc", "prop": 43.125} - assert await client.spread_different_float.get() == body - await client.spread_different_float.put(body) - - -@pytest.mark.asyncio -async def test_spread_different_model(client: AdditionalPropertiesClient): - body = {"knownProp": "abc", "prop": {"state": "ok"}} - assert await client.spread_different_model.get() == body - await client.spread_different_model.put(body) - - -@pytest.mark.asyncio -async def test_spread_different_model_array(client: AdditionalPropertiesClient): - body = {"knownProp": "abc", "prop": [{"state": "ok"}, {"state": "ok"}]} - assert await client.spread_different_model_array.get() == body - await client.spread_different_model_array.put(body) - - -@pytest.mark.asyncio -async def test_spread_different_string(client: AdditionalPropertiesClient): - body = {"id": 43.125, "prop": "abc"} - assert await client.spread_different_string.get() == body - await client.spread_different_string.put(body) - - -@pytest.mark.asyncio -async def test_spread_model(client: AdditionalPropertiesClient): - body = {"knownProp": {"state": "ok"}, "prop": {"state": "ok"}} - assert await client.spread_model.get() == body - await client.spread_model.put(body) - - -@pytest.mark.asyncio -async def test_spread_model_array(client: AdditionalPropertiesClient): - body = { - "knownProp": [{"state": "ok"}, {"state": "ok"}], - "prop": [{"state": "ok"}, {"state": "ok"}], - } - assert await client.spread_model_array.get() == body - await client.spread_model_array.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_discriminated_union(client: AdditionalPropertiesClient): - body = { - "name": "abc", - "prop1": {"fooProp": "abc", "kind": "kind0"}, - "prop2": { - "end": "2021-01-02T00:00:00Z", - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - }, - } - assert await client.spread_record_discriminated_union.get() == body - await client.spread_record_discriminated_union.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_non_discriminated_union( - client: AdditionalPropertiesClient, -): - body = { - "name": "abc", - "prop1": {"kind": "kind0", "fooProp": "abc"}, - "prop2": { - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - "end": "2021-01-02T00:00:00Z", - }, - } - assert await client.spread_record_non_discriminated_union.get() == body - await client.spread_record_non_discriminated_union.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_non_discriminated_union2( - client: AdditionalPropertiesClient, -): - body = { - "name": "abc", - "prop1": {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, - "prop2": { - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - "end": "2021-01-02T00:00:00Z", - }, - } - assert await client.spread_record_non_discriminated_union2.get() == body - await client.spread_record_non_discriminated_union2.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_non_discriminated_union3( - client: AdditionalPropertiesClient, -): - body = { - "name": "abc", - "prop1": [ - {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, - {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, - ], - "prop2": { - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - "end": "2021-01-02T00:00:00Z", - }, - } - assert await client.spread_record_non_discriminated_union3.get() == body - await client.spread_record_non_discriminated_union3.put(body) - - -@pytest.mark.asyncio -async def test_spread_record_union(client: AdditionalPropertiesClient): - body = {"flag": True, "prop1": "abc", "prop2": 43.125} - assert await client.spread_record_union.get() == body - await client.spread_record_union.put(body) - - -@pytest.mark.asyncio -async def test_spread_string(client: AdditionalPropertiesClient): - body = {"name": "SpreadSpringRecord", "prop": "abc"} - assert await client.spread_string.get() == body - await client.spread_string.put(body) - - -@pytest.mark.asyncio -async def test_spread_float(client: AdditionalPropertiesClient): - body = {"id": 43.125, "prop": 43.125} - assert await client.spread_float.get() == body - await client.spread_float.put(body) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_nullable_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_nullable_async.py deleted file mode 100644 index 70eeaf4e612..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_nullable_async.py +++ /dev/null @@ -1,110 +0,0 @@ -# cspell: ignore Hdvcmxk -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import json -import pytest -from type.property.nullable import models -from type.property.nullable.aio import NullableClient -from type.property.nullable._model_base import ( # pylint: disable=protected-access - SdkJSONEncoder, -) - -try: - from corehttp.serialization import NULL -except ImportError: - from azure.core.serialization import NULL - - -@pytest.fixture -async def client(): - async with NullableClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_bytes(client: NullableClient): - non_null_model = models.BytesProperty(required_property="foo", nullable_property="aGVsbG8sIHdvcmxkIQ==") - non_model = models.BytesProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.bytes.get_non_null() == non_null_model - assert (await client.bytes.get_null())["nullableProperty"] is None - await client.bytes.patch_non_null(body=non_null_model) - await client.bytes.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_collections_byte(client: NullableClient): - non_null_model = models.CollectionsByteProperty( - required_property="foo", - nullable_property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="], - ) - non_model = models.CollectionsByteProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.collections_byte.get_non_null() == non_null_model - assert (await client.collections_byte.get_null())["nullableProperty"] is None - await client.collections_byte.patch_non_null(body=non_null_model) - await client.collections_byte.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_collections_model(client: NullableClient): - non_null_model = models.CollectionsModelProperty( - required_property="foo", - nullable_property=[ - models.InnerModel(property="hello"), - models.InnerModel(property="world"), - ], - ) - non_model = models.CollectionsModelProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.collections_model.get_non_null() == non_null_model - assert (await client.collections_model.get_null())["nullableProperty"] is None - await client.collections_model.patch_non_null(body=non_null_model) - await client.collections_model.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_collections_string(client: NullableClient): - non_null_model = models.CollectionsStringProperty(required_property="foo", nullable_property=["hello", "world"]) - non_model = models.CollectionsStringProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.collections_string.get_non_null() == non_null_model - assert (await client.collections_string.get_null())["nullableProperty"] is None - await client.collections_string.patch_non_null(body=non_null_model) - await client.collections_string.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_datetime(client: NullableClient): - non_null_model = models.DatetimeProperty(required_property="foo", nullable_property="2022-08-26T18:38:00Z") - non_model = models.DatetimeProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.datetime.get_non_null() == non_null_model - assert (await client.datetime.get_null())["nullableProperty"] is None - await client.datetime.patch_non_null(body=non_null_model) - await client.datetime.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_duration(client: NullableClient): - non_null_model = models.DurationProperty(required_property="foo", nullable_property="P123DT22H14M12.011S") - non_model = models.DurationProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.duration.get_non_null() == non_null_model - assert (await client.duration.get_null())["nullableProperty"] is None - await client.duration.patch_non_null(body=non_null_model) - await client.duration.patch_null(body=non_model) - - -@pytest.mark.asyncio -async def test_string(client: NullableClient): - non_null_model = models.StringProperty(required_property="foo", nullable_property="hello") - non_model = models.StringProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert await client.string.get_non_null() == non_null_model - assert (await client.string.get_null())["nullableProperty"] is None - await client.string.patch_non_null(body=non_null_model) - await client.string.patch_null(body=non_model) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_optional_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_optional_async.py deleted file mode 100644 index bfa3dc80f13..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_optional_async.py +++ /dev/null @@ -1,197 +0,0 @@ -# cspell: ignore Hdvcmxk -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import Any -import pytest -from type.property.optional import models -from type.property.optional.aio import OptionalClient - - -@pytest.fixture -async def client(): - async with OptionalClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_boolean_literal(client): - body = models.BooleanLiteralProperty(property=True) - assert await client.boolean_literal.get_all() == body - assert await client.boolean_literal.get_default() == models.BooleanLiteralProperty() - await client.boolean_literal.put_all(body) - await client.boolean_literal.put_default(models.BooleanLiteralProperty()) - - -@pytest.mark.asyncio -async def test_bytes(client): - body = models.BytesProperty(property="aGVsbG8sIHdvcmxkIQ==") - assert await client.bytes.get_all() == body - assert await client.bytes.get_default() == models.BytesProperty() - await client.bytes.put_all(body) - await client.bytes.put_default(models.BytesProperty()) - - -@pytest.mark.asyncio -async def test_collections_byte(client): - body = models.CollectionsByteProperty(property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="]) - assert await client.collections_byte.get_all() == body - assert await client.collections_byte.get_default() == models.CollectionsByteProperty() - await client.collections_byte.put_all(body) - await client.collections_byte.put_default(models.CollectionsByteProperty()) - - -@pytest.mark.asyncio -async def test_collections_model(client): - body = models.CollectionsModelProperty( - property=[ - models.StringProperty(property="hello"), - models.StringProperty(property="world"), - ] - ) - assert await client.collections_model.get_all() == body - assert await client.collections_model.get_default() == models.CollectionsModelProperty() - await client.collections_model.put_all(body) - await client.collections_model.put_default(models.CollectionsModelProperty()) - - -@pytest.mark.asyncio -async def test_datetime(client): - body = models.DatetimeProperty(property="2022-08-26T18:38:00Z") - assert await client.datetime.get_all() == body - assert await client.datetime.get_default() == models.DatetimeProperty() - await client.datetime.put_all(body) - await client.datetime.put_default(models.DatetimeProperty()) - - -@pytest.mark.asyncio -async def test_duration(client): - body = models.DurationProperty(property="P123DT22H14M12.011S") - assert await client.duration.get_all() == body - assert await client.duration.get_default() == models.DurationProperty() - await client.duration.put_all(body) - await client.duration.put_default(models.DurationProperty()) - - -@pytest.mark.asyncio -async def test_float_literal(client): - body = models.FloatLiteralProperty(property=1.25) - assert await client.float_literal.get_all() == body - assert await client.float_literal.get_default() == models.FloatLiteralProperty() - await client.float_literal.put_all(body) - await client.float_literal.put_default(models.FloatLiteralProperty()) - - -@pytest.mark.asyncio -async def test_int_literal(client): - body = models.IntLiteralProperty(property=1) - assert await client.int_literal.get_all() == body - assert await client.int_literal.get_default() == models.IntLiteralProperty() - await client.int_literal.put_all(body) - await client.int_literal.put_default(models.IntLiteralProperty()) - - -@pytest.mark.asyncio -async def test_plaindate(client): - body = models.PlainDateProperty(property="2022-12-12") - assert await client.plain_date.get_all() == body - - -@pytest.mark.asyncio -async def test_plaindate(client): - assert await client.plain_date.get_default() == models.PlainDateProperty() - - -@pytest.mark.asyncio -async def test_plaindate(client): - body = models.PlainDateProperty(property="2022-12-12") - await client.plain_date.put_all(body) - - -@pytest.mark.asyncio -async def test_plaindate(client): - await client.plain_date.put_default(models.PlainDateProperty()) - - -@pytest.mark.asyncio -async def test_plaintime(client): - body = models.PlainTimeProperty(property="13:06:12") - assert await client.plain_time.get_all() == body - - -@pytest.mark.asyncio -async def test_plaintime(client): - assert await client.plain_time.get_default() == models.PlainTimeProperty() - - -@pytest.mark.asyncio -async def test_plaintime(client): - body = models.PlainTimeProperty(property="13:06:12") - await client.plain_time.put_all(body) - - -@pytest.mark.asyncio -async def test_plaintime(client): - await client.plain_time.put_default(models.PlainTimeProperty()) - - -@pytest.mark.asyncio -async def test_required_and_optional(client): - all_body = { - "optionalProperty": "hello", - "requiredProperty": 42, - } - required_only_body = { - "requiredProperty": 42, - } - assert await client.required_and_optional.get_all() == all_body - assert await client.required_and_optional.get_required_only() == required_only_body - await client.required_and_optional.put_all(all_body) - await client.required_and_optional.put_required_only(required_only_body) - - -@pytest.mark.asyncio -async def test_string(client): - body = models.StringProperty(property="hello") - assert await client.string.get_all() == body - assert await client.string.get_default() == models.StringProperty() - await client.string.put_all(body) - await client.string.put_default(models.StringProperty()) - - -@pytest.mark.asyncio -async def test_string_literal(client): - body = models.StringLiteralProperty(property="hello") - assert await client.string_literal.get_all() == body - assert await client.string_literal.get_default() == models.StringLiteralProperty() - await client.string_literal.put_all(body) - await client.string_literal.put_default(models.StringLiteralProperty()) - - -@pytest.mark.asyncio -async def test_union_float_literal(client): - body = models.UnionFloatLiteralProperty(property=2.375) - assert await client.union_float_literal.get_all() == body - assert await client.union_float_literal.get_default() == models.UnionFloatLiteralProperty() - await client.union_float_literal.put_all(body) - await client.union_float_literal.put_default(models.UnionFloatLiteralProperty()) - - -@pytest.mark.asyncio -async def test_union_int_literal(client): - body = models.UnionIntLiteralProperty(property=2) - assert await client.union_int_literal.get_all() == body - assert await client.union_int_literal.get_default() == models.UnionIntLiteralProperty() - await client.union_int_literal.put_all(body) - await client.union_int_literal.put_default(models.UnionIntLiteralProperty()) - - -@pytest.mark.asyncio -async def test_union_string_literal(client): - body = models.UnionStringLiteralProperty(property="world") - assert await client.union_string_literal.get_all() == body - assert await client.union_string_literal.get_default() == models.UnionStringLiteralProperty() - await client.union_string_literal.put_all(body) - await client.union_string_literal.put_default(models.UnionStringLiteralProperty()) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py deleted file mode 100644 index 97f5260f773..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_property_valuetypes_async.py +++ /dev/null @@ -1,315 +0,0 @@ -# cspell: ignore Hdvcmxk -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import decimal - -import pytest -import datetime -from type.property.valuetypes import models -from type.property.valuetypes.aio import ValueTypesClient - - -@pytest.fixture -async def client(): - async with ValueTypesClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_boolean(client: ValueTypesClient): - body = models.BooleanProperty(property=True) - assert body.property == body["property"] - await client.boolean.put(body) - - resp = await client.boolean.get() - assert resp.property == resp["property"] == True - - -@pytest.mark.asyncio -async def test_boolean_literal(client: ValueTypesClient): - body = models.BooleanLiteralProperty(property=True) - assert body.property == body["property"] - await client.boolean_literal.put(body) - - resp = await client.boolean_literal.get() - assert resp.property == resp["property"] == True - - -@pytest.mark.asyncio -async def test_bytes(client: ValueTypesClient): - body = models.BytesProperty(property=b"hello, world!") - assert body.property == b"hello, world!" - assert body["property"] == "aGVsbG8sIHdvcmxkIQ==" - await client.bytes.put(body) - - resp = await client.bytes.get() - assert resp.property == b"hello, world!" - assert resp["property"] == "aGVsbG8sIHdvcmxkIQ==" - - -@pytest.mark.asyncio -async def test_collections_int(client: ValueTypesClient): - body = models.CollectionsIntProperty(property=[1, 2]) - assert body.property == body["property"] - await client.collections_int.put(body) - - resp = await client.collections_int.get() - assert resp.property == resp["property"] == [1, 2] - - -@pytest.mark.asyncio -async def test_collections_model(client: ValueTypesClient): - body = models.CollectionsModelProperty(property=[{"property": "hello"}, {"property": "world"}]) - assert body.property[0].property == body["property"][0]["property"] - await client.collections_model.put(body) - - resp = await client.collections_model.get() - assert resp.property[1].property == resp["property"][1]["property"] - - -@pytest.mark.asyncio -async def test_collections_string(client: ValueTypesClient): - body = models.CollectionsStringProperty(property=["hello", "world"]) - assert body.property == body["property"] - await client.collections_string.put(body) - - resp = await client.collections_string.get() - assert resp.property == resp["property"] == ["hello", "world"] - - -@pytest.mark.asyncio -async def test_datetime(client): - received_body = await client.datetime.get() - assert received_body == {"property": "2022-08-26T18:38:00Z"} - assert received_body.property.year == 2022 - assert received_body.property.month == 8 - assert received_body.property.day == 26 - assert received_body.property.hour == 18 - assert received_body.property.minute == 38 - - await client.datetime.put(models.DatetimeProperty(property=datetime.datetime(2022, 8, 26, hour=18, minute=38))) - - -@pytest.mark.asyncio -async def test_decimal(client: ValueTypesClient): - body = models.DecimalProperty(property=decimal.Decimal("0.33333")) - assert body.property == decimal.Decimal("0.33333") - assert body["property"] == 0.33333 - await client.decimal.put(body) - - resp = await client.decimal.get() - assert resp.property == decimal.Decimal("0.33333") - assert resp["property"] == 0.33333 - - -@pytest.mark.asyncio -async def test_decimal128(client: ValueTypesClient): - body = models.Decimal128Property(property=decimal.Decimal("0.33333")) - assert body.property == decimal.Decimal("0.33333") - assert body["property"] == 0.33333 - await client.decimal128.put(body) - - resp = await client.decimal128.get() - assert resp.property == decimal.Decimal("0.33333") - assert resp["property"] == 0.33333 - - -@pytest.mark.asyncio -async def test_dictionary_string(client: ValueTypesClient): - body = models.DictionaryStringProperty(property={"k1": "hello", "k2": "world"}) - assert body.property == body["property"] - await client.dictionary_string.put(body) - - resp = await client.dictionary_string.get() - assert resp.property == resp["property"] == {"k1": "hello", "k2": "world"} - - -@pytest.mark.asyncio -async def test_duration(client: ValueTypesClient): - body = models.DurationProperty(property="P123DT22H14M12.011S") - assert body.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) - assert body["property"] == "P123DT22H14M12.011S" - await client.duration.put(body) - - resp = await client.duration.get() - assert resp.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) - assert resp["property"] == "P123DT22H14M12.011S" - - -@pytest.mark.asyncio -async def test_enum(client: ValueTypesClient): - body = models.EnumProperty(property=models.InnerEnum.VALUE_ONE) - assert body.property == body["property"] - await client.enum.put(body) - - resp = await client.enum.get() - assert resp.property == resp["property"] == "ValueOne" - - -@pytest.mark.asyncio -async def test_extensible_enum(client: ValueTypesClient): - body = models.ExtensibleEnumProperty(property="UnknownValue") - assert body.property == body["property"] - await client.extensible_enum.put(body) - - resp = await client.extensible_enum.get() - assert resp.property == resp["property"] == "UnknownValue" - - -@pytest.mark.asyncio -async def test_float(client: ValueTypesClient): - body = models.FloatProperty(property=43.125) - assert body.property == body["property"] - await client.float.put(body) - - resp = await client.float.get() - assert resp.property == resp["property"] == 43.125 - - -@pytest.mark.asyncio -async def test_float_literal(client: ValueTypesClient): - body = models.FloatLiteralProperty(property=43.125) - assert body.property == body["property"] - await client.float_literal.put(body) - - resp = await client.float_literal.get() - assert resp.property == resp["property"] == 43.125 - - -@pytest.mark.asyncio -async def test_int(client: ValueTypesClient): - body = models.IntProperty(property=42) - assert body.property == body["property"] - await client.int_operations.put(body) - - resp = await client.int_operations.get() - assert resp.property == resp["property"] == 42 - - -@pytest.mark.asyncio -async def test_int_literal(client: ValueTypesClient): - body = models.IntLiteralProperty(property=42) - assert body.property == body["property"] - await client.int_literal.put(body) - - resp = await client.int_literal.get() - assert resp.property == resp["property"] == 42 - - -@pytest.mark.asyncio -async def test_model(client: ValueTypesClient): - body = models.ModelProperty(property={"property": "hello"}) - assert body.property.property == body["property"]["property"] - await client.model.put(body) - - resp = await client.model.get() - assert resp.property.property == resp["property"]["property"] - - -@pytest.mark.asyncio -async def test_never(client: ValueTypesClient): - assert await client.never.get() == models.NeverProperty() - await client.never.put(models.NeverProperty()) - - -@pytest.mark.asyncio -async def test_string(client: ValueTypesClient): - body = models.StringProperty(property="hello") - assert body.property == body["property"] - await client.string.put(body) - - resp = await client.string.get() - assert resp.property == resp["property"] == "hello" - - -@pytest.mark.asyncio -async def test_string_literal(client: ValueTypesClient): - body = models.StringLiteralProperty(property="hello") - assert body.property == body["property"] - await client.string_literal.put(body) - - resp = await client.string_literal.get() - assert resp.property == resp["property"] == "hello" - - -@pytest.mark.asyncio -async def test_union_enum_value(client: ValueTypesClient): - body = models.UnionEnumValueProperty(property=models.ExtendedEnum.ENUM_VALUE2) - assert body.property == body["property"] - await client.union_enum_value.put(body) - - resp = await client.union_enum_value.get() - assert resp.property == resp["property"] == "value2" - - -@pytest.mark.asyncio -async def test_union_float_literal(client: ValueTypesClient): - body = models.UnionFloatLiteralProperty(property=46.875) - assert body.property == body["property"] - await client.union_float_literal.put(body) - - resp = await client.union_float_literal.get() - assert resp.property == resp["property"] == 46.875 - - -@pytest.mark.asyncio -async def test_union_int_literal(client: ValueTypesClient): - body = models.UnionIntLiteralProperty(property=42) - assert body.property == body["property"] - await client.union_int_literal.put(body) - - resp = await client.union_int_literal.get() - assert resp.property == resp["property"] == 42 - - -@pytest.mark.asyncio -async def test_union_string_literal(client: ValueTypesClient): - body = models.UnionStringLiteralProperty(property="world") - assert body.property == body["property"] - await client.union_string_literal.put(body) - - resp = await client.union_string_literal.get() - assert resp.property == resp["property"] == "world" - - -@pytest.mark.asyncio -async def test_unknown_array(client: ValueTypesClient): - body = models.UnknownArrayProperty(property=["hello", "world"]) - assert body.property == body["property"] - await client.unknown_array.put(body) - - resp = await client.unknown_array.get() - assert resp.property == resp["property"] == ["hello", "world"] - - -@pytest.mark.asyncio -async def test_unknown_dict(client: ValueTypesClient): - body = models.UnknownDictProperty(property={"k1": "hello", "k2": 42}) - assert body.property == body["property"] - await client.unknown_dict.put(body) - - resp = await client.unknown_dict.get() - assert resp.property == resp["property"] == {"k1": "hello", "k2": 42} - - -@pytest.mark.asyncio -async def test_unknown_int(client: ValueTypesClient): - body = models.UnknownIntProperty(property=42) - assert body.property == body["property"] - await client.unknown_int.put(body) - - resp = await client.unknown_int.get() - assert resp.property == resp["property"] == 42 - - -@pytest.mark.asyncio -async def test_unknown_string(client: ValueTypesClient): - body = models.UnknownStringProperty(property="hello") - assert body.property == body["property"] - await client.unknown_string.put(body) - - resp = await client.unknown_string.get() - assert resp.property == resp["property"] == "hello" diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_scalar_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_scalar_async.py deleted file mode 100644 index c0ccb293d5b..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_scalar_async.py +++ /dev/null @@ -1,60 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import decimal -from functools import reduce - -import pytest -from type.scalar.aio import ScalarClient - - -@pytest.fixture -async def client(): - async with ScalarClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_scalar_string(client: ScalarClient): - assert await client.string.get() == "test" - await client.string.put("test") - - -@pytest.mark.asyncio -async def test_scalar_boolean(client: ScalarClient): - assert await client.boolean.get() == True - await client.boolean.put(True) - - -@pytest.mark.asyncio -async def test_scalar_unknown(client: ScalarClient): - assert await client.unknown.get() == "test" - await client.unknown.put("test") - - -@pytest.mark.asyncio -async def test_decimal128_type(client: ScalarClient): - assert await client.decimal128_type.response_body() == decimal.Decimal("0.33333") - await client.decimal128_type.request_body(decimal.Decimal("0.33333")) - await client.decimal128_type.request_parameter(value=decimal.Decimal("0.33333")) - - -@pytest.mark.asyncio -async def test_decimal_type(client: ScalarClient): - assert await client.decimal_type.response_body() == decimal.Decimal("0.33333") - await client.decimal_type.request_body(decimal.Decimal("0.33333")) - await client.decimal_type.request_parameter(value=decimal.Decimal("0.33333")) - - -@pytest.mark.asyncio -async def test_decimal128_verify(client: ScalarClient): - prepare = await client.decimal128_verify.prepare_verify() - await client.decimal128_verify.verify(reduce(lambda x, y: x + y, prepare)) - - -@pytest.mark.asyncio -async def test_decimal_verify(client: ScalarClient): - prepare = await client.decimal_verify.prepare_verify() - await client.decimal_verify.verify(reduce(lambda x, y: x + y, prepare)) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_union_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_union_async.py deleted file mode 100644 index c85cf57407a..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_typetest_union_async.py +++ /dev/null @@ -1,90 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.union.aio import UnionClient -from type.union import models - - -@pytest.fixture -async def client(): - async with UnionClient() as client: - yield client - - -@pytest.mark.asyncio -async def test_enums_only(client: UnionClient): - value = models.EnumsOnlyCases(lr="right", ud="up") - assert (await client.enums_only.get()) == {"prop": value} - await client.enums_only.send(prop=value) - - -@pytest.mark.asyncio -async def test_floats_only(client: UnionClient): - value = 2.2 - assert (await client.floats_only.get()) == {"prop": value} - await client.floats_only.send(prop=value) - - -@pytest.mark.asyncio -async def test_ints_only(client: UnionClient): - value = 2 - assert (await client.ints_only.get()) == {"prop": value} - await client.ints_only.send(prop=value) - - -@pytest.mark.asyncio -async def test_mixed_literals(client: UnionClient): - value = models.MixedLiteralsCases(string_literal="a", int_literal=2, float_literal=3.3, boolean_literal=True) - assert (await client.mixed_literals.get()) == {"prop": value} - await client.mixed_literals.send(prop=value) - - -@pytest.mark.asyncio -async def test_mixed_types(client: UnionClient): - value = models.MixedTypesCases( - model=models.Cat(name="test"), - literal="a", - int_property=2, - boolean=True, - array=[models.Cat(name="test"), "a", 2, True], - ) - assert (await client.mixed_types.get()) == {"prop": value} - await client.mixed_types.send(prop=value) - - -@pytest.mark.asyncio -async def test_models_only(client: UnionClient): - value = models.Cat(name="test") - assert (await client.models_only.get()) == {"prop": value} - await client.models_only.send(prop=value) - - -@pytest.mark.asyncio -async def test_string_and_array(client: UnionClient): - value = models.StringAndArrayCases(string="test", array=["test1", "test2"]) - assert (await client.string_and_array.get()) == {"prop": value} - await client.string_and_array.send(prop=value) - - -@pytest.mark.asyncio -async def test_string_extensible(client: UnionClient): - value = "custom" - assert (await client.string_extensible.get()) == {"prop": value} - await client.string_extensible.send(prop=value) - - -@pytest.mark.asyncio -async def test_string_extensible_named(client: UnionClient): - value = "custom" - assert (await client.string_extensible_named.get()) == {"prop": value} - await client.string_extensible_named.send(prop=value) - - -@pytest.mark.asyncio -async def test_strings_only(client: UnionClient): - value = "b" - assert (await client.strings_only.get()) == {"prop": value} - await client.strings_only.send(prop=value) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py index c5dda175a7e..1ba8cc5750d 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_unbranded_async.py @@ -4,7 +4,7 @@ # ------------------------------------ import traceback import pytest -from type.scalar.aio import ScalarClient +from typetest.scalar.aio import ScalarClient from corehttp.exceptions import HttpResponseError diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_array.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_array.py deleted file mode 100644 index 1af3bc8e46b..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_array.py +++ /dev/null @@ -1,103 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 isodate -from type.array import ArrayClient, models - - -@pytest.fixture -def client(): - with ArrayClient() as client: - yield client - - -def test_boolean_value(client: ArrayClient): - assert client.boolean_value.get() == [True, False] - client.boolean_value.put([True, False]) - - -def test_datetime_value(client: ArrayClient): - assert client.datetime_value.get() == [isodate.parse_datetime("2022-08-26T18:38:00Z")] - client.datetime_value.put([isodate.parse_datetime("2022-08-26T18:38:00Z")]) - - -def test_duration_value(client: ArrayClient): - assert client.duration_value.get() == [isodate.parse_duration("P123DT22H14M12.011S")] - client.duration_value.put([isodate.parse_duration("P123DT22H14M12.011S")]) - - -def test_float32_value(client: ArrayClient): - assert client.float32_value.get() == [43.125] - client.float32_value.put([43.125]) - - -def test_int32_value(client: ArrayClient): - assert client.int32_value.get() == [1, 2] - client.int32_value.put([1, 2]) - - -def test_int64_value(client: ArrayClient): - assert client.int64_value.get() == [2**53 - 1, -(2**53 - 1)] - client.int64_value.put([2**53 - 1, -(2**53 - 1)]) - - -def test_model_value(client: ArrayClient): - assert client.model_value.get() == [ - models.InnerModel(property="hello"), - models.InnerModel(property="world"), - ] - client.model_value.put( - [ - models.InnerModel(property="hello"), - models.InnerModel(property="world"), - ] - ) - - -def test_nullable_boolean_value(client: ArrayClient): - assert client.nullable_boolean_value.get() == [True, None, False] - client.nullable_boolean_value.put([True, None, False]) - - -def test_nullable_float_value(client: ArrayClient): - assert client.nullable_float_value.get() == [1.25, None, 3.0] - client.nullable_float_value.put([1.25, None, 3.0]) - - -def test_nullable_int32_value(client: ArrayClient): - assert client.nullable_int32_value.get() == [1, None, 3] - client.nullable_int32_value.put([1, None, 3]) - - -def test_nullable_model_value(client: ArrayClient): - assert client.nullable_model_value.get() == [ - models.InnerModel(property="hello"), - None, - models.InnerModel(property="world"), - ] - client.nullable_model_value.put( - [ - models.InnerModel(property="hello"), - None, - models.InnerModel(property="world"), - ] - ) - - -def test_nullable_string_value(client: ArrayClient): - assert client.nullable_string_value.get() == ["hello", None, "world"] - client.nullable_string_value.put(["hello", None, "world"]) - - -def test_string_value(client: ArrayClient): - assert client.string_value.get() == ["hello", ""] - client.string_value.put(["hello", ""]) - - -def test_unknown_value(client: ArrayClient): - assert client.unknown_value.get() == [1, "hello", None] - client.unknown_value.put([1, "hello", None]) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_dictionary.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_dictionary.py deleted file mode 100644 index 5563a603fea..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_dictionary.py +++ /dev/null @@ -1,86 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.dictionary import DictionaryClient, models -import isodate - - -@pytest.fixture -def client(): - with DictionaryClient() as client: - yield client - - -def test_boolean_value(client: DictionaryClient): - value = {"k1": True, "k2": False} - assert client.boolean_value.get() == value - client.boolean_value.put(value) - - -def test_datetime_value(client: DictionaryClient): - value = {"k1": isodate.parse_datetime("2022-08-26T18:38:00Z")} - assert client.datetime_value.get() == value - client.datetime_value.put(value) - - -def test_duration_value(client: DictionaryClient): - value = {"k1": isodate.parse_duration("P123DT22H14M12.011S")} - assert client.duration_value.get() == value - client.duration_value.put(value) - - -def test_float32_value(client: DictionaryClient): - value = {"k1": 43.125} - assert client.float32_value.get() == value - client.float32_value.put(value) - - -def test_int32_value(client: DictionaryClient): - value = {"k1": 1, "k2": 2} - assert client.int32_value.get() == value - client.int32_value.put(value) - - -def test_int64_value(client: DictionaryClient): - value = {"k1": 2**53 - 1, "k2": -(2**53 - 1)} - assert client.int64_value.get() == value - client.int64_value.put(value) - - -def test_model_value(client: DictionaryClient): - value = { - "k1": models.InnerModel(property="hello"), - "k2": models.InnerModel(property="world"), - } - assert client.model_value.get() == value - client.model_value.put(value) - - -def test_nullable_float_value(client: DictionaryClient): - value = {"k1": 1.25, "k2": 0.5, "k3": None} - assert client.nullable_float_value.get() == value - client.nullable_float_value.put(value) - - -def test_recursive_model_value(client: DictionaryClient): - value = { - "k1": models.InnerModel(property="hello", children={}), - "k2": models.InnerModel(property="world", children={"k2.1": models.InnerModel(property="inner world")}), - } - assert client.recursive_model_value.get() == value - client.recursive_model_value.put(value) - - -def test_string_value(client: DictionaryClient): - value = {"k1": "hello", "k2": ""} - assert client.string_value.get() == value - client.string_value.put(value) - - -def test_unknown_value(client: DictionaryClient): - value = {"k1": 1, "k2": "hello", "k3": None} - assert client.unknown_value.get() == value - client.unknown_value.put(value) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_extensible.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_extensible.py deleted file mode 100644 index d98cb594001..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_extensible.py +++ /dev/null @@ -1,23 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.enum.extensible import ExtensibleClient, models - - -@pytest.fixture -def client(): - with ExtensibleClient() as client: - yield client - - -def test_known_value(client): - assert client.string.get_known_value() == models.DaysOfWeekExtensibleEnum.MONDAY - client.string.put_known_value(models.DaysOfWeekExtensibleEnum.MONDAY) - - -def test_unknown_value(client): - assert client.string.get_unknown_value() == "Weekend" - client.string.put_unknown_value("Weekend") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py deleted file mode 100644 index 720f61a7668..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_enum_fixed.py +++ /dev/null @@ -1,26 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.enum.fixed import FixedClient, models -from corehttp.exceptions import HttpResponseError - - -@pytest.fixture -def client(): - with FixedClient() as client: - yield client - - -def test_known_value(client): - assert client.string.get_known_value() == models.DaysOfWeekEnum.MONDAY - client.string.put_known_value(models.DaysOfWeekEnum.MONDAY) - - -def test_unknown_value(client: FixedClient): - try: - client.string.put_unknown_value("Weekend") - except HttpResponseError as err: - assert err.status_code == 500 diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_empty.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_empty.py deleted file mode 100644 index 38ad39e6b54..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_empty.py +++ /dev/null @@ -1,29 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.empty import EmptyClient -from type.model.empty.models import EmptyInput, EmptyOutput, EmptyInputOutput - - -@pytest.fixture -def client(): - with EmptyClient() as client: - yield client - - -def test_put(client: EmptyClient): - client.put_empty(EmptyInput()) - client.put_empty({}) - - -def test_get(client: EmptyClient): - assert client.get_empty() == EmptyOutput() - assert client.get_empty() == {} - - -def test_post_round(client: EmptyClient): - assert client.post_round_trip_empty(EmptyInputOutput()) == EmptyInputOutput() - assert client.post_round_trip_empty({}) == {} diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py deleted file mode 100644 index 837fe1b4582..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_enum_discriminator.py +++ /dev/null @@ -1,58 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.enumdiscriminator import EnumDiscriminatorClient -from type.model.inheritance.enumdiscriminator import models - - -@pytest.fixture -def client(): - with EnumDiscriminatorClient() as client: - yield client - - -@pytest.fixture -def valid_body(): - return models.Golden(weight=10) - - -@pytest.fixture -def valid_fixed_body(): - return models.Cobra(length=10) - - -def test_get_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): - assert client.get_extensible_model() == valid_body - assert isinstance(client.get_extensible_model(), models.Golden) - - -def test_put_extensible_model(client: EnumDiscriminatorClient, valid_body: models.Dog): - client.put_extensible_model(valid_body) - - -def test_get_extensible_model_missing_discriminator(client: EnumDiscriminatorClient): - assert client.get_extensible_model_missing_discriminator() == models.Dog(weight=10) - - -def test_get_extensible_model_wrong_discriminator(client: EnumDiscriminatorClient): - assert client.get_extensible_model_wrong_discriminator() == models.Dog(weight=8, kind="wrongKind") - - -def test_get_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): - assert client.get_fixed_model() == valid_fixed_body - assert isinstance(client.get_fixed_model(), models.Cobra) - - -def test_put_fixed_model(client: EnumDiscriminatorClient, valid_fixed_body: models.Snake): - client.put_fixed_model(valid_fixed_body) - - -def test_get_fixed_model_missing_discriminator(client: EnumDiscriminatorClient): - assert client.get_fixed_model_missing_discriminator() == models.Snake(length=10) - - -def test_get_fixed_model_wrong_discriminator(client: EnumDiscriminatorClient): - assert client.get_fixed_model_wrong_discriminator() == models.Snake(length=8, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py deleted file mode 100644 index ba74713b7a5..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_nested_discriminator.py +++ /dev/null @@ -1,79 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.nesteddiscriminator import NestedDiscriminatorClient -from type.model.inheritance.nesteddiscriminator.models import GoblinShark, Salmon, Fish - - -@pytest.fixture -def client(): - with NestedDiscriminatorClient() as client: - yield client - - -@pytest.fixture -def valid_body(): - return GoblinShark(age=1) - - -def test_get_model(client, valid_body): - assert client.get_model() == valid_body - assert isinstance(client.get_model(), GoblinShark) - - -def test_put_model(client, valid_body): - client.put_model(valid_body) - - -@pytest.fixture -def valid_recursive_body(): - return Salmon( - { - "age": 1, - "kind": "salmon", - "partner": {"age": 2, "kind": "shark", "sharktype": "saw"}, - "friends": [ - { - "age": 2, - "kind": "salmon", - "partner": {"age": 3, "kind": "salmon"}, - "hate": { - "key1": {"age": 4, "kind": "salmon"}, - "key2": {"age": 2, "kind": "shark", "sharktype": "goblin"}, - }, - }, - {"age": 3, "kind": "shark", "sharktype": "goblin"}, - ], - "hate": { - "key3": {"age": 3, "kind": "shark", "sharktype": "saw"}, - "key4": { - "age": 2, - "kind": "salmon", - "friends": [ - {"age": 1, "kind": "salmon"}, - {"age": 4, "kind": "shark", "sharktype": "goblin"}, - ], - }, - }, - } - ) - - -def test_get_recursive_model(client, valid_recursive_body): - assert valid_recursive_body == client.get_recursive_model() - assert isinstance(client.get_recursive_model(), Salmon) - - -def test_put_recursive_model(client, valid_recursive_body): - client.put_recursive_model(valid_recursive_body) - - -def test_get_missing_discriminator(client): - assert client.get_missing_discriminator() == Fish(age=1) - - -def test_get_wrong_discriminator(client): - assert client.get_wrong_discriminator() == Fish(age=1, kind="wrongKind") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py deleted file mode 100644 index 2bdbce464fc..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_not_discriminated.py +++ /dev/null @@ -1,31 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.notdiscriminated import NotDiscriminatedClient -from type.model.inheritance.notdiscriminated.models import Siamese - - -@pytest.fixture -def client(): - with NotDiscriminatedClient() as client: - yield client - - -@pytest.fixture -def valid_body(): - return Siamese(name="abc", age=32, smart=True) - - -def test_get_valid(client, valid_body): - assert client.get_valid() == valid_body - - -def test_post_valid(client, valid_body): - client.post_valid(valid_body) - - -def test_put_valid(client, valid_body): - assert valid_body == client.put_valid(valid_body) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py deleted file mode 100644 index f014b8d08e5..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_recursive.py +++ /dev/null @@ -1,32 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.recursive import RecursiveClient -from type.model.inheritance.recursive.models import Extension - - -@pytest.fixture -def client(): - with RecursiveClient() as client: - yield client - - -@pytest.fixture -def expected(): - return Extension( - { - "level": 0, - "extension": [{"level": 1, "extension": [{"level": 2}]}, {"level": 1}], - } - ) - - -def test_put(client: RecursiveClient, expected: Extension): - client.put(expected) - - -def test_get(client: RecursiveClient, expected: Extension): - assert client.get() == expected diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py deleted file mode 100644 index d81729560cb..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_inheritance_single_discriminator.py +++ /dev/null @@ -1,60 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.inheritance.singlediscriminator import SingleDiscriminatorClient -from type.model.inheritance.singlediscriminator.models import Sparrow, Eagle, Bird, Dinosaur - - -@pytest.fixture -def client(): - with SingleDiscriminatorClient() as client: - yield client - - -@pytest.fixture -def valid_body(): - return Sparrow(wingspan=1) - - -def test_get_model(client, valid_body): - assert client.get_model() == valid_body - - -def test_put_model(client, valid_body): - client.put_model(valid_body) - - -@pytest.fixture -def recursive_body(): - return Eagle( - { - "wingspan": 5, - "kind": "eagle", - "partner": {"wingspan": 2, "kind": "goose"}, - "friends": [{"wingspan": 2, "kind": "seagull"}], - "hate": {"key3": {"wingspan": 1, "kind": "sparrow"}}, - } - ) - - -def test_get_recursive_model(client, recursive_body): - assert client.get_recursive_model() == recursive_body - - -def test_put_recursive_model(client, recursive_body): - client.put_recursive_model(recursive_body) - - -def test_get_missing_discriminator(client): - assert client.get_missing_discriminator() == Bird(wingspan=1) - - -def test_get_wrong_discriminator(client): - assert client.get_wrong_discriminator() == Bird(wingspan=1, kind="wrongKind") - - -def test_get_legacy_model(client): - assert client.get_legacy_model() == Dinosaur(size=20, kind="t-rex") diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_usage.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_usage.py deleted file mode 100644 index 7541e8568e5..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_usage.py +++ /dev/null @@ -1,28 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.usage import UsageClient, models - - -@pytest.fixture -def client(): - with UsageClient() as client: - yield client - - -def test_input(client: UsageClient): - input = models.InputRecord(required_prop="example-value") - assert client.input(input) is None - - -def test_output(client: UsageClient): - output = models.OutputRecord(required_prop="example-value") - assert output == client.output() - - -def test_input_and_output(client: UsageClient): - input_output = models.InputOutputRecord(required_prop="example-value") - assert input_output == client.input_and_output(input_output) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_visibility.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_visibility.py deleted file mode 100644 index d7a56e5b3d3..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_model_visibility.py +++ /dev/null @@ -1,40 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.model.visibility import VisibilityClient, models - - -@pytest.fixture -def client(): - with VisibilityClient() as client: - yield client - - -def test_get_model(client): - result = client.get_model(models.VisibilityModel(query_prop=123)) - assert result == models.VisibilityModel(read_prop="abc") - - -def test_put_model(client): - client.put_model(models.VisibilityModel(create_prop=["foo", "bar"], update_prop=[1, 2])) - - -def test_patch_model(client): - client.patch_model(models.VisibilityModel(update_prop=[1, 2])) - - -def test_post_model(client): - client.post_model(models.VisibilityModel(create_prop=["foo", "bar"])) - - -def test_delete_model(client): - client.delete_model(models.VisibilityModel(delete_prop=True)) - - -def test_put_read_only_model(client): - client.put_read_only_model( - models.ReadOnlyModel(optional_nullable_int_list=[1, 2], optional_string_record={"foo", "bar"}) - ) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_additionalproperties.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_additionalproperties.py deleted file mode 100644 index d3e48a97013..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_additionalproperties.py +++ /dev/null @@ -1,313 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.property.additionalproperties import AdditionalPropertiesClient, models - - -@pytest.fixture -def client(): - with AdditionalPropertiesClient() as client: - yield client - - -def test_extends_different_spread_float(client: AdditionalPropertiesClient): - body = models.DifferentSpreadFloatDerived({"name": "abc", "prop": 43.125, "derivedProp": 43.125}) - assert client.extends_different_spread_float.get() == body - client.extends_different_spread_float.put(body) - - -def test_extends_different_spread_model(client: AdditionalPropertiesClient): - body = models.DifferentSpreadModelDerived( - {"knownProp": "abc", "prop": {"state": "ok"}, "derivedProp": {"state": "ok"}} - ) - assert client.extends_different_spread_model.get() == body - client.extends_different_spread_model.put(body) - - -def test_extends_different_spread_model_array(client: AdditionalPropertiesClient): - body = models.DifferentSpreadModelArrayDerived( - { - "knownProp": "abc", - "prop": [{"state": "ok"}, {"state": "ok"}], - "derivedProp": [{"state": "ok"}, {"state": "ok"}], - } - ) - assert client.extends_different_spread_model_array.get() == body - client.extends_different_spread_model_array.put(body) - - -def test_extends_different_spread_string(client: AdditionalPropertiesClient): - body = models.DifferentSpreadStringDerived({"id": 43.125, "prop": "abc", "derivedProp": "abc"}) - assert client.extends_different_spread_string.get() == body - client.extends_different_spread_string.put(body) - - -def test_extends_float(client: AdditionalPropertiesClient): - body = models.ExtendsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) - assert client.extends_float.get() == body - client.extends_float.put(body) - - -def test_extends_model(client: AdditionalPropertiesClient): - body = models.ExtendsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) - assert client.extends_model.get() == body - client.extends_model.put(body) - - -def test_extends_model_array(client: AdditionalPropertiesClient): - body = models.ExtendsModelArrayAdditionalProperties( - { - "knownProp": [{"state": "ok"}, {"state": "ok"}], - "prop": [{"state": "ok"}, {"state": "ok"}], - } - ) - assert client.extends_model_array.get() == body - client.extends_model_array.put(body) - - -def test_extends_string(client: AdditionalPropertiesClient): - body = models.ExtendsStringAdditionalProperties({"name": "ExtendsStringAdditionalProperties", "prop": "abc"}) - assert client.extends_string.get() == body - client.extends_string.put(body) - - -def test_extends_unknown(client: AdditionalPropertiesClient): - body = models.ExtendsUnknownAdditionalProperties( - { - "name": "ExtendsUnknownAdditionalProperties", - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert client.extends_unknown.get() == body - client.extends_unknown.put(body) - - -def test_extends_unknown_derived(client: AdditionalPropertiesClient): - body = models.ExtendsUnknownAdditionalPropertiesDerived( - { - "name": "ExtendsUnknownAdditionalProperties", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert client.extends_unknown_derived.get() == body - client.extends_unknown_derived.put(body) - - -def test_extends_unknown_discriminated(client: AdditionalPropertiesClient): - body = models.ExtendsUnknownAdditionalPropertiesDiscriminatedDerived( - { - "kind": "derived", - "name": "Derived", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert client.extends_unknown_discriminated.get() == body - client.extends_unknown_discriminated.put(body) - - -def test_is_float(client: AdditionalPropertiesClient): - body = models.IsFloatAdditionalProperties({"id": 43.125, "prop": 43.125}) - assert client.is_float.get() == body - client.is_float.put(body) - - -def test_is_model(client: AdditionalPropertiesClient): - body = models.IsModelAdditionalProperties({"knownProp": {"state": "ok"}, "prop": {"state": "ok"}}) - assert client.is_model.get() == body - client.is_model.put(body) - - -def test_is_model_array(client: AdditionalPropertiesClient): - body = models.IsModelArrayAdditionalProperties( - { - "knownProp": [{"state": "ok"}, {"state": "ok"}], - "prop": [{"state": "ok"}, {"state": "ok"}], - } - ) - assert client.is_model_array.get() == body - client.is_model_array.put(body) - - -def test_is_string(client: AdditionalPropertiesClient): - body = models.IsStringAdditionalProperties({"name": "IsStringAdditionalProperties", "prop": "abc"}) - assert client.is_string.get() == body - client.is_string.put(body) - - -def test_is_unknown(client: AdditionalPropertiesClient): - body = models.IsUnknownAdditionalProperties( - { - "name": "IsUnknownAdditionalProperties", - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert client.is_unknown.get() == body - client.is_unknown.put(body) - - -def test_is_unknown_derived(client: AdditionalPropertiesClient): - body = models.IsUnknownAdditionalPropertiesDerived( - { - "name": "IsUnknownAdditionalProperties", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert client.is_unknown_derived.get() == body - client.is_unknown_derived.put(body) - - -def test_is_unknown_discriminated(client: AdditionalPropertiesClient): - body = models.IsUnknownAdditionalPropertiesDiscriminatedDerived( - { - "kind": "derived", - "name": "Derived", - "index": 314, - "age": 2.71875, - "prop1": 32, - "prop2": True, - "prop3": "abc", - } - ) - assert client.is_unknown_discriminated.get() == body - client.is_unknown_discriminated.put(body) - - -def test_multiple_spread(client: AdditionalPropertiesClient): - body = {"flag": True, "prop1": "abc", "prop2": 43.125} - assert client.multiple_spread.get() == body - client.multiple_spread.put(body) - - -def test_spread_different_float(client: AdditionalPropertiesClient): - body = {"name": "abc", "prop": 43.125} - assert client.spread_different_float.get() == body - client.spread_different_float.put(body) - - -def test_spread_different_model(client: AdditionalPropertiesClient): - body = {"knownProp": "abc", "prop": {"state": "ok"}} - assert client.spread_different_model.get() == body - client.spread_different_model.put(body) - - -def test_spread_different_model_array(client: AdditionalPropertiesClient): - body = {"knownProp": "abc", "prop": [{"state": "ok"}, {"state": "ok"}]} - assert client.spread_different_model_array.get() == body - client.spread_different_model_array.put(body) - - -def test_spread_different_string(client: AdditionalPropertiesClient): - body = {"id": 43.125, "prop": "abc"} - assert client.spread_different_string.get() == body - client.spread_different_string.put(body) - - -def test_spread_model(client: AdditionalPropertiesClient): - body = {"knownProp": {"state": "ok"}, "prop": {"state": "ok"}} - assert client.spread_model.get() == body - client.spread_model.put(body) - - -def test_spread_model_array(client: AdditionalPropertiesClient): - body = { - "knownProp": [{"state": "ok"}, {"state": "ok"}], - "prop": [{"state": "ok"}, {"state": "ok"}], - } - assert client.spread_model_array.get() == body - client.spread_model_array.put(body) - - -def test_spread_record_discriminated_union(client: AdditionalPropertiesClient): - body = { - "name": "abc", - "prop1": {"fooProp": "abc", "kind": "kind0"}, - "prop2": { - "end": "2021-01-02T00:00:00Z", - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - }, - } - assert client.spread_record_discriminated_union.get() == body - client.spread_record_discriminated_union.put(body) - - -def test_spread_record_non_discriminated_union(client: AdditionalPropertiesClient): - body = { - "name": "abc", - "prop1": {"kind": "kind0", "fooProp": "abc"}, - "prop2": { - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - "end": "2021-01-02T00:00:00Z", - }, - } - assert client.spread_record_non_discriminated_union.get() == body - client.spread_record_non_discriminated_union.put(body) - - -def test_spread_record_non_discriminated_union2(client: AdditionalPropertiesClient): - body = { - "name": "abc", - "prop1": {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, - "prop2": { - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - "end": "2021-01-02T00:00:00Z", - }, - } - assert client.spread_record_non_discriminated_union2.get() == body - client.spread_record_non_discriminated_union2.put(body) - - -def test_spread_record_non_discriminated_union3(client: AdditionalPropertiesClient): - body = { - "name": "abc", - "prop1": [ - {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, - {"kind": "kind1", "start": "2021-01-01T00:00:00Z"}, - ], - "prop2": { - "kind": "kind1", - "start": "2021-01-01T00:00:00Z", - "end": "2021-01-02T00:00:00Z", - }, - } - assert client.spread_record_non_discriminated_union3.get() == body - client.spread_record_non_discriminated_union3.put(body) - - -def test_spread_record_union(client: AdditionalPropertiesClient): - body = {"flag": True, "prop1": "abc", "prop2": 43.125} - assert client.spread_record_union.get() == body - client.spread_record_union.put(body) - - -def test_spread_string(client: AdditionalPropertiesClient): - body = {"name": "SpreadSpringRecord", "prop": "abc"} - assert client.spread_string.get() == body - client.spread_string.put(body) - - -def test_spread_float(client: AdditionalPropertiesClient): - body = {"id": 43.125, "prop": 43.125} - assert client.spread_float.get() == body - client.spread_float.put(body) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_nullable.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_nullable.py deleted file mode 100644 index 528965447f7..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_nullable.py +++ /dev/null @@ -1,102 +0,0 @@ -# cspell: ignore Hdvcmxk -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import json -import pytest -from type.property.nullable import NullableClient, models -from type.property.nullable._model_base import ( # pylint: disable=protected-access - SdkJSONEncoder, -) - -try: - from corehttp.serialization import NULL -except ImportError: - from azure.core.serialization import NULL - - -@pytest.fixture -def client(): - with NullableClient() as client: - yield client - - -def test_bytes(client: NullableClient): - non_null_model = models.BytesProperty(required_property="foo", nullable_property="aGVsbG8sIHdvcmxkIQ==") - non_model = models.BytesProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert client.bytes.get_non_null() == non_null_model - assert client.bytes.get_null()["nullableProperty"] is None - client.bytes.patch_non_null(body=non_null_model) - client.bytes.patch_null(body=non_model) - - -def test_collections_byte(client: NullableClient): - non_null_model = models.CollectionsByteProperty( - required_property="foo", - nullable_property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="], - ) - non_model = models.CollectionsByteProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert client.collections_byte.get_non_null() == non_null_model - assert client.collections_byte.get_null()["nullableProperty"] is None - client.collections_byte.patch_non_null(body=non_null_model) - client.collections_byte.patch_null(body=non_model) - - -def test_collections_model(client: NullableClient): - non_null_model = models.CollectionsModelProperty( - required_property="foo", - nullable_property=[ - models.InnerModel(property="hello"), - models.InnerModel(property="world"), - ], - ) - non_model = models.CollectionsModelProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert client.collections_model.get_non_null() == non_null_model - assert client.collections_model.get_null()["nullableProperty"] is None - client.collections_model.patch_non_null(body=non_null_model) - client.collections_model.patch_null(body=non_model) - - -def test_collections_string(client: NullableClient): - non_null_model = models.CollectionsStringProperty(required_property="foo", nullable_property=["hello", "world"]) - non_model = models.CollectionsStringProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert client.collections_string.get_non_null() == non_null_model - assert client.collections_string.get_null()["nullableProperty"] is None - client.collections_string.patch_non_null(body=non_null_model) - client.collections_string.patch_null(body=non_model) - - -def test_datetime(client: NullableClient): - non_null_model = models.DatetimeProperty(required_property="foo", nullable_property="2022-08-26T18:38:00Z") - non_model = models.DatetimeProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert client.datetime.get_non_null() == non_null_model - assert client.datetime.get_null()["nullableProperty"] is None - client.datetime.patch_non_null(body=non_null_model) - client.datetime.patch_null(body=non_model) - - -def test_duration(client: NullableClient): - non_null_model = models.DurationProperty(required_property="foo", nullable_property="P123DT22H14M12.011S") - non_model = models.DurationProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert client.duration.get_non_null() == non_null_model - assert client.duration.get_null()["nullableProperty"] is None - client.duration.patch_non_null(body=non_null_model) - client.duration.patch_null(body=non_model) - - -def test_string(client: NullableClient): - non_null_model = models.StringProperty(required_property="foo", nullable_property="hello") - non_model = models.StringProperty(required_property="foo", nullable_property=NULL) - assert '{"requiredProperty": "foo", "nullableProperty": null}' == json.dumps(non_model, cls=SdkJSONEncoder) - assert client.string.get_non_null() == non_null_model - assert client.string.get_null()["nullableProperty"] is None - client.string.patch_non_null(body=non_null_model) - client.string.patch_null(body=non_model) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_optional.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_optional.py deleted file mode 100644 index 7f2d0d75aa0..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_optional.py +++ /dev/null @@ -1,174 +0,0 @@ -# cspell: ignore Hdvcmxk -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import Any -import pytest -from type.property.optional import OptionalClient, models - - -@pytest.fixture -def client(): - with OptionalClient() as client: - yield client - - -def test_boolean_literal(client): - body = models.BooleanLiteralProperty(property=True) - assert client.boolean_literal.get_all() == body - assert client.boolean_literal.get_default() == models.BooleanLiteralProperty() - client.boolean_literal.put_all(body) - client.boolean_literal.put_default(models.BooleanLiteralProperty()) - - -def test_bytes(client): - body = models.BytesProperty(property="aGVsbG8sIHdvcmxkIQ==") - assert client.bytes.get_all() == body - assert client.bytes.get_default() == models.BytesProperty() - client.bytes.put_all(body) - client.bytes.put_default(models.BytesProperty()) - - -def test_collections_byte(client): - body = models.CollectionsByteProperty(property=["aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ=="]) - assert client.collections_byte.get_all() == body - assert client.collections_byte.get_default() == models.CollectionsByteProperty() - client.collections_byte.put_all(body) - client.collections_byte.put_default(models.CollectionsByteProperty()) - - -def test_collections_model(client): - body = models.CollectionsModelProperty( - property=[ - models.StringProperty(property="hello"), - models.StringProperty(property="world"), - ] - ) - assert client.collections_model.get_all() == body - assert client.collections_model.get_default() == models.CollectionsModelProperty() - client.collections_model.put_all(body) - client.collections_model.put_default(models.CollectionsModelProperty()) - - -def test_datetime(client): - body = models.DatetimeProperty(property="2022-08-26T18:38:00Z") - assert client.datetime.get_all() == body - assert client.datetime.get_default() == models.DatetimeProperty() - client.datetime.put_all(body) - client.datetime.put_default(models.DatetimeProperty()) - - -def test_duration(client): - body = models.DurationProperty(property="P123DT22H14M12.011S") - assert client.duration.get_all() == body - assert client.duration.get_default() == models.DurationProperty() - client.duration.put_all(body) - client.duration.put_default(models.DurationProperty()) - - -def test_float_literal(client): - body = models.FloatLiteralProperty(property=1.25) - assert client.float_literal.get_all() == body - assert client.float_literal.get_default() == models.FloatLiteralProperty() - client.float_literal.put_all(body) - client.float_literal.put_default(models.FloatLiteralProperty()) - - -def test_int_literal(client): - body = models.IntLiteralProperty(property=1) - assert client.int_literal.get_all() == body - assert client.int_literal.get_default() == models.IntLiteralProperty() - client.int_literal.put_all(body) - client.int_literal.put_default(models.IntLiteralProperty()) - - -def test_plaindate_get_all(client): - body = models.PlainDateProperty(property="2022-12-12") - assert client.plain_date.get_all() == body - - -def test_plaindate_get_default(client): - assert client.plain_date.get_default() == models.PlainDateProperty() - - -def test_plaindate_put_all(client): - body = models.PlainDateProperty(property="2022-12-12") - client.plain_date.put_all(body) - - -def test_plaindate_put_default(client): - client.plain_date.put_default(models.PlainDateProperty()) - - -def test_plaintime_get_all(client): - body = models.PlainTimeProperty(property="13:06:12") - assert client.plain_time.get_all() == body - - -def test_plaintime_get_default(client): - assert client.plain_time.get_default() == models.PlainTimeProperty() - - -def test_plaintime_put_all(client): - body = models.PlainTimeProperty(property="13:06:12") - client.plain_time.put_all(body) - - -def test_plaintime_put_default(client): - client.plain_time.put_default(models.PlainTimeProperty()) - - -def test_required_and_optional(client): - all_body = { - "optionalProperty": "hello", - "requiredProperty": 42, - } - required_only_body = { - "requiredProperty": 42, - } - assert client.required_and_optional.get_all() == all_body - assert client.required_and_optional.get_required_only() == required_only_body - client.required_and_optional.put_all(all_body) - client.required_and_optional.put_required_only(required_only_body) - - -def test_string(client): - body = models.StringProperty(property="hello") - assert client.string.get_all() == body - assert client.string.get_default() == models.StringProperty() - client.string.put_all(body) - client.string.put_default(models.StringProperty()) - - -def test_string_literal(client): - body = models.StringLiteralProperty(property="hello") - assert client.string_literal.get_all() == body - assert client.string_literal.get_default() == models.StringLiteralProperty() - client.string_literal.put_all(body) - client.string_literal.put_default(models.StringLiteralProperty()) - - -def test_union_float_literal(client): - body = models.UnionFloatLiteralProperty(property=2.375) - assert client.union_float_literal.get_all() == body - assert client.union_float_literal.get_default() == models.UnionFloatLiteralProperty() - client.union_float_literal.put_all(body) - client.union_float_literal.put_default(models.UnionFloatLiteralProperty()) - - -def test_union_int_literal(client): - body = models.UnionIntLiteralProperty(property=2) - assert client.union_int_literal.get_all() == body - assert client.union_int_literal.get_default() == models.UnionIntLiteralProperty() - client.union_int_literal.put_all(body) - client.union_int_literal.put_default(models.UnionIntLiteralProperty()) - - -def test_union_string_literal(client): - body = models.UnionStringLiteralProperty(property="world") - assert client.union_string_literal.get_all() == body - assert client.union_string_literal.get_default() == models.UnionStringLiteralProperty() - client.union_string_literal.put_all(body) - client.union_string_literal.put_default(models.UnionStringLiteralProperty()) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_valuetypes.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_valuetypes.py deleted file mode 100644 index 8171a944d15..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_property_valuetypes.py +++ /dev/null @@ -1,286 +0,0 @@ -# cspell: ignore Hdvcmxk -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from calendar import c -import decimal - -import pytest -import datetime -from type.property.valuetypes import ValueTypesClient, models - - -@pytest.fixture -def client(): - with ValueTypesClient() as client: - yield client - - -def test_boolean(client: ValueTypesClient): - body = models.BooleanProperty(property=True) - assert body.property == body["property"] - client.boolean.put(body) - - resp = client.boolean.get() - assert resp.property == resp["property"] == True - - -def test_boolean_literal(client: ValueTypesClient): - body = models.BooleanLiteralProperty(property=True) - assert body.property == body["property"] - client.boolean_literal.put(body) - - resp = client.boolean_literal.get() - assert resp.property == resp["property"] == True - - -def test_bytes(client: ValueTypesClient): - body = models.BytesProperty(property=b"hello, world!") - assert body.property == b"hello, world!" - assert body["property"] == "aGVsbG8sIHdvcmxkIQ==" - client.bytes.put(body) - - resp = client.bytes.get() - assert resp.property == b"hello, world!" - assert resp["property"] == "aGVsbG8sIHdvcmxkIQ==" - - -def test_collections_int(client: ValueTypesClient): - body = models.CollectionsIntProperty(property=[1, 2]) - assert body.property == body["property"] - client.collections_int.put(body) - - resp = client.collections_int.get() - assert resp.property == resp["property"] == [1, 2] - - -def test_collections_model(client: ValueTypesClient): - body = models.CollectionsModelProperty(property=[{"property": "hello"}, {"property": "world"}]) - assert body.property[0].property == body["property"][0]["property"] - client.collections_model.put(body) - - resp = client.collections_model.get() - assert resp.property[1].property == resp["property"][1]["property"] - - -def test_collections_string(client: ValueTypesClient): - body = models.CollectionsStringProperty(property=["hello", "world"]) - assert body.property == body["property"] - client.collections_string.put(body) - - resp = client.collections_string.get() - assert resp.property == resp["property"] == ["hello", "world"] - - -def test_datetime(client): - received_body = client.datetime.get() - assert received_body == {"property": "2022-08-26T18:38:00Z"} - assert received_body.property.year == 2022 - assert received_body.property.month == 8 - assert received_body.property.day == 26 - assert received_body.property.hour == 18 - assert received_body.property.minute == 38 - - client.datetime.put(models.DatetimeProperty(property=datetime.datetime(2022, 8, 26, hour=18, minute=38))) - - -def test_decimal(client: ValueTypesClient): - body = models.DecimalProperty(property=decimal.Decimal("0.33333")) - assert body.property == decimal.Decimal("0.33333") - assert body["property"] == 0.33333 - client.decimal.put(body) - - resp = client.decimal.get() - assert resp.property == decimal.Decimal("0.33333") - assert resp["property"] == 0.33333 - - -def test_decimal128(client: ValueTypesClient): - body = models.Decimal128Property(property=decimal.Decimal("0.33333")) - assert body.property == decimal.Decimal("0.33333") - assert body["property"] == 0.33333 - client.decimal128.put(body) - - resp = client.decimal128.get() - assert resp.property == decimal.Decimal("0.33333") - assert resp["property"] == 0.33333 - - -def test_dictionary_string(client: ValueTypesClient): - body = models.DictionaryStringProperty(property={"k1": "hello", "k2": "world"}) - assert body.property == body["property"] - client.dictionary_string.put(body) - - resp = client.dictionary_string.get() - assert resp.property == resp["property"] == {"k1": "hello", "k2": "world"} - - -def test_duration(client: ValueTypesClient): - body = models.DurationProperty(property="P123DT22H14M12.011S") - assert body.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) - assert body["property"] == "P123DT22H14M12.011S" - client.duration.put(body) - - resp = client.duration.get() - assert resp.property == datetime.timedelta(days=123, seconds=80052, microseconds=11000) - assert resp["property"] == "P123DT22H14M12.011S" - - -def test_enum(client: ValueTypesClient): - body = models.EnumProperty(property=models.InnerEnum.VALUE_ONE) - assert body.property == body["property"] - client.enum.put(body) - - resp = client.enum.get() - assert resp.property == resp["property"] == "ValueOne" - - -def test_extensible_enum(client: ValueTypesClient): - body = models.ExtensibleEnumProperty(property="UnknownValue") - assert body.property == body["property"] - client.extensible_enum.put(body) - - resp = client.extensible_enum.get() - assert resp.property == resp["property"] == "UnknownValue" - - -def test_float(client: ValueTypesClient): - body = models.FloatProperty(property=43.125) - assert body.property == body["property"] - client.float.put(body) - - resp = client.float.get() - assert resp.property == resp["property"] == 43.125 - - -def test_float_literal(client: ValueTypesClient): - body = models.FloatLiteralProperty(property=43.125) - assert body.property == body["property"] - client.float_literal.put(body) - - resp = client.float_literal.get() - assert resp.property == resp["property"] == 43.125 - - -def test_int(client: ValueTypesClient): - body = models.IntProperty(property=42) - assert body.property == body["property"] - client.int_operations.put(body) - - resp = client.int_operations.get() - assert resp.property == resp["property"] == 42 - - -def test_int_literal(client: ValueTypesClient): - body = models.IntLiteralProperty(property=42) - assert body.property == body["property"] - client.int_literal.put(body) - - resp = client.int_literal.get() - assert resp.property == resp["property"] == 42 - - -def test_model(client: ValueTypesClient): - body = models.ModelProperty(property={"property": "hello"}) - assert body.property.property == body["property"]["property"] - client.model.put(body) - - resp = client.model.get() - assert resp.property.property == resp["property"]["property"] - - -def test_never(client: ValueTypesClient): - assert client.never.get() == models.NeverProperty() - client.never.put(models.NeverProperty()) - - -def test_string(client: ValueTypesClient): - body = models.StringProperty(property="hello") - assert body.property == body["property"] - client.string.put(body) - - resp = client.string.get() - assert resp.property == resp["property"] == "hello" - - -def test_string_literal(client: ValueTypesClient): - body = models.StringLiteralProperty(property="hello") - assert body.property == body["property"] - client.string_literal.put(body) - - resp = client.string_literal.get() - assert resp.property == resp["property"] == "hello" - - -def test_union_enum_value(client: ValueTypesClient): - body = models.UnionEnumValueProperty(property=models.ExtendedEnum.ENUM_VALUE2) - assert body.property == body["property"] - client.union_enum_value.put(body) - - resp = client.union_enum_value.get() - assert resp.property == resp["property"] == "value2" - - -def test_union_float_literal(client: ValueTypesClient): - body = models.UnionFloatLiteralProperty(property=46.875) - assert body.property == body["property"] - client.union_float_literal.put(body) - - resp = client.union_float_literal.get() - assert resp.property == resp["property"] == 46.875 - - -def test_union_int_literal(client: ValueTypesClient): - body = models.UnionIntLiteralProperty(property=42) - assert body.property == body["property"] - client.union_int_literal.put(body) - - resp = client.union_int_literal.get() - assert resp.property == resp["property"] == 42 - - -def test_union_string_literal(client: ValueTypesClient): - body = models.UnionStringLiteralProperty(property="world") - assert body.property == body["property"] - client.union_string_literal.put(body) - - resp = client.union_string_literal.get() - assert resp.property == resp["property"] == "world" - - -def test_unknown_array(client: ValueTypesClient): - body = models.UnknownArrayProperty(property=["hello", "world"]) - assert body.property == body["property"] - client.unknown_array.put(body) - - resp = client.unknown_array.get() - assert resp.property == resp["property"] == ["hello", "world"] - - -def test_unknown_dict(client: ValueTypesClient): - body = models.UnknownDictProperty(property={"k1": "hello", "k2": 42}) - assert body.property == body["property"] - client.unknown_dict.put(body) - - resp = client.unknown_dict.get() - assert resp.property == resp["property"] == {"k1": "hello", "k2": 42} - - -def test_unknown_int(client: ValueTypesClient): - body = models.UnknownIntProperty(property=42) - assert body.property == body["property"] - client.unknown_int.put(body) - - resp = client.unknown_int.get() - assert resp.property == resp["property"] == 42 - - -def test_unknown_string(client: ValueTypesClient): - body = models.UnknownStringProperty(property="hello") - assert body.property == body["property"] - client.unknown_string.put(body) - - resp = client.unknown_string.get() - assert resp.property == resp["property"] == "hello" diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_scalar.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_scalar.py deleted file mode 100644 index 2dadfe8429f..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_scalar.py +++ /dev/null @@ -1,53 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import decimal -from functools import reduce - -import pytest -from type.scalar import ScalarClient - - -@pytest.fixture -def client(): - with ScalarClient() as client: - yield client - - -def test_scalar_string(client: ScalarClient): - assert client.string.get() == "test" - client.string.put("test") - - -def test_scalar_boolean(client: ScalarClient): - assert client.boolean.get() == True - client.boolean.put(True) - - -def test_scalar_unknown(client: ScalarClient): - assert client.unknown.get() == "test" - client.unknown.put("test") - - -def test_decimal128_type(client: ScalarClient): - assert client.decimal128_type.response_body() == decimal.Decimal("0.33333") - client.decimal128_type.request_body(decimal.Decimal("0.33333")) - client.decimal128_type.request_parameter(value=decimal.Decimal("0.33333")) - - -def test_decimal_type(client: ScalarClient): - assert client.decimal_type.response_body() == decimal.Decimal("0.33333") - client.decimal_type.request_body(decimal.Decimal("0.33333")) - client.decimal_type.request_parameter(value=decimal.Decimal("0.33333")) - - -def test_decimal128_verify(client: ScalarClient): - prepare = client.decimal128_verify.prepare_verify() - client.decimal128_verify.verify(reduce(lambda x, y: x + y, prepare)) - - -def test_decimal_verify(client: ScalarClient): - prepare = client.decimal_verify.prepare_verify() - client.decimal_verify.verify(reduce(lambda x, y: x + y, prepare)) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_union.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_union.py deleted file mode 100644 index 18c3f1b4c42..00000000000 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_typetest_union.py +++ /dev/null @@ -1,80 +0,0 @@ -# ------------------------------------------------------------------------- -# 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 type.union import UnionClient -from type.union import models - - -@pytest.fixture -def client(): - with UnionClient() as client: - yield client - - -def test_enums_only(client: UnionClient): - value = models.EnumsOnlyCases(lr="right", ud="up") - assert client.enums_only.get() == {"prop": value} - client.enums_only.send(prop=value) - - -def test_floats_only(client: UnionClient): - value = 2.2 - assert client.floats_only.get() == {"prop": value} - client.floats_only.send(prop=value) - - -def test_ints_only(client: UnionClient): - value = 2 - assert client.ints_only.get() == {"prop": value} - client.ints_only.send(prop=value) - - -def test_mixed_literals(client: UnionClient): - value = models.MixedLiteralsCases(string_literal="a", int_literal=2, float_literal=3.3, boolean_literal=True) - assert client.mixed_literals.get() == {"prop": value} - client.mixed_literals.send(prop=value) - - -def test_mixed_types(client: UnionClient): - value = models.MixedTypesCases( - model=models.Cat(name="test"), - literal="a", - int_property=2, - boolean=True, - array=[models.Cat(name="test"), "a", 2, True], - ) - assert client.mixed_types.get() == {"prop": value} - client.mixed_types.send(prop=value) - - -def test_models_only(client: UnionClient): - value = models.Cat(name="test") - assert client.models_only.get() == {"prop": value} - client.models_only.send(prop=value) - - -def test_string_and_array(client: UnionClient): - value = models.StringAndArrayCases(string="test", array=["test1", "test2"]) - assert client.string_and_array.get() == {"prop": value} - client.string_and_array.send(prop=value) - - -def test_string_extensible(client: UnionClient): - value = "custom" - assert client.string_extensible.get() == {"prop": value} - client.string_extensible.send(prop=value) - - -def test_string_extensible_named(client: UnionClient): - value = "custom" - assert client.string_extensible_named.get() == {"prop": value} - client.string_extensible_named.send(prop=value) - - -def test_strings_only(client: UnionClient): - value = "b" - assert client.strings_only.get() == {"prop": value} - client.strings_only.send(prop=value) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py index b4115b0211b..1f52da5d0f7 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_unbranded.py @@ -9,7 +9,7 @@ import traceback from importlib import import_module import pytest -from type.scalar import ScalarClient +from typetest.scalar import ScalarClient from corehttp.exceptions import HttpResponseError From 28d97b6fee1e824e2fcbd133d02a1da9b0651054 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 14 Mar 2025 17:17:59 +0800 Subject: [PATCH 20/32] update --- packages/http-client-python/emitter/src/emitter.ts | 7 ++++--- .../http-client-python/emitter/src/external-process.ts | 4 ++++ packages/http-client-python/emitter/src/lib.ts | 3 +-- packages/http-client-python/emitter/src/utils.ts | 6 +++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/http-client-python/emitter/src/emitter.ts b/packages/http-client-python/emitter/src/emitter.ts index 75cdd4c09c7..b27f4f44a95 100644 --- a/packages/http-client-python/emitter/src/emitter.ts +++ b/packages/http-client-python/emitter/src/emitter.ts @@ -50,13 +50,14 @@ function addDefaultOptions(sdkContext: SdkContext) { options["package-mode"] = sdkContext.arm ? "azure-mgmt" : "azure-dataplane"; } if (!options["package-name"]) { + const namespace = getRootNamespace(sdkContext as PythonSdkContext); + const packageName = namespace.replace(/\./g, "-"); reportDiagnostic(sdkContext.program, { code: "no-package-name", target: NoTarget, + format: { namespace, packageName }, }); - options["package-name"] = getRootNamespace( - sdkContext as PythonSdkContext, - ).replace(/\./g, "-"); + options["package-name"] = packageName; } if (options.flavor !== "azure") { // if they pass in a flavor other than azure, we want to ignore the value diff --git a/packages/http-client-python/emitter/src/external-process.ts b/packages/http-client-python/emitter/src/external-process.ts index 97a9125b44a..de1f34d1f1b 100644 --- a/packages/http-client-python/emitter/src/external-process.ts +++ b/packages/http-client-python/emitter/src/external-process.ts @@ -22,6 +22,10 @@ export async function saveCodeModelAsYaml(name: string, codemodel: unknown): Pro const filename = createTempPath(".yaml", name); const yamlStr = jsyaml.dump(codemodel); await writeFile(filename, yamlStr); + await writeFile( + joinPaths("C:/dev/typespec/packages/http-client-python", "alpha", "output.yaml"), + yamlStr, + ); return filename; } diff --git a/packages/http-client-python/emitter/src/lib.ts b/packages/http-client-python/emitter/src/lib.ts index 9ae89444d3a..7c8f2421a6d 100644 --- a/packages/http-client-python/emitter/src/lib.ts +++ b/packages/http-client-python/emitter/src/lib.ts @@ -78,8 +78,7 @@ const libDef = { "no-package-name": { severity: "warning", messages: { - default: - "No 'package-name' configured in tspconfig.yaml and will infer 'package-name' from namespace.", + default: paramMessage`No package-name configured in tspconfig.yaml and will infer package-name '${"packageName"}' from namespace '${"namespace"}'.`, }, }, "no-valid-client": { diff --git a/packages/http-client-python/emitter/src/utils.ts b/packages/http-client-python/emitter/src/utils.ts index 41887b7b26e..3ac9d317fc9 100644 --- a/packages/http-client-python/emitter/src/utils.ts +++ b/packages/http-client-python/emitter/src/utils.ts @@ -221,9 +221,7 @@ const LIB_NAMESPACE = [ export function getRootNamespace(context: PythonSdkContext): string { let rootNamespace = ""; - if (context.sdkPackage.namespaces.length > 0) { - rootNamespace = context.sdkPackage.namespaces[0].fullName; - } else if (context.sdkPackage.clients.length > 0) { + if (context.sdkPackage.clients.length > 0) { rootNamespace = context.sdkPackage.clients[0].namespace; } else if (context.sdkPackage.models.length > 0) { const result = context.sdkPackage.models @@ -233,6 +231,8 @@ export function getRootNamespace(context: PythonSdkContext) result.sort(); rootNamespace = result[0]; } + } else if (context.sdkPackage.namespaces.length > 0) { + rootNamespace = context.sdkPackage.namespaces[0].fullName; } return removeUnderscoresFromNamespace(rootNamespace).toLowerCase(); From 99e8a5230d02a32bb163753e75e8f8f053c4ab33 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 17 Mar 2025 12:48:09 +0800 Subject: [PATCH 21/32] update --- packages/http-client-python/emitter/src/external-process.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/http-client-python/emitter/src/external-process.ts b/packages/http-client-python/emitter/src/external-process.ts index de1f34d1f1b..97a9125b44a 100644 --- a/packages/http-client-python/emitter/src/external-process.ts +++ b/packages/http-client-python/emitter/src/external-process.ts @@ -22,10 +22,6 @@ export async function saveCodeModelAsYaml(name: string, codemodel: unknown): Pro const filename = createTempPath(".yaml", name); const yamlStr = jsyaml.dump(codemodel); await writeFile(filename, yamlStr); - await writeFile( - joinPaths("C:/dev/typespec/packages/http-client-python", "alpha", "output.yaml"), - yamlStr, - ); return filename; } From a05b266f656a746dcf6253014bf698eac65c95c0 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 17 Mar 2025 14:30:04 +0800 Subject: [PATCH 22/32] update package.json --- .../http-client-python/generator/pygen/codegen/__init__.py | 1 - .../generator/pygen/codegen/models/code_model.py | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/__init__.py b/packages/http-client-python/generator/pygen/codegen/__init__.py index 2cf10f3fac0..1a2882fba9c 100644 --- a/packages/http-client-python/generator/pygen/codegen/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/__init__.py @@ -316,7 +316,6 @@ def _build_code_model_options(self) -> Dict[str, Any]: "flavor", "company_name", "emit_cross_language_definition_file", - "enable_typespec_namespace", ] return {f: getattr(self.options_retriever, f) for f in flags} diff --git a/packages/http-client-python/generator/pygen/codegen/models/code_model.py b/packages/http-client-python/generator/pygen/codegen/models/code_model.py index 4d0f1da89b1..1d1fd9cdd20 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/code_model.py +++ b/packages/http-client-python/generator/pygen/codegen/models/code_model.py @@ -145,12 +145,8 @@ def get_relative_import_path( return result return f"{result}{module_name}" if result.endswith(".") else f"{result}.{module_name}" - @property - def need_unique_model_alias(self) -> bool: - return self.has_subnamespace and self.options["enable_typespec_namespace"] - def get_unique_models_alias(self, serialize_namespace: str, imported_namespace: str) -> str: - if not self.need_unique_model_alias: + if not self.has_subnamespace: return "_models" relative_path = self.get_relative_import_path( serialize_namespace, self.get_imported_namespace_for_model(imported_namespace) From c9dd60b5e7afebb4882b903601825b846b3ba54c Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 17 Mar 2025 16:27:34 +0800 Subject: [PATCH 23/32] update --- .../eng/scripts/ci/regenerate.ts | 77 +++++++++++++++---- ...test_azure_arm_operationtemplates_async.py | 1 + .../test_azure_arm_operationtemplates.py | 1 + 3 files changed, 62 insertions(+), 17 deletions(-) diff --git a/packages/http-client-python/eng/scripts/ci/regenerate.ts b/packages/http-client-python/eng/scripts/ci/regenerate.ts index 6293c757762..4995f6a8d9d 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate.ts @@ -38,6 +38,64 @@ interface TspCommand { command: string; } +const AZURE_EMITTER_OPTIONS: Record | Record[]> = { + "azure/example/basic": { + namespace: "specs.azure.example.basic", + }, + "azure/client-generator-core/access": { + namespace: "specs.azure.clientgenerator.core.access", + }, + "azure/client-generator-core/usage": { + namespace: "specs.azure.clientgenerator.core.usage", + }, + "azure/core/lro/rpc": { + "package-name": "azurecore-lro-rpc", + namespace: "azurecore.lro.rpc", + }, + "client/structure/default": { + namespace: "client.structure.service", + }, + "client/structure/multi-client": { + "package-name": "client-structure-multiclient", + namespace: "client.structure.multiclient", + }, + "client/structure/renamed-operation": { + "package-name": "client-structure-renamedoperation", + namespace: "client.structure.renamedoperation", + }, + "client/structure/two-operation-group": { + "package-name": "client-structure-twooperationgroup", + namespace: "client.structure.twooperationgroup", + }, + "client/naming": { + namespace: "client.naming", + }, + "encode/duration": { + namespace: "encode.duration", + }, + "encode/numeric": { + namespace: "encode.numeric", + }, + "parameters/basic": { + namespace: "parameters.basic", + }, + "parameters/spread": { + namespace: "parameters.spread", + }, + "payload/content-negotiation": { + namespace: "payload.contentnegotiation", + }, + "payload/multipart": { + namespace: "payload.multipart", + }, + "serialization/encoded-name/json": { + namespace: "serialization.encodedname.json", + }, + "special-words": { + namespace: "specialwords", + }, +}; + const EMITTER_OPTIONS: Record | Record[]> = { "resiliency/srv-driven/old.tsp": { "package-name": "resiliency-srv-driven1", @@ -146,22 +204,6 @@ const EMITTER_OPTIONS: Record | Record[ const key = relativeSpec.includes("resiliency/srv-driven/old.tsp") ? relativeSpec : dirname(relativeSpec); - const emitter_options = EMITTER_OPTIONS[key] || [{}]; + const emitter_options = EMITTER_OPTIONS[key] || + (flavor === "azure" ? AZURE_EMITTER_OPTIONS[key] : [{}]) || [{}]; return Array.isArray(emitter_options) ? emitter_options : [emitter_options]; } diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py index bb6f807e44c..df4e1f6246e 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_arm_operationtemplates_async.py @@ -18,6 +18,7 @@ async def client(credential, authentication_policy): SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy, + polling_interval=0, ) as client: yield client diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py index 4a2ca1309b5..d0e73ad772a 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_arm_operationtemplates.py @@ -18,6 +18,7 @@ def client(credential, authentication_policy): SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy, + polling_interval=0, ) as client: yield client From bfef02f59fd87714573e5a3b1523a7d27ed13006 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 18 Mar 2025 13:03:01 +0800 Subject: [PATCH 24/32] update --- .../pygen/codegen/templates/packaging_templates/setup.py.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 index f5b3b882f5a..2ad64e49412 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 @@ -11,8 +11,8 @@ from setuptools import setup, find_packages {% set package_name = package_name or code_model.clients[0].name %} PACKAGE_NAME = "{{ package_name|lower }}" -PACKAGE_NAMESPACE = "{{ code_model.namespace|lower }}" {% if package_mode %} +PACKAGE_NAMESPACE = "{{ code_model.namespace|lower }}" PACKAGE_PPRINT_NAME = "{{ package_pprint_name }}" # a.b.c => a/b/c From a78638cfccd67ac2152e7486cdda6334e6c62ad0 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 18 Mar 2025 14:39:02 +0800 Subject: [PATCH 25/32] review --- .../generator/pygen/codegen/models/code_model.py | 4 ++++ .../templates/packaging_templates/MANIFEST.in.jinja2 | 4 ++++ .../codegen/templates/packaging_templates/setup.py.jinja2 | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/http-client-python/generator/pygen/codegen/models/code_model.py b/packages/http-client-python/generator/pygen/codegen/models/code_model.py index 1d1fd9cdd20..2153cbcbf55 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/code_model.py +++ b/packages/http-client-python/generator/pygen/codegen/models/code_model.py @@ -402,3 +402,7 @@ def is_legacy(self) -> bool: @staticmethod def has_non_json_models(models: List[ModelType]) -> bool: return any(m for m in models if m.base != "json") + + @property + def is_tsp(self) -> bool: + return self.options.get("tsp_file") is not None diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 index df76124de2b..3cb8e23e6a4 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/MANIFEST.in.jinja2 @@ -1,6 +1,10 @@ include *.md include LICENSE +{% if code_model.is_tsp %} include {{ code_model.namespace.replace('.', '/') }}/py.typed +{% else %} +include {{ package_name.replace('-', '/') }}/py.typed +{% endif %} recursive-include tests *.py recursive-include samples *.py *.md {% for init_name in init_names %} diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 index 2ad64e49412..1153b4e62ef 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 @@ -13,11 +13,15 @@ from setuptools import setup, find_packages PACKAGE_NAME = "{{ package_name|lower }}" {% if package_mode %} PACKAGE_NAMESPACE = "{{ code_model.namespace|lower }}" +{% if code_model.is_tsp %} PACKAGE_PPRINT_NAME = "{{ package_pprint_name }}" # a.b.c => a/b/c package_folder_path = PACKAGE_NAMESPACE.replace(".", "/") - +{% else %} +# a-b-c => a/b/c +package_folder_path = PACKAGE_NAME.replace("-", "/") +{% endif %} # Version extraction inspired from 'requests' with open(os.path.join(package_folder_path, "_version.py"), "r") as fd: version = re.search( From f3bec5bce8e0c0e5640f8d4024c38686a4c8bf23 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 18 Mar 2025 14:58:43 +0800 Subject: [PATCH 26/32] review --- .../codegen/templates/packaging_templates/setup.py.jinja2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 index 1153b4e62ef..c6951d01427 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 @@ -12,9 +12,9 @@ from setuptools import setup, find_packages PACKAGE_NAME = "{{ package_name|lower }}" {% if package_mode %} -PACKAGE_NAMESPACE = "{{ code_model.namespace|lower }}" -{% if code_model.is_tsp %} PACKAGE_PPRINT_NAME = "{{ package_pprint_name }}" +{% if code_model.is_tsp %} +PACKAGE_NAMESPACE = "{{ code_model.namespace|lower }}" # a.b.c => a/b/c package_folder_path = PACKAGE_NAMESPACE.replace(".", "/") From 30cf71d53374303f00a6d811b112c57e70b500cc Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 18 Mar 2025 15:13:59 +0800 Subject: [PATCH 27/32] review --- .../generator/pygen/codegen/serializers/general_serializer.py | 2 +- .../codegen/templates/packaging_templates/setup.py.jinja2 | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py index e4586b733c7..b06a8ae1a68 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py @@ -28,7 +28,7 @@ def serialize_setup_file(self) -> str: def serialize_package_file(self, template_name: str, **kwargs: Any) -> str: template = self.env.get_template(template_name) - package_parts = self.code_model.namespace.split(".")[:-1] + package_parts = self.code_model.namespace.split(".")[:-1] if self.code_model.is_tsp else (self.code_model.options["package_name"] or "").split("-")[:-1] token_credential = any( c for c in self.code_model.clients if isinstance(getattr(c.credential, "type", None), TokenCredentialType) ) diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 index c6951d01427..6b3af5b10ef 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/setup.py.jinja2 @@ -19,9 +19,11 @@ PACKAGE_NAMESPACE = "{{ code_model.namespace|lower }}" # a.b.c => a/b/c package_folder_path = PACKAGE_NAMESPACE.replace(".", "/") {% else %} + # a-b-c => a/b/c package_folder_path = PACKAGE_NAME.replace("-", "/") {% endif %} + # Version extraction inspired from 'requests' with open(os.path.join(package_folder_path, "_version.py"), "r") as fd: version = re.search( @@ -40,6 +42,8 @@ version = "{{ package_version }}" {% set author_email = "" %} {% set url = "" %} {% endif %} + + setup( name=PACKAGE_NAME, version=version, From f32b9888417304ae1a182211b3f26cf1ad15e3b6 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 18 Mar 2025 15:34:30 +0800 Subject: [PATCH 28/32] review --- .../codegen/templates/packaging_templates/README.md.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 index cb221597bb4..f7dc4f8de52 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 @@ -11,7 +11,7 @@ For a more complete view of Azure libraries, see the [azure sdk python release]( To learn how to use this package, see the [quickstart guide](https://aka.ms/azsdk/python/mgmt) For docs and references, see [Python SDK References](https://docs.microsoft.com/python/api/overview/azure) -Code samples for this package can be found at [{{package_pprint_name}}](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20%20Managing&terms=Getting%20started%20%20Managing) on docs.microsoft.com. +Code samples for this package can be found at [{{package_pprint_name}}](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com. Additional code samples for different Azure services are available at [Samples Repo](https://aka.ms/azsdk/python/mgmt/samples) # Provide Feedback From 1550de44d04ac9075eae80a5983db3034bcaa625 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 21 Mar 2025 10:21:50 +0800 Subject: [PATCH 29/32] update --- packages/http-client-python/emitter/src/code-model.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-python/emitter/src/code-model.ts b/packages/http-client-python/emitter/src/code-model.ts index ff461da244b..2919e464a08 100644 --- a/packages/http-client-python/emitter/src/code-model.ts +++ b/packages/http-client-python/emitter/src/code-model.ts @@ -144,7 +144,7 @@ function emitMethodParameter( clientDefaultValue: parameter.clientDefaultValue, location: parameter.kind, }; - if (parameter.kind === "apiVersion") { + if (parameter.isApiVersionParam) { return [ { ...base, From 1418b8379b55c4a67fa9e43db50e2ccccbffa87e Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 21 Mar 2025 10:29:03 +0800 Subject: [PATCH 30/32] Fix typo in update-root-namespace file --- .chronus/changes/update-root-namespace-2025-2-12-6-11-5.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chronus/changes/update-root-namespace-2025-2-12-6-11-5.md b/.chronus/changes/update-root-namespace-2025-2-12-6-11-5.md index 8d0e04b9ec6..970830b700f 100644 --- a/.chronus/changes/update-root-namespace-2025-2-12-6-11-5.md +++ b/.chronus/changes/update-root-namespace-2025-2-12-6-11-5.md @@ -5,4 +5,4 @@ packages: - "@typespec/http-client-python" --- -Always respect namesapce from TCGC +Always respect namespace from TCGC From 9f1ddd4b1de1fad4f909fb9e91686816c6578fce Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 24 Mar 2025 10:39:02 +0800 Subject: [PATCH 31/32] bump tcgc 0.53.1 --- packages/http-client-python/emitter/src/code-model.ts | 7 +------ .../pygen/codegen/serializers/general_serializer.py | 6 +++++- packages/http-client-python/package-lock.json | 10 +++++----- packages/http-client-python/package.json | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/http-client-python/emitter/src/code-model.ts b/packages/http-client-python/emitter/src/code-model.ts index 2919e464a08..52efc1e7398 100644 --- a/packages/http-client-python/emitter/src/code-model.ts +++ b/packages/http-client-python/emitter/src/code-model.ts @@ -1,5 +1,4 @@ import { - SdkApiVersionParameter, SdkBasicServiceMethod, SdkClientType, SdkCredentialParameter, @@ -101,11 +100,7 @@ function emitLroPagingMethod( function emitMethodParameter( context: PythonSdkContext, - parameter: - | SdkEndpointParameter - | SdkCredentialParameter - | SdkMethodParameter - | SdkApiVersionParameter, + parameter: SdkEndpointParameter | SdkCredentialParameter | SdkMethodParameter, ): Record[] { if (parameter.kind === "endpoint") { if (parameter.type.kind === "union") { diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py index b06a8ae1a68..ef6b029af8e 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py @@ -28,7 +28,11 @@ def serialize_setup_file(self) -> str: def serialize_package_file(self, template_name: str, **kwargs: Any) -> str: template = self.env.get_template(template_name) - package_parts = self.code_model.namespace.split(".")[:-1] if self.code_model.is_tsp else (self.code_model.options["package_name"] or "").split("-")[:-1] + package_parts = ( + self.code_model.namespace.split(".")[:-1] + if self.code_model.is_tsp + else (self.code_model.options["package_name"] or "").split("-")[:-1] + ) token_credential = any( c for c in self.code_model.clients if isinstance(getattr(c.credential, "type", None), TokenCredentialType) ) diff --git a/packages/http-client-python/package-lock.json b/packages/http-client-python/package-lock.json index 8f30393e372..b435cbafc5d 100644 --- a/packages/http-client-python/package-lock.json +++ b/packages/http-client-python/package-lock.json @@ -22,7 +22,7 @@ "@azure-tools/typespec-azure-core": "~0.53.0", "@azure-tools/typespec-azure-resource-manager": "~0.53.0", "@azure-tools/typespec-azure-rulesets": "~0.53.0", - "@azure-tools/typespec-client-generator-core": "~0.53.0", + "@azure-tools/typespec-client-generator-core": "~0.53.1", "@types/js-yaml": "~4.0.5", "@types/node": "~22.5.4", "@types/semver": "7.5.8", @@ -47,7 +47,7 @@ "@azure-tools/typespec-azure-core": ">=0.53.0 <1.0.0", "@azure-tools/typespec-azure-resource-manager": ">=0.53.0 <1.0.0", "@azure-tools/typespec-azure-rulesets": ">=0.53.0 <3.0.0", - "@azure-tools/typespec-client-generator-core": ">=0.53.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": ">=0.53.1 <1.0.0", "@typespec/compiler": ">=0.67.0 <1.0.0", "@typespec/http": ">=0.67.0 <1.0.0", "@typespec/openapi": ">=0.67.0 <1.0.0", @@ -151,9 +151,9 @@ } }, "node_modules/@azure-tools/typespec-client-generator-core": { - "version": "0.53.0", - "resolved": "https://registry.npmjs.org/@azure-tools/typespec-client-generator-core/-/typespec-client-generator-core-0.53.0.tgz", - "integrity": "sha512-EXdkC76HmAdaH0kzET38pPpG7Phoyvp9AFYsAXnQdhRQssfI+x9nxEADix8GZ2n2P1P50ZysvzWeciqgqUbRVw==", + "version": "0.53.1", + "resolved": "https://registry.npmjs.org/@azure-tools/typespec-client-generator-core/-/typespec-client-generator-core-0.53.1.tgz", + "integrity": "sha512-BWHQQ9Kjsk23Rb0eZ6V6HI2Gr20n/LhxAKEuBChCFWLjrFMYyXrHtlUBK6j/9D2VqwjaurRQA2SVXx/wzGyvAg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index 8ec9f492442..7fda2e5c9f1 100644 --- a/packages/http-client-python/package.json +++ b/packages/http-client-python/package.json @@ -57,7 +57,7 @@ "@azure-tools/typespec-azure-core": ">=0.53.0 <1.0.0", "@azure-tools/typespec-azure-resource-manager": ">=0.53.0 <1.0.0", "@azure-tools/typespec-azure-rulesets": ">=0.53.0 <3.0.0", - "@azure-tools/typespec-client-generator-core": ">=0.53.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": ">=0.53.1 <1.0.0", "@typespec/compiler": ">=0.67.0 <1.0.0", "@typespec/http": ">=0.67.0 <1.0.0", "@typespec/openapi": ">=0.67.0 <1.0.0", @@ -77,7 +77,7 @@ "@azure-tools/typespec-azure-core": "~0.53.0", "@azure-tools/typespec-azure-resource-manager": "~0.53.0", "@azure-tools/typespec-azure-rulesets": "~0.53.0", - "@azure-tools/typespec-client-generator-core": "~0.53.0", + "@azure-tools/typespec-client-generator-core": "~0.53.1", "@types/js-yaml": "~4.0.5", "@types/node": "~22.5.4", "@types/semver": "7.5.8", From 3999daa6fb5b3293dd92f0c3b0b0cf5d7c3649b5 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 24 Mar 2025 14:22:12 +0800 Subject: [PATCH 32/32] Update packages/http-client-python/generator/pygen/codegen/serializers/__init__.py Co-authored-by: Chenjie Shi --- .../generator/pygen/codegen/serializers/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py index 7ff0787fcfe..305655d8680 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/__init__.py @@ -485,7 +485,7 @@ def exec_path(self, namespace: str) -> Path: # pylint: disable=line-too-long @property def sample_additional_folder(self) -> Path: - # For special package, we need to additional folder when generate sampoles. + # For special package, we need to additional folder when generate samples. # For example, azure-mgmt-resource is combined by multiple modules, and each module is multiapi package. # one of namespace is "azure.mgmt.resource.resources.v2020_01_01", then additional folder is "resources" # so that we could avoid conflict when generate samples.