From 7a36b030fe8e3f75738d5df94541084160624853 Mon Sep 17 00:00:00 2001 From: Wing Fung Lau <4760060+hawflau@users.noreply.github.com> Date: Fri, 28 Jul 2023 14:28:57 -0700 Subject: [PATCH 1/2] Update InvalidSamDocumentException to a subclass of UserException --- samcli/commands/validate/lib/exceptions.py | 4 +++- tests/unit/commands/list/resources/test_resources_context.py | 2 +- tests/unit/commands/validate/test_cli.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/samcli/commands/validate/lib/exceptions.py b/samcli/commands/validate/lib/exceptions.py index 96aa3f6008..0348f223da 100644 --- a/samcli/commands/validate/lib/exceptions.py +++ b/samcli/commands/validate/lib/exceptions.py @@ -2,8 +2,10 @@ Custom Exceptions for 'sam validate' commands """ +from samcli.commands.exceptions import UserException -class InvalidSamDocumentException(Exception): + +class InvalidSamDocumentException(UserException): """ Exception for Invalid Sam Documents """ diff --git a/tests/unit/commands/list/resources/test_resources_context.py b/tests/unit/commands/list/resources/test_resources_context.py index 298aef8d53..02e001a370 100644 --- a/tests/unit/commands/list/resources/test_resources_context.py +++ b/tests/unit/commands/list/resources/test_resources_context.py @@ -325,7 +325,7 @@ def test_get_translate_dict_invalid_template_error( } }, } - mock_get_translated_template_if_valid.side_effect = InvalidSamDocumentException() + mock_get_translated_template_if_valid.side_effect = InvalidSamDocumentException("") with self.assertRaises(InvalidSamTemplateException): resource_producer = ResourceMappingProducer( stack_name=None, diff --git a/tests/unit/commands/validate/test_cli.py b/tests/unit/commands/validate/test_cli.py index c19f5d0377..762a24ffa2 100644 --- a/tests/unit/commands/validate/test_cli.py +++ b/tests/unit/commands/validate/test_cli.py @@ -49,7 +49,7 @@ def test_template_fails_validation(self, patched_boto, read_sam_file_patch, clic read_sam_file_patch.return_value = {"a": "b"} get_translated_template_if_valid_mock = Mock() - get_translated_template_if_valid_mock.get_translated_template_if_valid.side_effect = InvalidSamDocumentException + get_translated_template_if_valid_mock.get_translated_template_if_valid.side_effect = InvalidSamDocumentException("") template_valiadator.return_value = get_translated_template_if_valid_mock with self.assertRaises(InvalidSamTemplateException): From 80d093cf198e2dcc2744293618f8d62121e6688b Mon Sep 17 00:00:00 2001 From: Wing Fung Lau <4760060+hawflau@users.noreply.github.com> Date: Fri, 28 Jul 2023 15:13:43 -0700 Subject: [PATCH 2/2] run black reformat --- tests/unit/commands/validate/test_cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/commands/validate/test_cli.py b/tests/unit/commands/validate/test_cli.py index 762a24ffa2..8f5d256045 100644 --- a/tests/unit/commands/validate/test_cli.py +++ b/tests/unit/commands/validate/test_cli.py @@ -49,7 +49,9 @@ def test_template_fails_validation(self, patched_boto, read_sam_file_patch, clic read_sam_file_patch.return_value = {"a": "b"} get_translated_template_if_valid_mock = Mock() - get_translated_template_if_valid_mock.get_translated_template_if_valid.side_effect = InvalidSamDocumentException("") + get_translated_template_if_valid_mock.get_translated_template_if_valid.side_effect = ( + InvalidSamDocumentException("") + ) template_valiadator.return_value = get_translated_template_if_valid_mock with self.assertRaises(InvalidSamTemplateException):