File tree Expand file tree Collapse file tree 1 file changed +20
-13
lines changed
tests/test_optional/test_kaleido Expand file tree Collapse file tree 1 file changed +20
-13
lines changed Original file line number Diff line number Diff line change 1- from io import BytesIO
1+ from io import BytesIO , StringIO
22from pathlib import Path
33import tempfile
4+ from contextlib import redirect_stdout
5+ import base64
46
57from pdfrw import PdfReader
68from PIL import Image
@@ -88,18 +90,23 @@ def test_kaleido_engine_write_image_kwargs(tmp_path):
8890
8991
9092def 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
105112def test_bytesio ():
You can’t perform that action at this time.
0 commit comments