Skip to content

Commit

Permalink
test: Add test for iterator exhaustion with next (#2273)
Browse files Browse the repository at this point in the history
* Add test to tests/contrib/test_viz.py to cover the case where the
  wrong labels are somehow returned in brazil.plot_results, causing the
  legend label ordering logic to fail.
* Amends PR #2264
  • Loading branch information
matthewfeickert authored Aug 10, 2023
1 parent 6f8ad2e commit 852a224
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/contrib/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,25 @@ def test_plot_results_components_data_structure(datadir):
brazil.plot_results(
data["testmus"], data["results"], test_size=0.05, ax=ax, components=True
)


def test_plot_results_wrong_axis_labels(datadir, mocker):
"""
If the returned labels are different from the expected, then the hardcoded
values in label_part will be wrong, causing `next` to fail on the iterator
for label_idx.
"""
data = json.load(datadir.joinpath("hypotest_results.json").open(encoding="utf-8"))

fig = Figure()
ax = fig.subplots()

get_legend_handles_labels = mocker.patch(
"matplotlib.axes._axes.Axes.get_legend_handles_labels",
return_value=(None, ["fail"]),
)

with pytest.raises(StopIteration):
brazil.plot_results(data["testmus"], data["results"], test_size=0.05, ax=ax)

assert get_legend_handles_labels.called

0 comments on commit 852a224

Please sign in to comment.