Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve tag parsing performance for list input #7049

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samcli/cli/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def convert(self, value, param, ctx):
if isinstance(value, list):
if not value:
return result
value = " ".join(value)
value = tuple(value)
# if value comes in a via configuration file, it will be a string. So we should still convert it.
value = (value,) if not isinstance(value, tuple) else value

Expand Down
24 changes: 23 additions & 1 deletion tests/unit/cli/test_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unittest import TestCase
from unittest.mock import MagicMock, Mock, ANY
from unittest.mock import MagicMock, Mock, ANY, patch

from click import BadParameter
from parameterized import parameterized
Expand Down Expand Up @@ -244,6 +244,28 @@ def test_successful_parsing(self, input, expected):
result = self.param_type.convert(input, None, None)
self.assertEqual(result, expected, msg="Failed with Input = " + str(input))

@parameterized.expand(
[
(
["stage=int", "company:application=awesome-service", "company:department=engineering"],
{"stage": "int", "company:application": "awesome-service", "company:department": "engineering"},
),
(
['owner:name="son of anton"', "company:application=awesome-service", "company:department=engineering"],
{
"owner:name": "son of anton",
"company:application": "awesome-service",
"company:department": "engineering",
},
),
]
)
@patch("re.findall")
def test_no_regex_parsing_if_input_is_list(self, input, expected, regex_mock):
result = self.param_type.convert(input, None, None)
self.assertEqual(result, expected, msg="Failed with Input = " + str(input))
regex_mock.assert_not_called()


class TestCfnTagsMultipleValues(TestCase):
"""
Expand Down
Loading