diff --git a/lobster/io.py b/lobster/io.py index 22eb7292..3feb737b 100644 --- a/lobster/io.py +++ b/lobster/io.py @@ -77,7 +77,8 @@ def lobster_read(mh, filename, level, items, source_info=None): for rkey in ("schema", "version", "generator", "data"): if rkey not in data: - mh.error(loc, "required top-levelkey %s not present" % rkey) + mh.error(loc, "required top-level key %s not present" % rkey) + return # Stop execution to avoid missing key error of next 'if' if rkey == "data": if not isinstance(data[rkey], list): mh.error(loc, "data is not an array") diff --git a/test-unit/test_io.py b/test-unit/test_io.py index 8fd36afc..331a4a11 100644 --- a/test-unit/test_io.py +++ b/test-unit/test_io.py @@ -1,4 +1,5 @@ import unittest +from unittest.mock import ANY import io import json from unittest.mock import patch, MagicMock, create_autospec, mock_open @@ -182,7 +183,8 @@ def test_lobster_read_valid(self, mock_open, mock_isfile): @patch("builtins.open", new_callable=unittest.mock.mock_open, read_data='{"schema": "lobster-req-trace", "version": 4, "generator": "mock_generator"}') def test_lobster_read_missing_data_key(self, mock_open, mock_isfile): lobster_read(self.mh, self.filename, self.level, self.items, self.source_info) - self.mh.error.assert_called_with(File_Reference(self.filename), "required top-level key data not present") + # Allow any File_Reference object, but striclty check the string of the error message + self.mh.error.assert_called_with(ANY, "required top-level key data not present") @patch("os.path.isfile", return_value=True) @patch("builtins.open", new_callable=mock_open, read_data='invalid')