From 780e13a75a2be2955c1905a33f5d57fefcda142f Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Mon, 5 Jun 2023 17:15:45 -0700 Subject: [PATCH] fix: add constant str for enums to support deepcopy operation (#5265) * fix: add constant str for enums to support deepcopy operation * add unit tests * formatting --- samcli/lib/providers/provider.py | 17 ++++++++++------- tests/unit/lib/build_module/test_build_graph.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/samcli/lib/providers/provider.py b/samcli/lib/providers/provider.py index bdf657cfe8..98e05051bf 100644 --- a/samcli/lib/providers/provider.py +++ b/samcli/lib/providers/provider.py @@ -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 ( @@ -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: """ diff --git a/tests/unit/lib/build_module/test_build_graph.py b/tests/unit/lib/build_module/test_build_graph.py index e0d1f524c9..4866777e8b 100644 --- a/tests/unit/lib/build_module/test_build_graph.py +++ b/tests/unit/lib/build_module/test_build_graph.py @@ -1,3 +1,4 @@ +import copy import os.path from unittest import TestCase from unittest.mock import patch, Mock @@ -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)