From eac2521cfb6189383513e716019e68217c247f67 Mon Sep 17 00:00:00 2001 From: Bruno Dufour Date: Thu, 5 Dec 2024 21:52:05 -0500 Subject: [PATCH] Add test for disabled processors --- .../_plugins/nativeapp/codegen/compiler.py | 8 ++-- tests/nativeapp/codegen/test_compiler.py | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/snowflake/cli/_plugins/nativeapp/codegen/compiler.py b/src/snowflake/cli/_plugins/nativeapp/codegen/compiler.py index 2151c25794..0339ff9467 100644 --- a/src/snowflake/cli/_plugins/nativeapp/codegen/compiler.py +++ b/src/snowflake/cli/_plugins/nativeapp/codegen/compiler.py @@ -62,11 +62,11 @@ def __init__( # dictionary of all processors created and shared between different artifact objects. self.cached_processors: Dict[str, ArtifactProcessor] = {} - self._register(SnowparkAnnotationProcessor) - self._register(NativeAppSetupProcessor) - self._register(TemplatesProcessor) + self.register(SnowparkAnnotationProcessor) + self.register(NativeAppSetupProcessor) + self.register(TemplatesProcessor) - def _register(self, processor_cls: ProcessorClassType): + def register(self, processor_cls: ProcessorClassType): """ Registers a processor class to enable. """ diff --git a/tests/nativeapp/codegen/test_compiler.py b/tests/nativeapp/codegen/test_compiler.py index 4ec64ef983..7da3382588 100644 --- a/tests/nativeapp/codegen/test_compiler.py +++ b/tests/nativeapp/codegen/test_compiler.py @@ -13,10 +13,12 @@ # limitations under the License. import re from pathlib import Path +from typing import Optional import pytest from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext from snowflake.cli._plugins.nativeapp.codegen.artifact_processor import ( + ArtifactProcessor, UnsupportedArtifactProcessorError, ) from snowflake.cli._plugins.nativeapp.codegen.compiler import NativeAppCompiler @@ -29,6 +31,10 @@ from snowflake.cli.api.project.schemas.project_definition import ( build_project_definition, ) +from snowflake.cli.api.project.schemas.v1.native_app.path_mapping import ( + PathMapping, + ProcessorMapping, +) @pytest.fixture() @@ -114,3 +120,35 @@ def test_find_and_execute_processors_exception(test_proj_def, test_compiler): with pytest.raises(UnsupportedArtifactProcessorError): test_compiler.compile_artifacts() + + +class TestProcessor(ArtifactProcessor): + NAME = "test_processor" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + assert False # never invoked + + @staticmethod + def is_enabled(): + return False + + def process( + self, + artifact_to_process: PathMapping, + processor_mapping: Optional[ProcessorMapping], + **kwargs, + ) -> None: + assert False # never invoked + + +def test_skips_disabled_processors(test_proj_def, test_compiler): + pkg_model = test_proj_def.entities["pkg"] + pkg_model.artifacts = [ + {"dest": "./", "src": "app/*", "processors": ["test_processor"]} + ] + test_compiler = NativeAppCompiler(_get_bundle_context(pkg_model)) + test_compiler.register(TestProcessor) + + # TestProcessor is never invoked, otherwise calling its methods will make the test fail + test_compiler.compile_artifacts()