Skip to content

Commit ab3b700

Browse files
committed
fix test_image_renderer() test to work with both kaleido v0 and v1
1 parent 2549299 commit ab3b700

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

tests/test_optional/test_kaleido/test_kaleido.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from io import BytesIO
1+
from io import BytesIO, StringIO
22
from pathlib import Path
33
import tempfile
4+
from contextlib import redirect_stdout
5+
import base64
46

57
from pdfrw import PdfReader
68
from PIL import Image
@@ -88,18 +90,23 @@ def test_kaleido_engine_write_image_kwargs(tmp_path):
8890

8991

9092
def test_image_renderer():
91-
# TODO: How to replicate this test using kaleido v1?
92-
# with mocked_scope() as scope:
93-
pio.show(fig, renderer="svg", engine="kaleido", validate=False)
94-
95-
renderer = pio.renderers["svg"]
96-
# scope.transform.assert_called_with(
97-
# fig,
98-
# format="svg",
99-
# width=None,
100-
# height=None,
101-
# scale=renderer.scale,
102-
# )
93+
"""Verify that the image renderer returns the expected mimebundle."""
94+
with redirect_stdout(StringIO()) as f:
95+
pio.show(fig, renderer="png", engine="kaleido", validate=False)
96+
mimebundle = f.getvalue().strip()
97+
mimebundle_expected = str(
98+
{
99+
"image/png": base64.b64encode(
100+
pio.to_image(
101+
fig,
102+
format="png",
103+
engine="kaleido",
104+
validate=False,
105+
)
106+
).decode("utf8")
107+
}
108+
)
109+
assert mimebundle == mimebundle_expected
103110

104111

105112
def test_bytesio():

0 commit comments

Comments
 (0)