Skip to content

Commit

Permalink
[test] Add a test to check the priority of show and savefig
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nabenabe0928 committed Dec 1, 2021
1 parent 26c8c1a commit 08368f7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions test/test_utils/test_results_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ def test_extract_dicts(cl_settings, with_ensemble):

@pytest.mark.parametrize('params', (
PlotSettingParams(show=True),
PlotSettingParams(show=False)
PlotSettingParams(show=False),
PlotSettingParams(show=True, figname='dummy')
))
def test_plt_show_in_set_plot_args(params): # TODO
plt.show = MagicMock()
plt.savefig = MagicMock()
_, ax = plt.subplots(nrows=1, ncols=1)
viz = ResultsVisualizer()

viz._set_plot_args(ax, params)
assert plt.show._mock_called == params.show
# if figname is not None, show will not be called. (due to the matplotlib design)
assert plt.show._mock_called == (params.figname is None and params.show)
plt.close()


Expand Down

0 comments on commit 08368f7

Please sign in to comment.