|
8 | 8 |
|
9 | 9 | from matplotlib import (
|
10 | 10 | collections, path, pyplot as plt, transforms as mtransforms, rcParams)
|
11 |
| -from matplotlib.image import imread |
| 11 | +from matplotlib.backends.backend_agg import RendererAgg |
12 | 12 | from matplotlib.figure import Figure
|
| 13 | +from matplotlib.image import imread |
| 14 | +from matplotlib.path import Path |
13 | 15 | from matplotlib.testing.decorators import image_comparison
|
| 16 | +from matplotlib.transforms import IdentityTransform |
14 | 17 |
|
15 | 18 |
|
16 | 19 | def test_repeated_save_with_alpha():
|
@@ -251,3 +254,79 @@ def test_draw_path_collection_error_handling():
|
251 | 254 | ax.scatter([1], [1]).set_paths(path.Path([(0, 1), (2, 3)]))
|
252 | 255 | with pytest.raises(TypeError):
|
253 | 256 | fig.canvas.draw()
|
| 257 | + |
| 258 | + |
| 259 | +@pytest.fixture |
| 260 | +def chunk_limit_setup(): |
| 261 | + N = 100_000 |
| 262 | + dpi = 500 |
| 263 | + w = 5*dpi |
| 264 | + h = 6*dpi |
| 265 | + |
| 266 | + # just fit in the width |
| 267 | + x = np.linspace(0, w, N) |
| 268 | + # and go top-to-bottom |
| 269 | + y = np.ones(N) * h |
| 270 | + y[::2] = 0 |
| 271 | + |
| 272 | + idt = IdentityTransform() |
| 273 | + # make a renderer |
| 274 | + ra = RendererAgg(w, h, dpi) |
| 275 | + # setup the minimal gc to draw a line |
| 276 | + gc = ra.new_gc() |
| 277 | + gc.set_linewidth(1) |
| 278 | + gc.set_foreground('r') |
| 279 | + # make a Path |
| 280 | + p = Path(np.vstack((x, y)).T) |
| 281 | + # effectively disable path simplification (but leaving it "on") |
| 282 | + p.simplify_threshold = 0 |
| 283 | + |
| 284 | + return ra, gc, p, idt |
| 285 | + |
| 286 | + |
| 287 | +def test_chunksize_hatch_fail(chunk_limit_setup): |
| 288 | + ra, gc, p, idt = chunk_limit_setup |
| 289 | + |
| 290 | + gc.set_hatch('/') |
| 291 | + |
| 292 | + with pytest.raises(OverflowError, match='hatched path'): |
| 293 | + ra.draw_path(gc, p, idt) |
| 294 | + |
| 295 | + |
| 296 | +def test_chunksize_rgbFace_fail(chunk_limit_setup): |
| 297 | + ra, gc, p, idt = chunk_limit_setup |
| 298 | + |
| 299 | + with pytest.raises(OverflowError, match='filled path'): |
| 300 | + ra.draw_path(gc, p, idt, (1, 0, 0)) |
| 301 | + |
| 302 | + |
| 303 | +def test_chunksize_no_simplify_fail(chunk_limit_setup): |
| 304 | + ra, gc, p, idt = chunk_limit_setup |
| 305 | + p.should_simplify = False |
| 306 | + with pytest.raises(OverflowError, match="should_simplify is False"): |
| 307 | + ra.draw_path(gc, p, idt) |
| 308 | + |
| 309 | + |
| 310 | +def test_chunksize_zero(chunk_limit_setup): |
| 311 | + ra, gc, p, idt = chunk_limit_setup |
| 312 | + # set to zero to disable, currently defaults to 0, but lets be sure |
| 313 | + rcParams['agg.path.chunksize'] = 0 |
| 314 | + with pytest.raises(OverflowError, match='Please set'): |
| 315 | + ra.draw_path(gc, p, idt) |
| 316 | + |
| 317 | + |
| 318 | +def test_chunksize_too_big_to_chunk(chunk_limit_setup): |
| 319 | + ra, gc, p, idt = chunk_limit_setup |
| 320 | + # set big enough that we do not try to chunk |
| 321 | + rcParams['agg.path.chunksize'] = 1_000_000 |
| 322 | + with pytest.raises(OverflowError, match='Please reduce'): |
| 323 | + ra.draw_path(gc, p, idt) |
| 324 | + |
| 325 | + |
| 326 | +def test_chunksize_toobig_chunks(chunk_limit_setup): |
| 327 | + ra, gc, p, idt = chunk_limit_setup |
| 328 | + # small enough we will try to chunk, but big enough we will fail |
| 329 | + # to render |
| 330 | + rcParams['agg.path.chunksize'] = 90_000 |
| 331 | + with pytest.raises(OverflowError, match='Please reduce'): |
| 332 | + ra.draw_path(gc, p, idt) |
0 commit comments