Skip to content

Commit

Permalink
Add test for disabled processors
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-bdufour committed Dec 6, 2024
1 parent a030a65 commit eac2521
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/snowflake/cli/_plugins/nativeapp/codegen/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
38 changes: 38 additions & 0 deletions tests/nativeapp/codegen/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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()

0 comments on commit eac2521

Please sign in to comment.