Skip to content

Commit

Permalink
Mock matplotlib figure in plotting tests
Browse files Browse the repository at this point in the history
Fix CI/CD by mocking matplotlib figure in plotting tests.
  • Loading branch information
alexbolfa committed Dec 24, 2023
1 parent 4ce02c1 commit cf7d76b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/napari_psf_extractor/_tests/test_plotting.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]}
Expand All @@ -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
)

0 comments on commit cf7d76b

Please sign in to comment.