Skip to content

Commit

Permalink
Merge pull request #22 from harrylojames/fix_write_svg
Browse files Browse the repository at this point in the history
fix: add encoding utf-8 for save_to_file
  • Loading branch information
juba committed Oct 13, 2023
2 parents 527548f + 4a73f63 commit 84bea33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pyobsplot/obsplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 12 additions & 0 deletions tests/python/test_obsplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

0 comments on commit 84bea33

Please sign in to comment.