Skip to content

Commit ce3dbb8

Browse files
committed
Add io.BytesIO test
1 parent b31d97a commit ce3dbb8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/python/plotly/plotly/tests/test_optional/test_kaleido/test_kaleido.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import plotly.io.kaleido
33
import sys
44
from contextlib import contextmanager
5+
from io import BytesIO
56

67
try:
78
from pathlib import Path
@@ -147,3 +148,13 @@ def test_image_renderer():
147148
height=renderer.height,
148149
scale=renderer.scale,
149150
)
151+
152+
153+
def test_bytesio():
154+
# Verify that writing to a BytesIO object contains the same data as with to_image().
155+
bio = BytesIO()
156+
pio.write_image(fig, bio, format="jpg", engine="kaleido", validate=False)
157+
bio.seek(0)
158+
bio_bytes = bio.read()
159+
to_image_bytes = pio.to_image(fig, format="jpg", engine="kaleido", validate=False)
160+
assert bio_bytes == to_image_bytes

packages/python/plotly/plotly/tests/test_orca/test_to_image.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
import sys
88
import pandas as pd
9+
from io import BytesIO
910

1011
if sys.version_info >= (3, 3):
1112
from unittest.mock import MagicMock
@@ -339,3 +340,13 @@ def test_invalid_figure_json():
339340
)
340341

341342
assert "400: invalid or malformed request syntax" in str(err.value)
343+
344+
345+
def test_bytesio():
346+
# Verify that writing to a BytesIO object contains the same data as with to_image().
347+
bio = BytesIO()
348+
pio.write_image(fig1, bio, format="jpg", validate=False)
349+
bio.seek(0)
350+
bio_bytes = bio.read()
351+
to_image_bytes = pio.to_image(fig1, format="jpg", validate=False)
352+
assert bio_bytes == to_image_bytes

0 commit comments

Comments
 (0)