mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-11 17:56:18 +03:00
Use pytest.importorskip to skip on a missing import dependency
This commit is contained in:
parent
8ec548d163
commit
17c67a2cfb
|
@ -1,15 +1,8 @@
|
||||||
import pytest
|
import pytest
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
try:
|
FpxImagePlugin = pytest.importorskip(
|
||||||
from PIL import FpxImagePlugin
|
"PIL.FpxImagePlugin", reason="olefile not installed"
|
||||||
except ImportError:
|
|
||||||
olefile_installed = False
|
|
||||||
else:
|
|
||||||
olefile_installed = True
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.skipif(
|
|
||||||
not olefile_installed, reason="olefile package not installed"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,22 +3,17 @@ from PIL import Image, ImagePalette, features
|
||||||
|
|
||||||
from .helper import assert_image_similar, hopper
|
from .helper import assert_image_similar, hopper
|
||||||
|
|
||||||
try:
|
MicImagePlugin = pytest.importorskip(
|
||||||
from PIL import MicImagePlugin
|
"PIL.MicImagePlugin", reason="olefile not installed"
|
||||||
except ImportError:
|
)
|
||||||
olefile_installed = False
|
|
||||||
else:
|
pytestmark = pytest.mark.skipif(
|
||||||
olefile_installed = True
|
not features.check("libtiff"), reason="libtiff not installed"
|
||||||
|
)
|
||||||
|
|
||||||
TEST_FILE = "Tests/images/hopper.mic"
|
TEST_FILE = "Tests/images/hopper.mic"
|
||||||
|
|
||||||
|
|
||||||
pytestmark = [
|
|
||||||
pytest.mark.skipif(not olefile_installed, reason="olefile package not installed"),
|
|
||||||
pytest.mark.skipif(not features.check("libtiff"), reason="libtiff not installed"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_sanity():
|
def test_sanity():
|
||||||
with Image.open(TEST_FILE) as im:
|
with Image.open(TEST_FILE) as im:
|
||||||
im.load()
|
im.load()
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
import unittest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import PillowTestCase, assert_image_equal, assert_image_similar, hopper
|
from .helper import PillowTestCase, assert_image_equal, assert_image_similar, hopper
|
||||||
|
|
||||||
try:
|
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||||
from PIL import _webp
|
|
||||||
except ImportError:
|
|
||||||
_webp = None
|
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(_webp is None, "WebP support not installed")
|
|
||||||
class TestFileWebpAlpha(PillowTestCase):
|
class TestFileWebpAlpha(PillowTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if _webp.WebPDecoderBuggyAlpha(self):
|
if _webp.WebPDecoderBuggyAlpha(self):
|
||||||
|
|
|
@ -9,20 +9,11 @@ from .helper import (
|
||||||
on_ci,
|
on_ci,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||||
from PIL import _webp
|
|
||||||
|
|
||||||
HAVE_WEBP = True
|
|
||||||
except ImportError:
|
|
||||||
HAVE_WEBP = False
|
|
||||||
|
|
||||||
|
|
||||||
class TestFileWebpAnimation(PillowTestCase):
|
class TestFileWebpAnimation(PillowTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if not HAVE_WEBP:
|
|
||||||
self.skipTest("WebP support not installed")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not _webp.HAVE_WEBPANIM:
|
if not _webp.HAVE_WEBPANIM:
|
||||||
self.skipTest(
|
self.skipTest(
|
||||||
"WebP library does not contain animation support, "
|
"WebP library does not contain animation support, "
|
||||||
|
|
|
@ -1,21 +1,13 @@
|
||||||
|
import pytest
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import PillowTestCase, assert_image_equal, hopper
|
from .helper import PillowTestCase, assert_image_equal, hopper
|
||||||
|
|
||||||
try:
|
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||||
from PIL import _webp
|
|
||||||
|
|
||||||
HAVE_WEBP = True
|
|
||||||
except ImportError:
|
|
||||||
HAVE_WEBP = False
|
|
||||||
|
|
||||||
|
|
||||||
class TestFileWebpLossless(PillowTestCase):
|
class TestFileWebpLossless(PillowTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if not HAVE_WEBP:
|
|
||||||
self.skipTest("WebP support not installed")
|
|
||||||
return
|
|
||||||
|
|
||||||
if _webp.WebPDecoderVersion() < 0x0200:
|
if _webp.WebPDecoderVersion() < 0x0200:
|
||||||
self.skipTest("lossless not included")
|
self.skipTest("lossless not included")
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,15 @@
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
import pytest
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import PillowTestCase
|
from .helper import PillowTestCase
|
||||||
|
|
||||||
try:
|
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||||
from PIL import _webp
|
|
||||||
|
|
||||||
HAVE_WEBP = True
|
|
||||||
except ImportError:
|
|
||||||
HAVE_WEBP = False
|
|
||||||
|
|
||||||
|
|
||||||
class TestFileWebpMetadata(PillowTestCase):
|
class TestFileWebpMetadata(PillowTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if not HAVE_WEBP:
|
|
||||||
self.skipTest("WebP support not installed")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not _webp.HAVE_WEBPMUX:
|
if not _webp.HAVE_WEBPMUX:
|
||||||
self.skipTest("WebPMux support not installed")
|
self.skipTest("WebPMux support not installed")
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,6 @@ from PIL import Image
|
||||||
|
|
||||||
from .helper import is_win32
|
from .helper import is_win32
|
||||||
|
|
||||||
try:
|
|
||||||
import numpy
|
|
||||||
except ImportError:
|
|
||||||
numpy = None
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.skipif(is_win32(), reason="Win32 does not call map_buffer")
|
pytestmark = pytest.mark.skipif(is_win32(), reason="Win32 does not call map_buffer")
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,8 +27,9 @@ def test_overflow():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="Requires 64-bit system")
|
@pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="Requires 64-bit system")
|
||||||
@pytest.mark.skipif(numpy is None, reason="NumPy is not installed")
|
|
||||||
def test_ysize():
|
def test_ysize():
|
||||||
|
numpy = pytest.importorskip("numpy", reason="NumPy not installed")
|
||||||
|
|
||||||
# Should not raise 'Integer overflow in ysize'
|
# Should not raise 'Integer overflow in ysize'
|
||||||
arr = numpy.zeros((46341, 46341), dtype=numpy.uint8)
|
arr = numpy.zeros((46341, 46341), dtype=numpy.uint8)
|
||||||
Image.fromarray(arr)
|
Image.fromarray(arr)
|
||||||
|
|
|
@ -3,18 +3,11 @@ from PIL import Image
|
||||||
|
|
||||||
from .helper import assert_deep_equal, assert_image, hopper
|
from .helper import assert_deep_equal, assert_image, hopper
|
||||||
|
|
||||||
try:
|
numpy = pytest.importorskip("numpy", reason="NumPy not installed")
|
||||||
import numpy
|
|
||||||
except ImportError:
|
|
||||||
numpy = None
|
|
||||||
|
|
||||||
|
|
||||||
TEST_IMAGE_SIZE = (10, 10)
|
TEST_IMAGE_SIZE = (10, 10)
|
||||||
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.skipif(numpy is None, reason="NumPy is not installed")
|
|
||||||
|
|
||||||
|
|
||||||
def test_numpy_to_image():
|
def test_numpy_to_image():
|
||||||
def to_image(dtype, bands=1, boolean=0):
|
def to_image(dtype, bands=1, boolean=0):
|
||||||
if bands == 1:
|
if bands == 1:
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
import pytest
|
import pytest
|
||||||
from PIL import __version__
|
from PIL import __version__
|
||||||
|
|
||||||
try:
|
pyroma = pytest.importorskip("pyroma", reason="Pyroma not installed")
|
||||||
import pyroma
|
|
||||||
except ImportError:
|
|
||||||
pyroma = None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(pyroma is None, reason="Pyroma is not installed")
|
|
||||||
def test_pyroma():
|
def test_pyroma():
|
||||||
# Arrange
|
# Arrange
|
||||||
data = pyroma.projectdata.get_data(".")
|
data = pyroma.projectdata.get_data(".")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user