From c76e73a702d5d6f1c26dd7bdcab5ba3f99b90d69 Mon Sep 17 00:00:00 2001 From: Matteo Bigoi <1781140+crisidev@users.noreply.github.com> Date: Mon, 27 Mar 2023 14:57:32 +0100 Subject: [PATCH] Disable protocol tests for python until we add all the testing modules (#2501) * Disable protocol tests for python until we add all the testing modules * Generate operation ser/de in the correct module --- .../smithy/PythonServerCodegenVisitor.kt | 18 ++++++++-------- .../server/smithy/ServerCodegenVisitor.kt | 21 ++++++++++++++++--- .../protocol/ServerProtocolTestGenerator.kt | 1 - 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt index 8ca07570a..216f21a4f 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt @@ -1,4 +1,3 @@ - /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 @@ -103,11 +102,15 @@ class PythonServerCodegenVisitor( ) // Override `codegenContext` which carries the various symbol providers. + val moduleDocProvider = codegenDecorator.moduleDocumentationCustomization( + codegenContext, + PythonServerModuleDocProvider(ServerModuleDocProvider(codegenContext)), + ) codegenContext = ServerCodegenContext( model, serverSymbolProviders.symbolProvider, - null, + moduleDocProvider, service, protocol, settings, @@ -117,13 +120,6 @@ class PythonServerCodegenVisitor( serverSymbolProviders.pubCrateConstrainedShapeSymbolProvider, ) - codegenContext = codegenContext.copy( - moduleDocProvider = codegenDecorator.moduleDocumentationCustomization( - codegenContext, - PythonServerModuleDocProvider(ServerModuleDocProvider(codegenContext)), - ), - ) - // Override `rustCrate` which carries the symbolProvider. rustCrate = RustCrate( context.fileManifest, @@ -214,6 +210,10 @@ class PythonServerCodegenVisitor( } } + override fun protocolTests() { + logger.warning("[python-server-codegen] Protocol tests are disabled for this language") + } + /** * Generate service-specific code for the model: * - Serializers diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index b8bce1984..52381ed5c 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -556,6 +556,15 @@ open class ServerCodegenVisitor( } } + /** + * Generate protocol tests. This method can be overridden by other languages such has Python. + */ + open fun protocolTests() { + rustCrate.withModule(ServerRustModule.Operation) { + ServerProtocolTestGenerator(codegenContext, protocolGeneratorFactory.support(), protocolGenerator).render(this) + } + } + /** * Generate service-specific code for the model: * - Serializers @@ -583,9 +592,7 @@ open class ServerCodegenVisitor( } // Generate protocol tests - rustCrate.withModule(ServerRustModule.Operation) { - ServerProtocolTestGenerator(codegenContext, protocolGeneratorFactory.support(), protocolGenerator).render(this) - } + protocolTests() // Generate service module rustCrate.withModule(ServerRustModule.Service) { @@ -598,17 +605,25 @@ open class ServerCodegenVisitor( /** * For each operation shape generate: + * - Operations ser/de * - Errors via `ServerOperationErrorGenerator` * - OperationShapes via `ServerOperationGenerator` */ override fun operationShape(shape: OperationShape) { + // Generate errors. rustCrate.withModule(ServerRustModule.Error) { ServerOperationErrorGenerator(model, codegenContext.symbolProvider, shape).render(this) } + // Generate operation shapes. rustCrate.withModule(ServerRustModule.OperationShape) { ServerOperationGenerator(shape, codegenContext).render(this) } + + // Generate operations ser/de. + rustCrate.withModule(ServerRustModule.Operation) { + protocolGenerator.renderOperation(this, shape) + } } override fun blobShape(shape: BlobShape) { diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index 8e98e95db..2a2564808 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -138,7 +138,6 @@ class ServerProtocolTestGenerator( fun render(writer: RustWriter) { for (operation in operations) { - protocolGenerator.renderOperation(writer, operation) renderOperationTestCases(operation, writer) } } -- GitLab