7
7
8
8
9
9
from matplotlib import (
10
- collections , path , patheffects , pyplot as plt , transforms as mtransforms ,
10
+ collections , patheffects , pyplot as plt , transforms as mtransforms ,
11
11
rcParams , rc_context )
12
12
from matplotlib .backends .backend_agg import RendererAgg
13
13
from matplotlib .figure import Figure
@@ -56,7 +56,7 @@ def test_large_single_path_collection():
56
56
# applied.
57
57
f , ax = plt .subplots ()
58
58
collection = collections .PathCollection (
59
- [path . Path ([[- 10 , 5 ], [10 , 5 ], [10 , - 5 ], [- 10 , - 5 ], [- 10 , 5 ]])])
59
+ [Path ([[- 10 , 5 ], [10 , 5 ], [10 , - 5 ], [- 10 , - 5 ], [- 10 , 5 ]])])
60
60
ax .add_artist (collection )
61
61
ax .set_xlim (10 ** - 3 , 1 )
62
62
plt .savefig (buff )
@@ -270,61 +270,62 @@ def test_webp_alpha():
270
270
271
271
def test_draw_path_collection_error_handling ():
272
272
fig , ax = plt .subplots ()
273
- ax .scatter ([1 ], [1 ]).set_paths (path . Path ([(0 , 1 ), (2 , 3 )]))
273
+ ax .scatter ([1 ], [1 ]).set_paths (Path ([(0 , 1 ), (2 , 3 )]))
274
274
with pytest .raises (TypeError ):
275
275
fig .canvas .draw ()
276
276
277
277
278
278
def test_chunksize_fails ():
279
+ # NOTE: This test covers multiple independent test scenarios in a single
280
+ # function, because each scenario uses ~2GB of memory and we don't
281
+ # want parallel test executors to accidentally run multiple of these
282
+ # at the same time.
283
+
279
284
N = 100_000
280
285
dpi = 500
281
286
w = 5 * dpi
282
287
h = 6 * dpi
283
288
284
- # just fit in the width
289
+ # make a Path that spans the whole w-h rectangle
285
290
x = np .linspace (0 , w , N )
286
- # and go top-to-bottom
287
291
y = np .ones (N ) * h
288
292
y [::2 ] = 0
293
+ path = Path (np .vstack ((x , y )).T )
294
+ # effectively disable path simplification (but leaving it "on")
295
+ path .simplify_threshold = 0
289
296
290
- idt = IdentityTransform ()
291
- # make a renderer
297
+ # setup the minimal GraphicsContext to draw a Path
292
298
ra = RendererAgg (w , h , dpi )
293
- # setup the minimal gc to draw a line
294
299
gc = ra .new_gc ()
295
300
gc .set_linewidth (1 )
296
301
gc .set_foreground ('r' )
297
- # make a Path
298
- p = Path (np .vstack ((x , y )).T )
299
- # effectively disable path simplification (but leaving it "on")
300
- p .simplify_threshold = 0
301
302
302
303
gc .set_hatch ('/' )
303
- with pytest .raises (OverflowError , match = 'hatched path' ):
304
- ra .draw_path (gc , p , idt )
304
+ with pytest .raises (OverflowError , match = 'can not split hatched path' ):
305
+ ra .draw_path (gc , path , IdentityTransform () )
305
306
gc .set_hatch (None )
306
307
307
- with pytest .raises (OverflowError , match = 'filled path' ):
308
- ra .draw_path (gc , p , idt , (1 , 0 , 0 ))
308
+ with pytest .raises (OverflowError , match = 'can not split filled path' ):
309
+ ra .draw_path (gc , path , IdentityTransform () , (1 , 0 , 0 ))
309
310
310
311
# Set to zero to disable, currently defaults to 0, but let's be sure.
311
312
with rc_context ({'agg.path.chunksize' : 0 }):
312
313
with pytest .raises (OverflowError , match = 'Please set' ):
313
- ra .draw_path (gc , p , idt )
314
+ ra .draw_path (gc , path , IdentityTransform () )
314
315
315
316
# Set big enough that we do not try to chunk.
316
317
with rc_context ({'agg.path.chunksize' : 1_000_000 }):
317
318
with pytest .raises (OverflowError , match = 'Please reduce' ):
318
- ra .draw_path (gc , p , idt )
319
+ ra .draw_path (gc , path , IdentityTransform () )
319
320
320
321
# Small enough we will try to chunk, but big enough we will fail to render.
321
322
with rc_context ({'agg.path.chunksize' : 90_000 }):
322
323
with pytest .raises (OverflowError , match = 'Please reduce' ):
323
- ra .draw_path (gc , p , idt )
324
+ ra .draw_path (gc , path , IdentityTransform () )
324
325
325
- p .should_simplify = False
326
+ path .should_simplify = False
326
327
with pytest .raises (OverflowError , match = "should_simplify is False" ):
327
- ra .draw_path (gc , p , idt )
328
+ ra .draw_path (gc , path , IdentityTransform () )
328
329
329
330
330
331
def test_non_tuple_rgbaface ():
0 commit comments