Skip to content

Commit

Permalink
Issue#10: Exceptions from PyYaml are caught and displayed.
Browse files Browse the repository at this point in the history
Issue#10:  Exceptions from PyYaml are caught and displayed.
  • Loading branch information
jeremiah-c-leary authored Oct 21, 2023
2 parents 2bfb32c + dd1d87b commit cb95be4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions elfws/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
5 changes: 5 additions & 0 deletions tests/utils/error_suppress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

*something:
key1:
- value

9 changes: 9 additions & 0 deletions tests/utils/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit cb95be4

Please sign in to comment.