1717# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818#
1919
20- from contextlib import contextmanager
2120import unittest
2221
2322from PIL import Image
2423
2524from openslide import ImageSlide , OpenSlideCache , OpenSlideError
2625
27- from . import file_path , image_dimensions_cannot_be_zero , maybe_supported
28-
29-
30- @contextmanager
31- def image_open (* args , ** kwargs ):
32- img = Image .open (* args , ** kwargs )
33- try :
34- yield img
35- finally :
36- if hasattr (img , 'close' ):
37- # Pillow >= 2.5.0
38- img .close ()
26+ from . import file_path , maybe_supported
3927
4028
4129class TestImageWithoutOpening (unittest .TestCase ):
@@ -50,13 +38,13 @@ def test_open(self):
5038
5139 def test_open_image (self ):
5240 # passing PIL.Image to ImageSlide
53- with image_open (file_path ('boxes.png' )) as img :
41+ with Image . open (file_path ('boxes.png' )) as img :
5442 with ImageSlide (img ) as osr :
5543 self .assertEqual (osr .dimensions , (300 , 250 ))
5644 self .assertEqual (repr (osr ), 'ImageSlide(%r)' % img )
5745
5846 def test_operations_on_closed_handle (self ):
59- with image_open (file_path ('boxes.png' )) as img :
47+ with Image . open (file_path ('boxes.png' )) as img :
6048 osr = ImageSlide (img )
6149 osr .close ()
6250 self .assertRaises (
@@ -102,7 +90,6 @@ def test_read_region(self):
10290 self .osr .read_region ((- 10 , - 10 ), 0 , (400 , 400 )).size , (400 , 400 )
10391 )
10492
105- @unittest .skipIf (image_dimensions_cannot_be_zero , 'Pillow issue #2259' )
10693 def test_read_region_size_dimension_zero (self ):
10794 self .assertEqual (self .osr .read_region ((0 , 0 ), 0 , (400 , 0 )).size , (400 , 0 ))
10895
0 commit comments