Skip to content

Commit

Permalink
Correct unittest test_lobster_read_missing_data_key
Browse files Browse the repository at this point in the history
  • Loading branch information
DiFerMa authored and mugdhadhole1 committed Oct 29, 2024
1 parent 5847e7f commit 8a34029
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lobster/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion test-unit/test_io.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 8a34029

Please sign in to comment.