diff --git a/src/openjd/adaptor_runtime/_entrypoint.py b/src/openjd/adaptor_runtime/_entrypoint.py index 23ad98d..1365b25 100644 --- a/src/openjd/adaptor_runtime/_entrypoint.py +++ b/src/openjd/adaptor_runtime/_entrypoint.py @@ -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) diff --git a/test/openjd/adaptor_runtime/unit/test_entrypoint.py b/test/openjd/adaptor_runtime/unit/test_entrypoint.py index 46adc5d..50e58ac 100644 --- a/test/openjd/adaptor_runtime/unit/test_entrypoint.py +++ b/test/openjd/adaptor_runtime/unit/test_entrypoint.py @@ -860,12 +860,12 @@ 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): @@ -880,7 +880,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):