From a0032978b190795b6d9b6a7422517c2094fddbc2 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Sun, 19 Jan 2025 14:48:40 +0000 Subject: [PATCH] Fix failing image scalebar export test --- rsciio/tests/test_image.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rsciio/tests/test_image.py b/rsciio/tests/test_image.py index d56ab602..307d092e 100644 --- a/rsciio/tests/test_image.py +++ b/rsciio/tests/test_image.py @@ -106,6 +106,8 @@ def test_save_load_cycle_kwds(dtype, ext, tmp_path): def test_export_scalebar(ext, tmp_path): hs = pytest.importorskip("hyperspy.api", reason="hyperspy not installed") pytest.importorskip("matplotlib_scalebar") + import matplotlib.pyplot as plt + # Use np.uint8 to be able to save as BMP pixels = 64 data = np.arange(pixels**2).reshape((pixels, pixels)).astype(np.uint8) @@ -114,14 +116,16 @@ def test_export_scalebar(ext, tmp_path): s.axes_manager[1].units = "nm" filename = tmp_path / f"test_scalebar_export.{ext}" - if ext in ["bmp", "gif"]: + if ext in plt.figure().canvas.get_supported_filetypes(): + s.save(filename, scalebar=True) + else: + # file format not supported by matplotlib backend with pytest.raises(ValueError): s.save(filename, scalebar=True) with pytest.raises(ValueError): s.save(filename, output_size=512) s.save(filename) - else: - s.save(filename, scalebar=True) + s_reload = hs.load(filename) assert s.data.shape == s_reload.data.shape