Skip to content

Add encoding utf-8 for save_to_file #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2023
Merged
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
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",
)