diff --git a/src/pyobsplot/obsplot.py b/src/pyobsplot/obsplot.py index fc119e95..c8af5fc7 100644 --- a/src/pyobsplot/obsplot.py +++ b/src/pyobsplot/obsplot.py @@ -294,5 +294,5 @@ def save_to_file(path: str, res: Union[SVG, HTML]) -> None: warnings.warn( f"Output is HTML but file extension is '{extension}'", RuntimeWarning ) - with open(path, "w") as f: + with open(path, "w", encoding="utf-8") as f: f.write(res.data) diff --git a/tests/python/test_obsplot.py b/tests/python/test_obsplot.py index 59de937d..009fda2b 100644 --- a/tests/python/test_obsplot.py +++ b/tests/python/test_obsplot.py @@ -174,3 +174,15 @@ def test_jsdom_server(self, oj): r.content.decode() == "Server error: Unexpected token h in JSON at position 1." ) + + +class TestSaveToFile: + def test_svg_with_negative_numbers(self, tmp_path, oj): + """If utf-8 isn't specified encoding a minus symbol raises 'charmap' codec can't encode character '\u2212'.""" + oj = Obsplot(renderer="jsdom") + oj( + Plot.tickX( + [-1], + ), + path=tmp_path / "test.svg", + )