Skip to content

Commit 08368f7

Browse files
committed
[test] Add a test to check the priority of show and savefig
Since plt.savefig and plt.show do not work at the same time due to the matplotlib design, we need to check whether show will not be called when a figname is specified. We can actually raise an error, but plot will be basically called in the end of an optimization, so I wanted to avoid raising an error and just sticked to a check by tests.
1 parent 26c8c1a commit 08368f7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

test/test_utils/test_results_visualizer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ def test_extract_dicts(cl_settings, with_ensemble):
5555

5656
@pytest.mark.parametrize('params', (
5757
PlotSettingParams(show=True),
58-
PlotSettingParams(show=False)
58+
PlotSettingParams(show=False),
59+
PlotSettingParams(show=True, figname='dummy')
5960
))
6061
def test_plt_show_in_set_plot_args(params): # TODO
6162
plt.show = MagicMock()
63+
plt.savefig = MagicMock()
6264
_, ax = plt.subplots(nrows=1, ncols=1)
6365
viz = ResultsVisualizer()
6466

6567
viz._set_plot_args(ax, params)
66-
assert plt.show._mock_called == params.show
68+
# if figname is not None, show will not be called. (due to the matplotlib design)
69+
assert plt.show._mock_called == (params.figname is None and params.show)
6770
plt.close()
6871

6972

0 commit comments

Comments
 (0)