Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/openjd/adaptor_runtime/_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,14 @@ def _load_data(data: str) -> dict:

def _load_yaml_json(data: str) -> Any:
"""
Loads a YAML/JSON file/string.
Loads a YAML/JSON file/string using the UTF-8 encoding.

Note that yaml.safe_load() is capable of loading JSON documents.
"""
loaded_yaml = None
if data.startswith("file://"):
filepath = data[len("file://") :]
with open(filepath) as yaml_file:
with open(filepath, encoding="utf-8") as yaml_file:
loaded_yaml = yaml.safe_load(yaml_file)
else:
loaded_yaml = yaml.safe_load(data)
Expand Down
8 changes: 5 additions & 3 deletions test/openjd/adaptor_runtime/unit/test_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,14 @@ def test_accepts_file(self, input: str, expected: dict):

# WHEN
open_mock: MagicMock
with patch.object(runtime_entrypoint, "open", mock_open(read_data=input)) as open_mock:
with patch.object(
runtime_entrypoint, "open", mock_open(read_data=input), "encoding=utf8"
) as open_mock:
output = _load_data(file_uri)

# THEN
assert output == expected
open_mock.assert_called_once_with(filepath)
open_mock.assert_called_once_with(filepath, encoding="utf-8")

@patch.object(runtime_entrypoint, "open")
def test_raises_on_os_error(self, mock_open: MagicMock, caplog: pytest.LogCaptureFixture):
Expand All @@ -880,7 +882,7 @@ def test_raises_on_os_error(self, mock_open: MagicMock, caplog: pytest.LogCaptur

# THEN
assert raised_err.value is mock_open.side_effect
mock_open.assert_called_once_with(filepath)
mock_open.assert_called_once_with(filepath, encoding="utf-8")
assert "Failed to open data file: " in caplog.text

def test_raises_when_parsing_fails(self, caplog: pytest.LogCaptureFixture):
Expand Down
Loading