Skip to content

Commit

Permalink
test: update likelihood scan reference visualization for latest matpl…
Browse files Browse the repository at this point in the history
…otlib (#476)

* update legend positioning in likelihood scan visualization test reference
* update test to handle expected failure in Python 3.8
  • Loading branch information
alexander-held authored May 20, 2024
1 parent 9aa0447 commit 891fdb0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Binary file modified tests/visualize/reference/scan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 17 additions & 2 deletions tests/visualize/test_visualize_plot_result.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import sys
from unittest import mock

import matplotlib.pyplot as plt
from matplotlib.testing.compare import compare_images
import numpy as np
import pytest

from cabinetry.visualize import plot_result

Expand Down Expand Up @@ -117,6 +119,10 @@ def test_ranking(tmp_path):
plt.close("all")


@pytest.mark.xfail(
sys.version_info <= (3, 9),
reason="legend positioning in Python 3.8 with older matplotlib, see cabinetry#476",
)
def test_scan(tmp_path):
fname = tmp_path / "fig.png"
par_name = "a"
Expand All @@ -128,12 +134,18 @@ def test_scan(tmp_path):
fig = plot_result.scan(
par_name, par_mle, par_unc, par_vals, par_nlls, figure_path=fname
)
assert compare_images("tests/visualize/reference/scan.png", str(fname), 0) is None
# delay assert of comparison to be able to cover lines even with Python 3.8
comparison_results = []
comparison_results.append(
compare_images("tests/visualize/reference/scan.png", str(fname), 0)
)

# compare figure returned by function
fname = tmp_path / "fig_from_return.png"
fig.savefig(fname)
assert compare_images("tests/visualize/reference/scan.png", str(fname), 0) is None
comparison_results.append(
compare_images("tests/visualize/reference/scan.png", str(fname), 0)
)

# do not save figure, but close it
with mock.patch("cabinetry.visualize.utils._save_and_close") as mock_close_safe:
Expand All @@ -144,6 +156,9 @@ def test_scan(tmp_path):
)
assert mock_close_safe.call_args_list == [((fig, None, True), {})]

for comp_res in comparison_results:
assert comp_res is None

plt.close("all")


Expand Down

0 comments on commit 891fdb0

Please sign in to comment.