From aabf95673ed025ac2e6e765ccc464689a63d5e5b Mon Sep 17 00:00:00 2001 From: rxxg Date: Tue, 17 Jan 2023 16:37:02 +0100 Subject: [PATCH 1/2] Handle Unicode characters on systems where utf-8 is not default --- packages/python/plotly/plotly/io/_html.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py index 606df721f33..a1cc2a61990 100644 --- a/packages/python/plotly/plotly/io/_html.py +++ b/packages/python/plotly/plotly/io/_html.py @@ -533,7 +533,8 @@ def write_html( # Write HTML string if path is not None: - path.write_text(html_str) + # To use a different file encoding, pass a file descriptor + path.write_text(html_str, "utf-8") else: file.write(html_str) From 1f86ff0f812e4ddb3db51988b6c650704c0165b5 Mon Sep 17 00:00:00 2001 From: rxxg Date: Tue, 17 Jan 2023 17:28:54 +0100 Subject: [PATCH 2/2] Fix test --- packages/python/plotly/plotly/tests/test_io/test_pathlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/tests/test_io/test_pathlib.py b/packages/python/plotly/plotly/tests/test_io/test_pathlib.py index 48eab2bb9e5..092ffe6a9a6 100644 --- a/packages/python/plotly/plotly/tests/test_io/test_pathlib.py +++ b/packages/python/plotly/plotly/tests/test_io/test_pathlib.py @@ -40,7 +40,7 @@ def test_write_html(): mock_pathlib_path = Mock(spec=Path) pio.write_html(fig, mock_pathlib_path) mock_pathlib_path.write_text.assert_called_once() - (pl_html,) = mock_pathlib_path.write_text.call_args[0] + pl_html = mock_pathlib_path.write_text.call_args[0][0] assert replace_div_id(html) == replace_div_id(pl_html) # Test pio.write_html with a mock file descriptor