(monkeypatch)
| 1314 | |
| 1315 | |
| 1316 | def test_warn_big_data_best_loc(monkeypatch): |
| 1317 | # Force _find_best_position to think it took a long time. |
| 1318 | counter = itertools.count(0, step=1.5) |
| 1319 | monkeypatch.setattr(time, 'perf_counter', lambda: next(counter)) |
| 1320 | |
| 1321 | fig, ax = plt.subplots() |
| 1322 | fig.canvas.draw() # So that we can call draw_artist later. |
| 1323 | |
| 1324 | # Place line across all possible legend locations. |
| 1325 | x = [0.9, 0.1, 0.1, 0.9, 0.9, 0.5] |
| 1326 | y = [0.95, 0.95, 0.05, 0.05, 0.5, 0.5] |
| 1327 | ax.plot(x, y, 'o-', label='line') |
| 1328 | |
| 1329 | with rc_context({'legend.loc': 'best'}): |
| 1330 | legend = ax.legend() |
| 1331 | with pytest.warns(UserWarning, |
| 1332 | match='Creating legend with loc="best" can be slow with large ' |
| 1333 | 'amounts of data.') as records: |
| 1334 | fig.draw_artist(legend) # Don't bother drawing the lines -- it's slow. |
| 1335 | # The _find_best_position method of Legend is called twice, duplicating |
| 1336 | # the warning message. |
| 1337 | assert len(records) == 2 |
| 1338 | |
| 1339 | |
| 1340 | def test_no_warn_big_data_when_loc_specified(monkeypatch): |
nothing calls this directly
no test coverage detected
searching dependent graphs…