|
1 | 1 | import datetime |
2 | 2 | import platform |
3 | 3 | import re |
| 4 | +from unittest import mock |
4 | 5 |
|
5 | 6 | import contourpy # type: ignore |
6 | 7 | import numpy as np |
@@ -234,6 +235,31 @@ def test_labels(split_collections): |
234 | 235 | _maybe_split_collections(split_collections) |
235 | 236 |
|
236 | 237 |
|
| 238 | +def test_label_contour_start(): |
| 239 | + # Set up data and figure/axes that result in automatic labelling adding the |
| 240 | + # label to the start of a contour |
| 241 | + |
| 242 | + _, ax = plt.subplots(dpi=100) |
| 243 | + lats = lons = np.linspace(-np.pi / 2, np.pi / 2, 50) |
| 244 | + lons, lats = np.meshgrid(lons, lats) |
| 245 | + wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons) |
| 246 | + mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2) |
| 247 | + data = wave + mean |
| 248 | + |
| 249 | + cs = ax.contour(lons, lats, data) |
| 250 | + |
| 251 | + with mock.patch.object( |
| 252 | + cs, '_split_path_and_get_label_rotation', |
| 253 | + wraps=cs._split_path_and_get_label_rotation) as mocked_splitter: |
| 254 | + # Smoke test that we can add the labels |
| 255 | + cs.clabel(fontsize=9) |
| 256 | + |
| 257 | + # Verify at least one label was added to the start of a contour. I.e. the |
| 258 | + # splitting method was called with idx=0 at least once. |
| 259 | + idxs = [cargs[0][1] for cargs in mocked_splitter.call_args_list] |
| 260 | + assert 0 in idxs |
| 261 | + |
| 262 | + |
237 | 263 | @pytest.mark.parametrize("split_collections", [False, True]) |
238 | 264 | @image_comparison(['contour_corner_mask_False.png', 'contour_corner_mask_True.png'], |
239 | 265 | remove_text=True, tol=1.88) |
|
0 commit comments