From dd1d87bc92228bcebe40197298d0fe877a06a37a Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Sat, 21 Oct 2023 09:34:31 -0500 Subject: [PATCH] Issue#10: Exceptions from PyYaml are caught and displayed. --- elfws/utils.py | 8 ++++++-- tests/utils/error_suppress.yaml | 5 +++++ tests/utils/test_functions.py | 9 +++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/utils/error_suppress.yaml diff --git a/elfws/utils.py b/elfws/utils.py index b19d219..3f55ed6 100644 --- a/elfws/utils.py +++ b/elfws/utils.py @@ -19,8 +19,12 @@ def read_suppression_file(sFileName): Returns: dictionary ''' - with open(sFileName) as yaml_file: - dReturn = yaml.full_load(yaml_file) + try: + with open(sFileName) as yaml_file: + dReturn = yaml.full_load(yaml_file) + except Exception as e: + print(e) + sys.exit(1) if dReturn is None: dReturn = {} diff --git a/tests/utils/error_suppress.yaml b/tests/utils/error_suppress.yaml new file mode 100644 index 0000000..3cfede1 --- /dev/null +++ b/tests/utils/error_suppress.yaml @@ -0,0 +1,5 @@ + +*something: + key1: + - value + diff --git a/tests/utils/test_functions.py b/tests/utils/test_functions.py index 101cc43..8bc27de 100644 --- a/tests/utils/test_functions.py +++ b/tests/utils/test_functions.py @@ -57,6 +57,15 @@ def test_read_suppression_file_w_empty_file(self): self.assertEqual(dExpected, dActual) + @mock.patch('sys.stdout') + def test_read_suppression_file_w_error(self, mock_stdout): + + try: + utils.read_suppression_file(os.path.join(os.path.dirname(__file__),'error_suppress.yaml')) + except SystemExit as e: + self.assertEqual(e.code, 1) + pass + def test_create_suppression_list(self): dSuppression = {}