Skip to content

Commit 4ea9211

Browse files
committed
tests: Avoid spurious failures with Pillow 3.4.0 - 3.4.2
1 parent 78397ce commit 4ea9211

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

tests/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from functools import wraps
2121
import os
22+
from PIL import Image
2223
import unittest
2324

2425
try:
@@ -28,6 +29,15 @@
2829
have_optimizations = False
2930

3031

32+
# PIL.Image cannot have zero width or height on Pillow 3.4.0 - 3.4.2
33+
# https://github.com/python-pillow/Pillow/issues/2259
34+
try:
35+
Image.new('RGBA', (1, 0))
36+
image_dimensions_cannot_be_zero = False
37+
except ValueError:
38+
image_dimensions_cannot_be_zero = True
39+
40+
3141
def file_path(name):
3242
return os.path.join(os.path.dirname(__file__), name)
3343

tests/test_imageslide.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from PIL import Image
2323
import unittest
2424

25-
from . import file_path
25+
from . import file_path, image_dimensions_cannot_be_zero, skip_if
2626

2727
# Tests should be written to be compatible with Python 2.6 unittest.
2828

@@ -104,6 +104,7 @@ def test_read_region(self):
104104
self.assertEqual(self.osr.read_region((-10, -10), 0, (400, 400)).size,
105105
(400, 400))
106106

107+
@skip_if(image_dimensions_cannot_be_zero, 'Pillow issue #2259')
107108
def test_read_region_size_dimension_zero(self):
108109
self.assertEqual(self.osr.read_region((0, 0), 0, (400, 0)).size,
109110
(400, 0))

tests/test_openslide.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import sys
2626
import unittest
2727

28-
from . import file_path, have_optimizations, skip_if
28+
from . import (file_path, have_optimizations, image_dimensions_cannot_be_zero,
29+
skip_if)
2930

3031
# Tests should be written to be compatible with Python 2.6 unittest.
3132

@@ -110,6 +111,7 @@ def test_read_region(self):
110111
self.assertEqual(self.osr.read_region((-10, -10), 1, (400, 400)).size,
111112
(400, 400))
112113

114+
@skip_if(image_dimensions_cannot_be_zero, 'Pillow issue #2259')
113115
def test_read_region_size_dimension_zero(self):
114116
self.assertEqual(self.osr.read_region((0, 0), 1, (400, 0)).size,
115117
(400, 0))

0 commit comments

Comments
 (0)