From 872851f7f69cb76edd4d2a23f49d4194db362a32 Mon Sep 17 00:00:00 2001 From: Tim Mok Date: Mon, 1 Apr 2024 14:56:00 -0400 Subject: [PATCH] Fix test --- .../positron/positron_ipykernel/tests/test_plots.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extensions/positron-python/pythonFiles/positron/positron_ipykernel/tests/test_plots.py b/extensions/positron-python/pythonFiles/positron/positron_ipykernel/tests/test_plots.py index 3902e3960fe6..3b4628a63205 100644 --- a/extensions/positron-python/pythonFiles/positron/positron_ipykernel/tests/test_plots.py +++ b/extensions/positron-python/pythonFiles/positron/positron_ipykernel/tests/test_plots.py @@ -2,7 +2,9 @@ # Copyright (C) 2023-2024 Posit Software, PBC. All rights reserved. # +import base64 import codecs +import io import pickle from pathlib import Path from typing import Iterable, cast @@ -204,16 +206,20 @@ def test_hook_render(figure_comm: DummyComm, images_path: Path) -> None: width_in = width_px / BASE_DPI height_in = height_px / BASE_DPI + fig_buffer = io.BytesIO() fig_ref = cast(Figure, plt.figure()) fig_axes = cast(Axes, fig_ref.subplots()) fig_axes.plot([1, 2]) fig_ref.set_dpi(dpi) fig_ref.set_size_inches(width_in, height_in) + fig_ref.set_layout_engine("tight") # Serialize the reference figure as a base64-encoded image - data_ref, _ = format_display_data(fig_ref, include=["image/png"], exclude=[]) # type: ignore + # data_ref, _ = format_display_data(fig_ref, include=["image/png"], exclude=[]) # type: ignore + fig_ref.savefig(fig_buffer, format="png", dpi=dpi) + fig_buffer.seek(0) expected = images_path / "test-hook-render-expected.png" - _save_base64_image(data_ref["image/png"], expected) + _save_base64_image(base64.b64encode(fig_buffer.read()).decode(), expected) # Compare the actual vs expected figures err = compare_images(str(actual), str(expected), tol=0)