mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +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
|
||||
from PIL import Image
|
||||
|
||||
try:
|
||||
from PIL import FpxImagePlugin
|
||||
except ImportError:
|
||||
olefile_installed = False
|
||||
else:
|
||||
olefile_installed = True
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not olefile_installed, reason="olefile package not installed"
|
||||
FpxImagePlugin = pytest.importorskip(
|
||||
"PIL.FpxImagePlugin", reason="olefile not installed"
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -3,22 +3,17 @@ from PIL import Image, ImagePalette, features
|
|||
|
||||
from .helper import assert_image_similar, hopper
|
||||
|
||||
try:
|
||||
from PIL import MicImagePlugin
|
||||
except ImportError:
|
||||
olefile_installed = False
|
||||
else:
|
||||
olefile_installed = True
|
||||
MicImagePlugin = pytest.importorskip(
|
||||
"PIL.MicImagePlugin", reason="olefile not installed"
|
||||
)
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not features.check("libtiff"), reason="libtiff not installed"
|
||||
)
|
||||
|
||||
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():
|
||||
with Image.open(TEST_FILE) as im:
|
||||
im.load()
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
import unittest
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from .helper import PillowTestCase, assert_image_equal, assert_image_similar, hopper
|
||||
|
||||
try:
|
||||
from PIL import _webp
|
||||
except ImportError:
|
||||
_webp = None
|
||||
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||
|
||||
|
||||
@unittest.skipIf(_webp is None, "WebP support not installed")
|
||||
class TestFileWebpAlpha(PillowTestCase):
|
||||
def setUp(self):
|
||||
if _webp.WebPDecoderBuggyAlpha(self):
|
||||
|
|
|
@ -9,20 +9,11 @@ from .helper import (
|
|||
on_ci,
|
||||
)
|
||||
|
||||
try:
|
||||
from PIL import _webp
|
||||
|
||||
HAVE_WEBP = True
|
||||
except ImportError:
|
||||
HAVE_WEBP = False
|
||||
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||
|
||||
|
||||
class TestFileWebpAnimation(PillowTestCase):
|
||||
def setUp(self):
|
||||
if not HAVE_WEBP:
|
||||
self.skipTest("WebP support not installed")
|
||||
return
|
||||
|
||||
if not _webp.HAVE_WEBPANIM:
|
||||
self.skipTest(
|
||||
"WebP library does not contain animation support, "
|
||||
|
|
|
@ -1,21 +1,13 @@
|
|||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from .helper import PillowTestCase, assert_image_equal, hopper
|
||||
|
||||
try:
|
||||
from PIL import _webp
|
||||
|
||||
HAVE_WEBP = True
|
||||
except ImportError:
|
||||
HAVE_WEBP = False
|
||||
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||
|
||||
|
||||
class TestFileWebpLossless(PillowTestCase):
|
||||
def setUp(self):
|
||||
if not HAVE_WEBP:
|
||||
self.skipTest("WebP support not installed")
|
||||
return
|
||||
|
||||
if _webp.WebPDecoderVersion() < 0x0200:
|
||||
self.skipTest("lossless not included")
|
||||
|
||||
|
|
|
@ -1,23 +1,15 @@
|
|||
from io import BytesIO
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from .helper import PillowTestCase
|
||||
|
||||
try:
|
||||
from PIL import _webp
|
||||
|
||||
HAVE_WEBP = True
|
||||
except ImportError:
|
||||
HAVE_WEBP = False
|
||||
_webp = pytest.importorskip("PIL._webp", reason="WebP support not installed")
|
||||
|
||||
|
||||
class TestFileWebpMetadata(PillowTestCase):
|
||||
def setUp(self):
|
||||
if not HAVE_WEBP:
|
||||
self.skipTest("WebP support not installed")
|
||||
return
|
||||
|
||||
if not _webp.HAVE_WEBPMUX:
|
||||
self.skipTest("WebPMux support not installed")
|
||||
|
||||
|
|
|
@ -5,11 +5,6 @@ from PIL import Image
|
|||
|
||||
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")
|
||||
|
||||
|
||||
|
@ -32,8 +27,9 @@ def test_overflow():
|
|||
|
||||
|
||||
@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():
|
||||
numpy = pytest.importorskip("numpy", reason="NumPy not installed")
|
||||
|
||||
# Should not raise 'Integer overflow in ysize'
|
||||
arr = numpy.zeros((46341, 46341), dtype=numpy.uint8)
|
||||
Image.fromarray(arr)
|
||||
|
|
|
@ -3,18 +3,11 @@ from PIL import Image
|
|||
|
||||
from .helper import assert_deep_equal, assert_image, hopper
|
||||
|
||||
try:
|
||||
import numpy
|
||||
except ImportError:
|
||||
numpy = None
|
||||
|
||||
numpy = pytest.importorskip("numpy", reason="NumPy not installed")
|
||||
|
||||
TEST_IMAGE_SIZE = (10, 10)
|
||||
|
||||
|
||||
pytestmark = pytest.mark.skipif(numpy is None, reason="NumPy is not installed")
|
||||
|
||||
|
||||
def test_numpy_to_image():
|
||||
def to_image(dtype, bands=1, boolean=0):
|
||||
if bands == 1:
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
import pytest
|
||||
from PIL import __version__
|
||||
|
||||
try:
|
||||
import pyroma
|
||||
except ImportError:
|
||||
pyroma = None
|
||||
pyroma = pytest.importorskip("pyroma", reason="Pyroma not installed")
|
||||
|
||||
|
||||
@pytest.mark.skipif(pyroma is None, reason="Pyroma is not installed")
|
||||
def test_pyroma():
|
||||
# Arrange
|
||||
data = pyroma.projectdata.get_data(".")
|
||||
|
|
Loading…
Reference in New Issue
Block a user