diff --git a/aws_lambda_builders/workflow.py b/aws_lambda_builders/workflow.py index 3a881fd3a..f0dfb9ebc 100644 --- a/aws_lambda_builders/workflow.py +++ b/aws_lambda_builders/workflow.py @@ -6,6 +6,7 @@ import logging from collections import namedtuple +from enum import Enum from aws_lambda_builders.binary_path import BinaryPath from aws_lambda_builders.path_resolver import PathResolver @@ -37,6 +38,21 @@ class BuildMode(object): RELEASE = "release" +class BuildInSourceSupport(Enum): + """ + Enum to define a workflow's support for building in source. + """ + + # can't build in source directory (e.g. only able to build in temporary or artifacts directories) + NOT_SUPPORTED = [False] + + # can build in source directory but not required to + OPTIONALLY_SUPPORTED = [False, True] + + # only able to build in source directory and not somewhere else + EXCLUSIVELY_SUPPORTED = [True] + + # TODO: Move sanitize out to its own class. def sanitize(func): # pylint: disable=too-many-statements """ @@ -124,6 +140,15 @@ def __new__(mcs, name, bases, class_dict): if not isinstance(cls.CAPABILITY, Capability): raise ValueError("Workflow '{}' must register valid capabilities".format(cls.NAME)) + # All workflows must define valid default and supported values for build in source + if ( + not isinstance(cls.BUILD_IN_SOURCE_SUPPORT, BuildInSourceSupport) + or cls.BUILD_IN_SOURCE_BY_DEFAULT not in cls.BUILD_IN_SOURCE_SUPPORT.value + ): + raise ValueError( + "Workflow '{}' must define valid default and supported values for build in source".format(cls.NAME) + ) + LOG.debug("Registering workflow '%s' with capability '%s'", cls.NAME, cls.CAPABILITY) DEFAULT_REGISTRY[cls.CAPABILITY] = cls @@ -148,6 +173,12 @@ class BaseWorkflow(object, metaclass=_WorkflowMetaClass): # Optional list of manifests file/folder names supported by this workflow. SUPPORTED_MANIFESTS = [] + # Whether the workflow builds in source by default, each workflow should define this. + # (some workflows build in temporary or artifact directories by default) + BUILD_IN_SOURCE_BY_DEFAULT = None + # Support for building in source, each workflow should define this. + BUILD_IN_SOURCE_SUPPORT = None + def __init__( self, source_dir, @@ -229,7 +260,18 @@ def __init__( self.architecture = architecture self.is_building_layer = is_building_layer self.experimental_flags = experimental_flags if experimental_flags else [] + self.build_in_source = build_in_source + if build_in_source not in self.BUILD_IN_SOURCE_SUPPORT.value: + # only show warning if an unsupported value was explicitly passed in + if build_in_source is not None: + LOG.warning( + 'Workflow %s does not support value "%s" for building in source. Using default value "%s".', + self.NAME, + build_in_source, + self.BUILD_IN_SOURCE_BY_DEFAULT, + ) + self.build_in_source = self.BUILD_IN_SOURCE_BY_DEFAULT # Actions are registered by the subclasses as they seem fit self.actions = [] diff --git a/aws_lambda_builders/workflows/custom_make/workflow.py b/aws_lambda_builders/workflows/custom_make/workflow.py index 37b2cc469..208e9d469 100644 --- a/aws_lambda_builders/workflows/custom_make/workflow.py +++ b/aws_lambda_builders/workflows/custom_make/workflow.py @@ -2,7 +2,7 @@ ProvidedMakeWorkflow """ from aws_lambda_builders.workflows.custom_make.validator import CustomMakeRuntimeValidator -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, Capability, BuildInSourceSupport from aws_lambda_builders.actions import CopySourceAction from aws_lambda_builders.path_resolver import PathResolver from .actions import CustomMakeAction @@ -23,6 +23,9 @@ class CustomMakeWorkflow(BaseWorkflow): EXCLUDED_FILES = (".aws-sam", ".git") + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED + def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): super(CustomMakeWorkflow, self).__init__( @@ -44,10 +47,6 @@ def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtim subprocess_make = SubProcessMake(make_exe=self.binaries["make"].binary_path, osutils=self.os_utils) - # Don't build in source by default (backwards compatibility) - if build_in_source is None: - build_in_source = False - # an explicitly definied working directory should take precedence working_directory = options.get("working_directory") or self._select_working_directory( source_dir, scratch_dir, build_in_source diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py b/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py index cd79dc8c1..f514f31cf 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py @@ -1,7 +1,7 @@ """ .NET Core CLI Package Workflow """ -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, Capability, BuildInSourceSupport from .actions import GlobalToolInstallAction, RunPackageAction from .dotnetcli import SubprocessDotnetCLI @@ -19,6 +19,9 @@ class DotnetCliPackageWorkflow(BaseWorkflow): CAPABILITY = Capability(language="dotnet", dependency_manager="cli-package", application_framework=None) + BUILD_IN_SOURCE_BY_DEFAULT = True + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.EXCLUSIVELY_SUPPORTED + def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, mode=None, **kwargs): super(DotnetCliPackageWorkflow, self).__init__( diff --git a/aws_lambda_builders/workflows/go_modules/workflow.py b/aws_lambda_builders/workflows/go_modules/workflow.py index 94f3900d0..72ac03ba9 100644 --- a/aws_lambda_builders/workflows/go_modules/workflow.py +++ b/aws_lambda_builders/workflows/go_modules/workflow.py @@ -1,7 +1,7 @@ """ Go Modules Workflow """ -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, Capability, BuildInSourceSupport from .actions import GoModulesBuildAction from .builder import GoModulesBuilder @@ -15,6 +15,9 @@ class GoModulesWorkflow(BaseWorkflow): CAPABILITY = Capability(language="go", dependency_manager="modules", application_framework=None) + BUILD_IN_SOURCE_BY_DEFAULT = True + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.EXCLUSIVELY_SUPPORTED + def __init__( self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, mode=None, **kwargs ): diff --git a/aws_lambda_builders/workflows/java_gradle/workflow.py b/aws_lambda_builders/workflows/java_gradle/workflow.py index a03d34a2d..9a2546dae 100644 --- a/aws_lambda_builders/workflows/java_gradle/workflow.py +++ b/aws_lambda_builders/workflows/java_gradle/workflow.py @@ -4,7 +4,7 @@ import hashlib import os from aws_lambda_builders.actions import CleanUpAction -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, Capability, BuildInSourceSupport from aws_lambda_builders.workflows.java.actions import JavaCopyDependenciesAction, JavaMoveDependenciesAction from aws_lambda_builders.workflows.java.utils import OSUtils @@ -25,6 +25,9 @@ class JavaGradleWorkflow(BaseWorkflow): INIT_FILE = "lambda-build-init.gradle" + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.NOT_SUPPORTED + def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs): super(JavaGradleWorkflow, self).__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) diff --git a/aws_lambda_builders/workflows/java_maven/workflow.py b/aws_lambda_builders/workflows/java_maven/workflow.py index 321fe86ab..da80d17ae 100644 --- a/aws_lambda_builders/workflows/java_maven/workflow.py +++ b/aws_lambda_builders/workflows/java_maven/workflow.py @@ -1,7 +1,7 @@ """ Java Maven Workflow """ -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, Capability, BuildInSourceSupport from aws_lambda_builders.actions import CopySourceAction, CleanUpAction from aws_lambda_builders.workflows.java.actions import JavaCopyDependenciesAction, JavaMoveDependenciesAction from aws_lambda_builders.workflows.java.utils import OSUtils @@ -28,6 +28,9 @@ class JavaMavenWorkflow(BaseWorkflow): EXCLUDED_FILES = (".aws-sam", ".git") + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.NOT_SUPPORTED + def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs): super(JavaMavenWorkflow, self).__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) diff --git a/aws_lambda_builders/workflows/nodejs_npm/workflow.py b/aws_lambda_builders/workflows/nodejs_npm/workflow.py index 7c8ffe897..7f71fdf2f 100644 --- a/aws_lambda_builders/workflows/nodejs_npm/workflow.py +++ b/aws_lambda_builders/workflows/nodejs_npm/workflow.py @@ -5,7 +5,7 @@ import logging from aws_lambda_builders.path_resolver import PathResolver -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, Capability, BuildInSourceSupport from aws_lambda_builders.actions import ( CopySourceAction, CleanUpAction, @@ -42,6 +42,9 @@ class NodejsNpmWorkflow(BaseWorkflow): CONFIG_PROPERTY = "aws_sam" + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.NOT_SUPPORTED + def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): super(NodejsNpmWorkflow, self).__init__( diff --git a/aws_lambda_builders/workflows/nodejs_npm_esbuild/workflow.py b/aws_lambda_builders/workflows/nodejs_npm_esbuild/workflow.py index 6da34ec35..1f6db83d8 100644 --- a/aws_lambda_builders/workflows/nodejs_npm_esbuild/workflow.py +++ b/aws_lambda_builders/workflows/nodejs_npm_esbuild/workflow.py @@ -7,7 +7,7 @@ from pathlib import Path from typing import List -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, Capability, BuildInSourceSupport from aws_lambda_builders.actions import ( CopySourceAction, CleanUpAction, @@ -44,6 +44,9 @@ class NodejsNpmEsbuildWorkflow(BaseWorkflow): CONFIG_PROPERTY = "aws_sam" + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.NOT_SUPPORTED + def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): super(NodejsNpmEsbuildWorkflow, self).__init__( diff --git a/aws_lambda_builders/workflows/python_pip/workflow.py b/aws_lambda_builders/workflows/python_pip/workflow.py index 183e6835f..a304226be 100644 --- a/aws_lambda_builders/workflows/python_pip/workflow.py +++ b/aws_lambda_builders/workflows/python_pip/workflow.py @@ -3,7 +3,7 @@ """ import logging -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, BuildInSourceSupport, Capability from aws_lambda_builders.actions import CopySourceAction, CleanUpAction, LinkSourceAction from aws_lambda_builders.workflows.python_pip.validator import PythonRuntimeValidator from aws_lambda_builders.path_resolver import PathResolver @@ -67,6 +67,9 @@ class PythonPipWorkflow(BaseWorkflow): PYTHON_VERSION_THREE = "3" + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.NOT_SUPPORTED + def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): super(PythonPipWorkflow, self).__init__( diff --git a/aws_lambda_builders/workflows/ruby_bundler/workflow.py b/aws_lambda_builders/workflows/ruby_bundler/workflow.py index 801dd1f77..bc943affa 100644 --- a/aws_lambda_builders/workflows/ruby_bundler/workflow.py +++ b/aws_lambda_builders/workflows/ruby_bundler/workflow.py @@ -3,7 +3,7 @@ """ import logging -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, BuildInSourceSupport, Capability from aws_lambda_builders.actions import CopySourceAction, CopyDependenciesAction, CleanUpAction from .actions import RubyBundlerInstallAction, RubyBundlerVendorAction from .utils import OSUtils @@ -25,6 +25,9 @@ class RubyBundlerWorkflow(BaseWorkflow): EXCLUDED_FILES = (".aws-sam", ".git") + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.NOT_SUPPORTED + def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): super(RubyBundlerWorkflow, self).__init__( diff --git a/tests/functional/testdata/workflows/hello_workflow/write_hello.py b/tests/functional/testdata/workflows/hello_workflow/write_hello.py index a2cf94370..9987b1f5c 100644 --- a/tests/functional/testdata/workflows/hello_workflow/write_hello.py +++ b/tests/functional/testdata/workflows/hello_workflow/write_hello.py @@ -4,7 +4,7 @@ import os -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, BuildInSourceSupport, Capability from aws_lambda_builders.actions import BaseAction, Purpose @@ -34,6 +34,8 @@ class WriteHelloWorkflow(BaseWorkflow): NAME = "WriteHelloWorkflow" CAPABILITY = Capability(language="python", dependency_manager="test", application_framework="test") + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED def __init__(self, source_dir, artifacts_dir, *args, **kwargs): super(WriteHelloWorkflow, self).__init__(source_dir, artifacts_dir, *args, **kwargs) diff --git a/tests/unit/test_builder.py b/tests/unit/test_builder.py index b71aed5b2..ca99c058c 100644 --- a/tests/unit/test_builder.py +++ b/tests/unit/test_builder.py @@ -4,7 +4,7 @@ from parameterized import parameterized, param from aws_lambda_builders.builder import LambdaBuilder -from aws_lambda_builders.workflow import Capability, BaseWorkflow +from aws_lambda_builders.workflow import BuildInSourceSupport, Capability, BaseWorkflow from aws_lambda_builders.registry import DEFAULT_REGISTRY @@ -71,6 +71,8 @@ class MyWorkflow(BaseWorkflow): CAPABILITY = Capability( language=self.lang, dependency_manager=self.lang_framework, application_framework=self.app_framework ) + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED def __init__( self, diff --git a/tests/unit/test_workflow.py b/tests/unit/test_workflow.py index ad69bd5e4..523ea6731 100644 --- a/tests/unit/test_workflow.py +++ b/tests/unit/test_workflow.py @@ -1,6 +1,7 @@ import os import sys from unittest import TestCase +from parameterized import parameterized from mock import Mock, MagicMock, call @@ -11,7 +12,7 @@ from aws_lambda_builders.binary_path import BinaryPath from aws_lambda_builders.validator import RuntimeValidator -from aws_lambda_builders.workflow import BaseWorkflow, Capability +from aws_lambda_builders.workflow import BaseWorkflow, BuildInSourceSupport, Capability from aws_lambda_builders.registry import get_workflow, DEFAULT_REGISTRY from aws_lambda_builders.exceptions import ( WorkflowFailedError, @@ -40,6 +41,8 @@ def test_must_register_one_workflow(self): class TestWorkflow(BaseWorkflow): NAME = "TestWorkflow" CAPABILITY = self.CAPABILITY1 + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED result_cls = get_workflow(self.CAPABILITY1) self.assertEqual(len(DEFAULT_REGISTRY), 1) @@ -49,10 +52,14 @@ def test_must_register_two_workflows(self): class TestWorkflow1(BaseWorkflow): NAME = "TestWorkflow" CAPABILITY = self.CAPABILITY1 + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED class TestWorkflow2(BaseWorkflow): NAME = "TestWorkflow2" CAPABILITY = self.CAPABILITY2 + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED self.assertEqual(len(DEFAULT_REGISTRY), 2) self.assertEqual(get_workflow(self.CAPABILITY1), TestWorkflow1) @@ -64,6 +71,8 @@ def test_must_fail_if_name_not_present(self): class TestWorkflow1(BaseWorkflow): CAPABILITY = self.CAPABILITY1 + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED self.assertEqual(len(DEFAULT_REGISTRY), 0) self.assertEqual(str(ctx.exception), "Workflow must provide a valid name") @@ -74,6 +83,8 @@ def test_must_fail_if_capabilities_not_present(self): class TestWorkflow1(BaseWorkflow): NAME = "somename" + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED self.assertEqual(len(DEFAULT_REGISTRY), 0) self.assertEqual(str(ctx.exception), "Workflow 'somename' must register valid capabilities") @@ -85,10 +96,32 @@ def test_must_fail_if_capabilities_is_wrong_type(self): class TestWorkflow1(BaseWorkflow): NAME = "somename" CAPABILITY = "wrong data type" + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED self.assertEqual(len(DEFAULT_REGISTRY), 0) self.assertEqual(str(ctx.exception), "Workflow 'somename' must register valid capabilities") + @parameterized.expand( + [ + (None, BuildInSourceSupport.NOT_SUPPORTED), # default not defined + (False, None), # support not defined + (False, BuildInSourceSupport.EXCLUSIVELY_SUPPORTED), # default incompatible with support + (True, False), # support not instance of enum + ] + ) + def test_must_fail_if_build_in_source_variables_invalid(self, build_in_source_default, build_in_source_support): + + with self.assertRaises(ValueError) as ctx: + + class TestWorkflow1(BaseWorkflow): + NAME = "somename" + CAPABILITY = self.CAPABILITY1 + BUILD_IN_SOURCE_BY_DEFAULT = build_in_source_default + BUILD_IN_SOURCE_SUPPORT = build_in_source_support + + self.assertEqual(len(DEFAULT_REGISTRY), 0) + class TestBaseWorkflow_init(TestCase): class MyWorkflow(BaseWorkflow): @@ -97,6 +130,8 @@ class MyWorkflow(BaseWorkflow): CAPABILITY = Capability( language="test", dependency_manager="testframework", application_framework="appframework" ) + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED def test_must_initialize_variables(self): self.work = self.MyWorkflow( @@ -108,6 +143,7 @@ def test_must_initialize_variables(self): executable_search_paths=[str(sys.executable)], optimizations={"a": "b"}, options={"c": "d"}, + build_in_source=True, ) self.assertEqual(self.work.source_dir, "source_dir") @@ -119,6 +155,7 @@ def test_must_initialize_variables(self): self.assertEqual(self.work.optimizations, {"a": "b"}) self.assertEqual(self.work.options, {"c": "d"}) self.assertEqual(self.work.architecture, "x86_64") + self.assertTrue(self.work.build_in_source) class TestBaseWorkflow_is_supported(TestCase): @@ -128,6 +165,8 @@ class MyWorkflow(BaseWorkflow): CAPABILITY = Capability( language="test", dependency_manager="testframework", application_framework="appframework" ) + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED def setUp(self): self.work = self.MyWorkflow( @@ -174,6 +213,8 @@ class MyWorkflow(BaseWorkflow): CAPABILITY = Capability( language="test", dependency_manager="testframework", application_framework="appframework" ) + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED def setUp(self): self.work = self.MyWorkflow( @@ -359,6 +400,8 @@ class MyWorkflow(BaseWorkflow): CAPABILITY = Capability( language="test", dependency_manager="testframework", application_framework="appframework" ) + BUILD_IN_SOURCE_BY_DEFAULT = False + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED def setUp(self): self.action1 = Mock() @@ -394,3 +437,66 @@ def test_must_pretty_print_workflow_info(self): \tName=Action3, Purpose=COMPILE_SOURCE, Description=Compiles code""" self.assertEqual(result, expected) + + +class TestBaseWorkflow_build_in_source(TestCase): + @parameterized.expand([(True,), (False,)]) + def test_must_use_correct_default_value(self, default_value): + class MyWorkflow(BaseWorkflow): + __TESTING__ = True + NAME = "MyWorkflow" + CAPABILITY = Capability( + language="test", dependency_manager="testframework", application_framework="appframework" + ) + BUILD_IN_SOURCE_BY_DEFAULT = default_value + BUILD_IN_SOURCE_SUPPORT = BuildInSourceSupport.OPTIONALLY_SUPPORTED + + self.work = MyWorkflow( + "source_dir", + "artifacts_dir", + "scratch_dir", + "manifest_path", + runtime="runtime", + executable_search_paths=[str(sys.executable)], + optimizations={"a": "b"}, + options={"c": "d"}, + ) + + self.assertEqual(self.work.build_in_source, default_value) + + @parameterized.expand( + [ + (True, False, BuildInSourceSupport.NOT_SUPPORTED), # want to build in source but it's not supported + ( + False, + True, + BuildInSourceSupport.EXCLUSIVELY_SUPPORTED, + ), # don't want to build in source but workflow requires it + ("unsupported", False, BuildInSourceSupport.OPTIONALLY_SUPPORTED), # unsupported value passed in + ] + ) + def test_must_use_default_if_unsupported_value_is_provided( + self, build_in_source_value, build_in_source_default, build_in_source_support + ): + class MyWorkflow(BaseWorkflow): + __TESTING__ = True + NAME = "MyWorkflow" + CAPABILITY = Capability( + language="test", dependency_manager="testframework", application_framework="appframework" + ) + BUILD_IN_SOURCE_BY_DEFAULT = build_in_source_default + BUILD_IN_SOURCE_SUPPORT = build_in_source_support + + self.work = MyWorkflow( + "source_dir", + "artifacts_dir", + "scratch_dir", + "manifest_path", + runtime="runtime", + executable_search_paths=[str(sys.executable)], + optimizations={"a": "b"}, + options={"c": "d"}, + build_in_source=build_in_source_value, + ) + + self.assertEqual(self.work.build_in_source, build_in_source_default)