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

Skip to content

Commit 775c700

Browse files
committed
Remove importorskip("PIL")
1 parent 8636308 commit 775c700

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

lib/matplotlib/tests/test_agg.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import numpy as np
44
from numpy.testing import assert_array_almost_equal
5+
from PIL import Image, TiffTags
56
import pytest
67

8+
79
from matplotlib import (
810
collections, path, pyplot as plt, transforms as mtransforms, rcParams)
911
from matplotlib.image import imread
@@ -217,7 +219,6 @@ def test_chunksize():
217219

218220
@pytest.mark.backend('Agg')
219221
def test_jpeg_dpi():
220-
Image = pytest.importorskip("PIL.Image")
221222
# Check that dpi is set correctly in jpg files.
222223
plt.plot([0, 1, 2], [0, 1, 0])
223224
buf = io.BytesIO()
@@ -227,7 +228,6 @@ def test_jpeg_dpi():
227228

228229

229230
def test_pil_kwargs_png():
230-
Image = pytest.importorskip("PIL.Image")
231231
from PIL.PngImagePlugin import PngInfo
232232
buf = io.BytesIO()
233233
pnginfo = PngInfo()
@@ -238,11 +238,9 @@ def test_pil_kwargs_png():
238238

239239

240240
def test_pil_kwargs_tiff():
241-
Image = pytest.importorskip("PIL.Image")
242-
from PIL.TiffTags import TAGS_V2 as TAGS
243241
buf = io.BytesIO()
244242
pil_kwargs = {"description": "test image"}
245243
plt.figure().savefig(buf, format="tiff", pil_kwargs=pil_kwargs)
246244
im = Image.open(buf)
247-
tags = {TAGS[k].name: v for k, v in im.tag_v2.items()}
245+
tags = {TiffTags.TAGS_V2[k].name: v for k, v in im.tag_v2.items()}
248246
assert tags["ImageDescription"] == "test image"

lib/matplotlib/tests/test_animation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ def isAvailable(cls):
132132
# matplotlib.testing.image_comparison
133133
@pytest.mark.parametrize('writer, output', WRITER_OUTPUT)
134134
def test_save_animation_smoketest(tmpdir, writer, output):
135-
if writer == 'pillow':
136-
pytest.importorskip("PIL")
137135
try:
138136
# for ImageMagick the rcparams must be patched to account for
139137
# 'convert' being a built in MS tool, not the imagemagick

lib/matplotlib/tests/test_image.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import numpy as np
1212
from numpy import ma
1313
from numpy.testing import assert_array_equal
14+
from PIL import Image
1415

1516
from matplotlib import (
1617
colors, image as mimage, patches, pyplot as plt, style, rcParams)
@@ -219,27 +220,24 @@ def test_imshow_zoom(fig_test, fig_ref):
219220
@check_figures_equal()
220221
def test_imshow_pil(fig_test, fig_ref):
221222
style.use("default")
222-
PIL = pytest.importorskip("PIL")
223223
png_path = Path(__file__).parent / "baseline_images/pngsuite/basn3p04.png"
224224
tiff_path = Path(__file__).parent / "baseline_images/test_image/uint16.tif"
225225
axs = fig_test.subplots(2)
226-
axs[0].imshow(PIL.Image.open(png_path))
227-
axs[1].imshow(PIL.Image.open(tiff_path))
226+
axs[0].imshow(Image.open(png_path))
227+
axs[1].imshow(Image.open(tiff_path))
228228
axs = fig_ref.subplots(2)
229229
axs[0].imshow(plt.imread(png_path))
230230
axs[1].imshow(plt.imread(tiff_path))
231231

232232

233233
def test_imread_pil_uint16():
234-
pytest.importorskip("PIL")
235234
img = plt.imread(os.path.join(os.path.dirname(__file__),
236235
'baseline_images', 'test_image', 'uint16.tif'))
237236
assert img.dtype == np.uint16
238237
assert np.sum(img) == 134184960
239238

240239

241240
def test_imread_fspath():
242-
pytest.importorskip("PIL")
243241
img = plt.imread(
244242
Path(__file__).parent / 'baseline_images/test_image/uint16.tif')
245243
assert img.dtype == np.uint16
@@ -248,8 +246,6 @@ def test_imread_fspath():
248246

249247
@pytest.mark.parametrize("fmt", ["png", "jpg", "jpeg", "tiff"])
250248
def test_imsave(fmt):
251-
if fmt in ["jpg", "jpeg", "tiff"]:
252-
pytest.importorskip("PIL")
253249
has_alpha = fmt not in ["jpg", "jpeg"]
254250

255251
# The goal here is that the user can specify an output logical DPI
@@ -314,7 +310,6 @@ def test_imsave_color_alpha():
314310

315311

316312
def test_imsave_pil_kwargs_png():
317-
Image = pytest.importorskip("PIL.Image")
318313
from PIL.PngImagePlugin import PngInfo
319314
buf = io.BytesIO()
320315
pnginfo = PngInfo()
@@ -326,7 +321,6 @@ def test_imsave_pil_kwargs_png():
326321

327322

328323
def test_imsave_pil_kwargs_tiff():
329-
Image = pytest.importorskip("PIL.Image")
330324
from PIL.TiffTags import TAGS_V2 as TAGS
331325
buf = io.BytesIO()
332326
pil_kwargs = {"description": "test image"}
@@ -664,7 +658,6 @@ def test_nonuniformimage_setnorm():
664658

665659

666660
def test_jpeg_2d():
667-
Image = pytest.importorskip('PIL.Image')
668661
# smoke test that mode-L pillow images work.
669662
imd = np.ones((10, 10), dtype='uint8')
670663
for i in range(10):
@@ -676,8 +669,6 @@ def test_jpeg_2d():
676669

677670

678671
def test_jpeg_alpha():
679-
Image = pytest.importorskip('PIL.Image')
680-
681672
plt.figure(figsize=(1, 1), dpi=300)
682673
# Create an image that is all black, with a gradient from 0-1 in
683674
# the alpha channel from left to right.

0 commit comments

Comments
 (0)