From cf7d76bef967e3affef70009902bad62b77c946c Mon Sep 17 00:00:00 2001 From: Alexandru Bolfa Date: Sun, 24 Dec 2023 14:41:24 +0200 Subject: [PATCH] Mock matplotlib figure in plotting tests Fix CI/CD by mocking matplotlib figure in plotting tests. --- src/napari_psf_extractor/_tests/test_plotting.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/napari_psf_extractor/_tests/test_plotting.py b/src/napari_psf_extractor/_tests/test_plotting.py index e2277ba..442a13c 100644 --- a/src/napari_psf_extractor/_tests/test_plotting.py +++ b/src/napari_psf_extractor/_tests/test_plotting.py @@ -1,5 +1,5 @@ import unittest -from unittest.mock import patch +from unittest.mock import patch, Mock import numpy as np import pandas as pd @@ -9,9 +9,14 @@ class TestPlotting(unittest.TestCase): @patch('matplotlib.axes.Axes') - def test_plot_mass_range_aspect_ratio(self, mock_axes): + @patch('matplotlib.pyplot.gcf') + def test_plot_mass_range_aspect_ratio(self, mock_gcf, mock_axes): # Given + mock_fig = Mock() + mock_fig.dpi = 1 + mock_gcf.return_value = mock_fig ax = mock_axes + mip = np.ones((10, 10), dtype=np.float64) # Ensure dtype is float64 mass = (1, 4) features_data = {'raw_mass': [2, 3], 'x': [1, 2], 'y': [3, 4]} @@ -23,3 +28,7 @@ def test_plot_mass_range_aspect_ratio(self, mock_axes): # Then expected = mip.shape[1] / mip.shape[0] ax.set_aspect.assert_called_once_with(expected) + mock_fig.set_size_inches.assert_called_once_with( + mip.shape[1] / mock_fig.dpi, + mip.shape[0] / mock_fig.dpi + )