Skip to content

Commit

Permalink
fix: add constant str for enums to support deepcopy operation (aws#5265)
Browse files Browse the repository at this point in the history
* fix: add constant str for enums to support deepcopy operation

* add unit tests

* formatting
  • Loading branch information
mndeveci authored and moelasmar committed Jun 13, 2023
1 parent cc0d3b5 commit 780e13a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 10 additions & 7 deletions samcli/lib/providers/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import posixpath
from collections import namedtuple
from enum import Enum, auto
from enum import Enum
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, NamedTuple, Optional, Set, Union, cast

from samcli.commands.local.cli_common.user_exceptions import (
Expand Down Expand Up @@ -43,13 +43,16 @@ class FunctionBuildInfo(Enum):
"""

# buildable
BuildableZip = auto(), "Regular ZIP function which can be build with SAM CLI"
BuildableImage = auto(), "Regular IMAGE function which can be build with SAM CLI"
BuildableZip = "BuildableZip", "Regular ZIP function which can be build with SAM CLI"
BuildableImage = "BuildableImage", "Regular IMAGE function which can be build with SAM CLI"
# non-buildable
InlineCode = auto(), "A ZIP function which has inline code, non buildable"
PreZipped = auto(), "A ZIP function which points to a .zip file, non buildable"
SkipBuild = auto(), "A Function which is denoted with SkipBuild in metadata, non buildable"
NonBuildableImage = auto(), "An IMAGE function which is missing some information to build, non buildable"
InlineCode = "InlineCode", "A ZIP function which has inline code, non buildable"
PreZipped = "PreZipped", "A ZIP function which points to a .zip file, non buildable"
SkipBuild = "SkipBuild", "A Function which is denoted with SkipBuild in metadata, non buildable"
NonBuildableImage = (
"NonBuildableImage",
"An IMAGE function which is missing some information to build, non buildable",
)

def is_buildable(self) -> bool:
"""
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/lib/build_module/test_build_graph.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import os.path
from unittest import TestCase
from unittest.mock import patch, Mock
Expand Down Expand Up @@ -961,3 +962,17 @@ def test_build_folder_with_multiple_functions(self, build_improvements_22_enable
build_definition.get_build_dir("build_dir"),
build_definition.functions[0].get_build_dir("build_dir") + "-Shared",
)

def test_deepcopy_build_definition(self):
build_definition = FunctionBuildDefinition(
"runtime", "codeuri", ZIP, ARM64, {}, "handler", "source_hash", "manifest_hash"
)
function1 = generate_function(runtime="runtime", codeuri="codeuri", handler="handler")
function2 = generate_function(runtime="runtime", codeuri="codeuri", handler="handler")
build_definition.add_function(function1)
build_definition.add_function(function2)
build_definitions = [build_definition]

copied_build_definitions = copy.deepcopy(build_definitions)

self.assertEqual(copied_build_definitions, build_definitions)

0 comments on commit 780e13a

Please sign in to comment.