@@ -64,14 +64,16 @@ def test_wrong_bits_per_sample(self):
64
64
65
65
self .assertEqual (im .mode , "RGBA" )
66
66
self .assertEqual (im .size , (52 , 53 ))
67
- self .assertEqual (im .tile , [("raw" , (0 , 0 , 52 , 53 ), 160 , ("RGBA" , 0 , 1 ))])
67
+ self .assertEqual (
68
+ im .tile , [("raw" , (0 , 0 , 52 , 53 ), 160 , ("RGBA" , 0 , 1 ))])
68
69
im .load ()
69
70
70
71
def test_set_legacy_api (self ):
71
72
ifd = TiffImagePlugin .ImageFileDirectory_v2 ()
72
73
with self .assertRaises (Exception ) as e :
73
74
ifd .legacy_api = None
74
- self .assertEqual (str (e .exception ), "Not allowing setting of legacy api" )
75
+ self .assertEqual (str (e .exception ),
76
+ "Not allowing setting of legacy api" )
75
77
76
78
def test_size (self ):
77
79
filename = "Tests/images/pil168.tif"
@@ -91,8 +93,10 @@ def test_xyres_tiff(self):
91
93
self .assertIsInstance (im .tag [Y_RESOLUTION ][0 ], tuple )
92
94
93
95
# v2 api
94
- self .assertIsInstance (im .tag_v2 [X_RESOLUTION ], TiffImagePlugin .IFDRational )
95
- self .assertIsInstance (im .tag_v2 [Y_RESOLUTION ], TiffImagePlugin .IFDRational )
96
+ self .assertIsInstance (
97
+ im .tag_v2 [X_RESOLUTION ], TiffImagePlugin .IFDRational )
98
+ self .assertIsInstance (
99
+ im .tag_v2 [Y_RESOLUTION ], TiffImagePlugin .IFDRational )
96
100
97
101
self .assertEqual (im .info ["dpi" ], (72.0 , 72.0 ))
98
102
@@ -101,8 +105,10 @@ def test_xyres_fallback_tiff(self):
101
105
im = Image .open (filename )
102
106
103
107
# v2 api
104
- self .assertIsInstance (im .tag_v2 [X_RESOLUTION ], TiffImagePlugin .IFDRational )
105
- self .assertIsInstance (im .tag_v2 [Y_RESOLUTION ], TiffImagePlugin .IFDRational )
108
+ self .assertIsInstance (
109
+ im .tag_v2 [X_RESOLUTION ], TiffImagePlugin .IFDRational )
110
+ self .assertIsInstance (
111
+ im .tag_v2 [Y_RESOLUTION ], TiffImagePlugin .IFDRational )
106
112
self .assertRaises (KeyError , lambda : im .tag_v2 [RESOLUTION_UNIT ])
107
113
108
114
# Legacy.
@@ -157,10 +163,12 @@ def test_save_setting_missing_resolution(self):
157
163
def test_invalid_file (self ):
158
164
invalid_file = "Tests/images/flower.jpg"
159
165
160
- self .assertRaises (SyntaxError , TiffImagePlugin .TiffImageFile , invalid_file )
166
+ self .assertRaises (
167
+ SyntaxError , TiffImagePlugin .TiffImageFile , invalid_file )
161
168
162
169
TiffImagePlugin .PREFIXES .append (b"\xff \xd8 \xff \xe0 " )
163
- self .assertRaises (SyntaxError , TiffImagePlugin .TiffImageFile , invalid_file )
170
+ self .assertRaises (
171
+ SyntaxError , TiffImagePlugin .TiffImageFile , invalid_file )
164
172
TiffImagePlugin .PREFIXES .pop ()
165
173
166
174
def test_bad_exif (self ):
@@ -235,7 +243,8 @@ def test_32bit_float(self):
235
243
im .load ()
236
244
237
245
self .assertEqual (im .getpixel ((0 , 0 )), - 0.4526388943195343 )
238
- self .assertEqual (im .getextrema (), (- 3.140936851501465 , 3.140684127807617 ))
246
+ self .assertEqual (
247
+ im .getextrema (), (- 3.140936851501465 , 3.140684127807617 ))
239
248
240
249
def test_unknown_pixel_mode (self ):
241
250
self .assertRaises (
@@ -445,7 +454,8 @@ def test_gray_semibyte_per_pixel(self):
445
454
self .assert_image_equal (im , im2 )
446
455
447
456
def test_with_underscores (self ):
448
- kwargs = {"resolution_unit" : "inch" , "x_resolution" : 72 , "y_resolution" : 36 }
457
+ kwargs = {"resolution_unit" : "inch" ,
458
+ "x_resolution" : 72 , "y_resolution" : 36 }
449
459
filename = self .tempfile ("temp.tif" )
450
460
hopper ("RGB" ).save (filename , ** kwargs )
451
461
im = Image .open (filename )
@@ -476,22 +486,25 @@ def test_strip_raw(self):
476
486
infile = "Tests/images/tiff_strip_raw.tif"
477
487
im = Image .open (infile )
478
488
479
- self .assert_image_equal_tofile (im , "Tests/images/tiff_adobe_deflate.png" )
489
+ self .assert_image_equal_tofile (
490
+ im , "Tests/images/tiff_adobe_deflate.png" )
480
491
481
492
def test_strip_planar_raw (self ):
482
493
# gdal_translate -of GTiff -co INTERLEAVE=BAND \
483
494
# tiff_strip_raw.tif tiff_strip_planar_raw.tiff
484
495
infile = "Tests/images/tiff_strip_planar_raw.tif"
485
496
im = Image .open (infile )
486
497
487
- self .assert_image_equal_tofile (im , "Tests/images/tiff_adobe_deflate.png" )
498
+ self .assert_image_equal_tofile (
499
+ im , "Tests/images/tiff_adobe_deflate.png" )
488
500
489
501
def test_strip_planar_raw_with_overviews (self ):
490
502
# gdaladdo tiff_strip_planar_raw2.tif 2 4 8 16
491
503
infile = "Tests/images/tiff_strip_planar_raw_with_overviews.tif"
492
504
im = Image .open (infile )
493
505
494
- self .assert_image_equal_tofile (im , "Tests/images/tiff_adobe_deflate.png" )
506
+ self .assert_image_equal_tofile (
507
+ im , "Tests/images/tiff_adobe_deflate.png" )
495
508
496
509
def test_tiled_planar_raw (self ):
497
510
# gdal_translate -of GTiff -co TILED=YES -co BLOCKXSIZE=32 \
@@ -500,7 +513,8 @@ def test_tiled_planar_raw(self):
500
513
infile = "Tests/images/tiff_tiled_planar_raw.tif"
501
514
im = Image .open (infile )
502
515
503
- self .assert_image_equal_tofile (im , "Tests/images/tiff_adobe_deflate.png" )
516
+ self .assert_image_equal_tofile (
517
+ im , "Tests/images/tiff_adobe_deflate.png" )
504
518
505
519
def test_palette (self ):
506
520
for mode in ["P" , "PA" ]:
@@ -527,7 +541,8 @@ def test_tiff_save_all(self):
527
541
# Test appending images
528
542
mp = io .BytesIO ()
529
543
im = Image .new ("RGB" , (100 , 100 ), "#f00" )
530
- ims = [Image .new ("RGB" , (100 , 100 ), color ) for color in ["#0f0" , "#00f" ]]
544
+ ims = [Image .new ("RGB" , (100 , 100 ), color )
545
+ for color in ["#0f0" , "#00f" ]]
531
546
im .copy ().save (mp , format = "TIFF" , save_all = True , append_images = ims )
532
547
533
548
mp .seek (0 , os .SEEK_SET )
@@ -540,7 +555,8 @@ def imGenerator(ims):
540
555
yield im
541
556
542
557
mp = io .BytesIO ()
543
- im .save (mp , format = "TIFF" , save_all = True , append_images = imGenerator (ims ))
558
+ im .save (mp , format = "TIFF" , save_all = True ,
559
+ append_images = imGenerator (ims ))
544
560
545
561
mp .seek (0 , os .SEEK_SET )
546
562
reread = Image .open (mp )
@@ -589,8 +605,9 @@ def test_close_on_load_nonexclusive(self):
589
605
590
606
def test_string_dimension (self ):
591
607
# Assert that an error is raised if one of the dimensions is a string
592
- with self .assertRaises (ValueError ):
593
- Image .open ("Tests/images/string_dimension.tiff" )
608
+ with self .assertRaises (OSError ):
609
+ with Image .open ("Tests/images/string_dimension.tiff" ) as im :
610
+ im .load ()
594
611
595
612
596
613
@unittest .skipUnless (sys .platform .startswith ("win32" ), "Windows only" )
0 commit comments