Skip to content

Commit

Permalink
Use mocker over unittest.mock
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfeickert committed Aug 10, 2023
1 parent 505753b commit ba052fa
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tests/contrib/test_viz.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import sys
from unittest.mock import patch

import matplotlib
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -184,7 +183,7 @@ def test_plot_results_components_data_structure(datadir):
)


def test_plot_results_wrong_axis_labels(datadir):
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
Expand All @@ -195,12 +194,12 @@ def test_plot_results_wrong_axis_labels(datadir):
fig = Figure()
ax = fig.subplots()

with patch(
"matplotlib.axes._axes.Axes.get_legend_handles_labels"
) as mock_get_legend_handles_labels:
mock_get_legend_handles_labels.return_value = None, ["fail"]
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)
with pytest.raises(StopIteration):
brazil.plot_results(data["testmus"], data["results"], test_size=0.05, ax=ax)

mock_get_legend_handles_labels.assert_called()
assert get_legend_handles_labels.called

0 comments on commit ba052fa

Please sign in to comment.