8000 Merge pull request #23420 from timhoffm/test-cunksize · matplotlib/matplotlib@37ccdca · GitHub
[go: up one dir, main page]

Skip to content

Commit 37ccdca

Browse files
authored
Merge pull request #23420 from timhoffm/test-cunksize
Clean up test_chunksize_fails()
2 parents 9d9ba8a + a10b4c5 commit 37ccdca

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

lib/matplotlib/tests/test_agg.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
from matplotlib import (
10-
collections, path, patheffects, pyplot as plt, transforms as mtransforms,
10+
collections, patheffects, pyplot as plt, transforms as mtransforms,
1111
rcParams, rc_context)
1212
from matplotlib.backends.backend_agg import RendererAgg
1313
from matplotlib.figure import Figure
@@ -56,7 +56,7 @@ def test_large_single_path_collection():
5656
# applied.
5757
f, ax = plt.subplots()
5858
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]])])
6060
ax.add_artist(collection)
6161
ax.set_xlim(10**-3, 1)
6262
plt.savefig(buff)
@@ -270,61 +270,62 @@ def test_webp_alpha():
270270

271271
def test_draw_path_collection_error_handling():
272272
10000 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)]))
274274
with pytest.raises(TypeError):
275275
fig.canvas.draw()
276276

277277

278278
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+
279284
N = 100_000
280285
dpi = 500
281286
w = 5*dpi
282287
h = 6*dpi
283288

284-
# just fit in the width
289+
# make a Path that spans the whole w-h rectangle
285290
x = np.linspace(0, w, N)
286-
# and go top-to-bottom
287291
y = np.ones(N) * h
288292
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
289296

290-
idt = IdentityTransform()
291-
# make a renderer
297+
# setup the minimal GraphicsContext to draw a Path
292298
ra = RendererAgg(w, h, dpi)
293-
# setup the minimal gc to draw a line
294299
gc = ra.new_gc()
295300
gc.set_linewidth(1)
296301
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
301302

302303
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())
305306
gc.set_hatch(None)
306307

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))
309310

310311
# Set to zero to disable, currently defaults to 0, but let's be sure.
311312
with rc_context({'agg.path.chunksize': 0}):
312313
with pytest.raises(OverflowError, match='Please set'):
313-
ra.draw_path(gc, p, idt)
314+
ra.draw_path(gc, path, IdentityTransform())
314315

315316
# Set big enough that we do not try to chunk.
316317
with rc_context({'agg.path.chunksize': 1_000_000}):
317318
with pytest.raises(OverflowError, match='Please reduce'):
318-
ra.draw_path(gc, p, idt)
319+
ra.draw_path(gc, path, IdentityTransform())
319320

320321
# Small enough we will try to chunk, but big enough we will fail to render.
321322
with rc_context({'agg.path.chunksize': 90_000}):
322323
with pytest.raises(OverflowError, match='Please reduce'):
323-
ra.draw_path(gc, p, idt)
324+
ra.draw_path(gc, path, IdentityTransform())
324325

325-
p.should_simplify = False
326+
path.should_simplify = False
326327
with pytest.raises(OverflowError, match="should_simplify is False"):
327-
ra.draw_path(gc, p, idt)
328+
ra.draw_path(gc, path, IdentityTransform())
328329

329330

330331
def test_non_tuple_rgbaface():

0 commit comments

Comments
 (0)
0