11from typing import Any , List , Tuple
2+ from unittest .mock import patch
23
34import matplotlib .pyplot as plt
45import numpy as np
56import pandas as pd
67import pytest
78import scipy .sparse
8- from pytest_mock .plugin import MockerFixture
99
1010from qolmat .utils import plot
1111
3838
3939
4040@pytest .mark .parametrize ("list_matrices" , [list_matrices ])
41+ @patch ("matplotlib.pyplot.show" )
42+ @patch ("matplotlib.pyplot.savefig" )
4143def test_utils_plot_plot_matrices (
42- list_matrices : List [np .ndarray ], mocker : MockerFixture
44+ mock_savefig , mock_show , list_matrices : List [np .ndarray ]
4345) -> None :
44- mocker .patch ("matplotlib.pyplot.savefig" )
45- mocker .patch ("matplotlib.pyplot.show" )
4646 plot .plot_matrices (list_matrices = list_matrices , title = "title" )
4747 assert len (plt .gcf ().get_axes ()) > 0
48- assert plt . savefig .call_count == 1
48+ assert mock_savefig .call_count == 1
4949 plt .close ("all" )
5050
5151
5252@pytest .mark .parametrize ("list_signals" , [list_signals ])
53+ @patch ("matplotlib.pyplot.show" )
54+ @patch ("matplotlib.pyplot.savefig" )
5355def test_utils_plot_plot_signal (
54- list_signals : List [List [Any ]], mocker : MockerFixture
56+ mock_savefig , mock_show , list_signals : List [List [Any ]]
5557) -> None :
56- mocker .patch ("matplotlib.pyplot.savefig" )
57- mocker .patch ("matplotlib.pyplot.show" )
5858 plot .plot_signal (list_signals = list_signals , ylabel = "ylabel" , title = "title" )
5959 assert len (plt .gcf ().get_axes ()) > 0
60- assert plt . savefig .call_count == 1
60+ assert mock_savefig .call_count == 1
6161 plt .close ("all" )
6262
6363
6464@pytest .mark .parametrize (
6565 "M, A, E, index_array, dims" , [(M , A , E , [0 , 1 , 2 ], (10 , 10 ))]
6666)
67+ @patch ("matplotlib.pyplot.show" )
68+ @patch ("matplotlib.pyplot.savefig" )
6769def test__utils_plot_plot_images (
70+ mock_savefig ,
71+ mock_show ,
6872 M : np .ndarray ,
6973 A : np .ndarray ,
7074 E : np .ndarray ,
7175 index_array : List [int ],
7276 dims : Tuple [int , int ],
73- mocker : MockerFixture ,
7477):
75- mocker .patch ("matplotlib.pyplot.savefig" )
76- mocker .patch ("matplotlib.pyplot.show" )
7778 plot .plot_images (M , A , E , index_array , dims , filename = "filename" )
7879 assert len (plt .gcf ().get_axes ()) > 0
79- assert plt . savefig .call_count == 1
80+ assert mock_savefig .call_count == 1
8081 plt .close ("all" )
8182
8283
8384@pytest .mark .parametrize ("X" , [X ])
84- def test_utils_plot_make_ellipses_from_data (
85- X : np .ndarray , mocker : MockerFixture
86- ):
87- mocker .patch ("matplotlib.pyplot.show" )
85+ @patch ("matplotlib.pyplot.show" )
86+ def test_utils_plot_make_ellipses_from_data (mock_show , X : np .ndarray ):
8887 ax = plt .gca ()
8988 plot .make_ellipses_from_data (X [1 ], X [2 ], ax , color = "blue" )
9089 assert len (plt .gcf ().get_axes ()) > 0
9190 plt .close ("all" )
9291
9392
9493@pytest .mark .parametrize ("df1,df2" , [(df1 , df2 )])
94+ @patch ("matplotlib.pyplot.show" )
9595def test_utils_plot_compare_covariances (
96- df1 : pd .DataFrame , df2 : pd .DataFrame , mocker : MockerFixture
96+ mock_show , df1 : pd .DataFrame , df2 : pd .DataFrame
9797):
98- mocker .patch ("matplotlib.pyplot.show" )
9998 ax = plt .gca ()
10099 plot .compare_covariances (df1 , df2 , "x" , "y" , ax )
101100 assert len (plt .gcf ().get_axes ()) > 0
@@ -104,18 +103,16 @@ def test_utils_plot_compare_covariances(
104103
105104@pytest .mark .parametrize ("df" , [df ])
106105@pytest .mark .parametrize ("orientation" , ["horizontal" , "vertical" ])
107- def test_utils_plot_multibar (
108- df : pd .DataFrame , orientation : str , mocker : MockerFixture
109- ):
110- mocker .patch ("matplotlib.pyplot.show" )
106+ @patch ("matplotlib.pyplot.show" )
107+ def test_utils_plot_multibar (mock_show , df : pd .DataFrame , orientation : str ):
111108 plot .multibar (df , orientation = orientation )
112109 assert len (plt .gcf ().get_axes ()) > 0
113110 plt .close ("all" )
114111
115112
116113@pytest .mark .parametrize ("df" , [df ])
117- def test_utils_plot_plot_imputations ( df : pd . DataFrame , mocker : MockerFixture ):
118- mocker . patch ( "matplotlib.pyplot.show" )
114+ @ patch ( "matplotlib.pyplot.show" )
115+ def test_utils_plot_plot_imputations ( mock_show , df : pd . DataFrame ):
119116 plot .plot_imputations (df , dict_df_imputed )
120117 assert len (plt .gcf ().get_axes ()) > 0
121118 plt .close ("all" )
0 commit comments