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

Skip to content

Commit 119effd

Browse files
authored
Merge pull request #9486 from anntzer/test-file-leak
Don't leak test.jpeg into cwd while testing.
2 parents e14f98e + 798a428 commit 119effd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/matplotlib/tests/test_agg.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,10 @@ def test_chunksize():
238238

239239
@pytest.mark.backend('Agg')
240240
def test_jpeg_dpi():
241-
try:
242-
from PIL import Image
243-
except Exception:
244-
pytest.skip("Could not import PIL")
245-
# Check that dpi is set correctly in jpg files
241+
Image = pytest.importorskip("PIL.Image")
242+
# Check that dpi is set correctly in jpg files.
246243
plt.plot([0, 1, 2], [0, 1, 0])
247-
plt.savefig('test.jpg', dpi=200)
248-
im = Image.open("test.jpg")
244+
buf = io.BytesIO()
245+
plt.savefig(buf, format="jpg", dpi=200)
246+
im = Image.open(buf)
249247
assert im.info['dpi'] == (200, 200)

0 commit comments

Comments
 (0)