Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3944155

Browse files
committed
Use io.BytesIO rather than a real on-disk file for test
1 parent b43d5f5 commit 3944155

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

lib/matplotlib/tests/test_agg.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import print_function
22

3+
import io
34
import os
45
import tempfile
56

@@ -25,25 +26,25 @@ def test_repeated_save_with_alpha():
2526

2627
# The target color is fig.patch.get_facecolor()
2728

28-
_, img_fname = tempfile.mkstemp(suffix='.png')
29-
try:
30-
fig.savefig(img_fname,
31-
facecolor=fig.get_facecolor(),
32-
edgecolor='none')
33-
34-
# Save the figure again to check that the
35-
# colors don't bleed from the previous renderer.
36-
fig.savefig(img_fname,
37-
facecolor=fig.get_facecolor(),
38-
edgecolor='none')
39-
40-
# Check the first pixel has the desired color & alpha
41-
# (approx: 0, 1.0, 0.4, 0.25)
42-
assert_array_almost_equal(tuple(imread(img_fname)[0, 0]),
43-
(0.0, 1.0, 0.4, 0.250),
44-
decimal=3)
45-
finally:
46-
os.remove(img_fname)
29+
buf = io.BytesIO()
30+
31+
fig.savefig(buf,
32+
facecolor=fig.get_facecolor(),
33+
edgecolor='none')
34+
35+
# Save the figure again to check that the
36+
# colors don't bleed from the previous renderer.
37+
buf.seek(0)
38+
fig.savefig(buf,
39+
facecolor=fig.get_facecolor(),
40+
edgecolor='none')
41+
42+
# Check the first pixel has the desired color & alpha
43+
# (approx: 0, 1.0, 0.4, 0.25)
44+
buf.seek(0)
45+
assert_array_almost_equal(tuple(imread(buf)[0, 0]),
46+
(0.0, 1.0, 0.4, 0.250),
47+
decimal=3)
4748

4849

4950
def report_memory(i):

0 commit comments

Comments
 (0)