Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add test for iterator exhaustion with next #2273

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines +197 to +203
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really just causes the error to cover the iterator exhaustion case for next and so is somewhat of a bad test, but we'd need to add a custom exception here otherwise and I'm not sure if that is worth it.


assert get_legend_handles_labels.called