Skip to content

Commit

Permalink
Remove warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick Price committed Apr 22, 2023
1 parent 5eaa850 commit 734edca
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions Tests/test_file_tiff.py
Expand Up @@ -65,14 +65,16 @@ def test_wrong_bits_per_sample(self):

self.assertEqual(im.mode, "RGBA")
self.assertEqual(im.size, (52, 53))
self.assertEqual(im.tile, [("raw", (0, 0, 52, 53), 160, ("RGBA", 0, 1))])
self.assertEqual(
im.tile, [("raw", (0, 0, 52, 53), 160, ("RGBA", 0, 1))])
im.load()

def test_set_legacy_api(self):
ifd = TiffImagePlugin.ImageFileDirectory_v2()
with self.assertRaises(Exception) as e:
ifd.legacy_api = None
self.assertEqual(str(e.exception), "Not allowing setting of legacy api")
self.assertEqual(str(e.exception),
"Not allowing setting of legacy api")

def test_size(self):
filename = "Tests/images/pil168.tif"
Expand All @@ -92,8 +94,10 @@ def test_xyres_tiff(self):
self.assertIsInstance(im.tag[Y_RESOLUTION][0], tuple)

# v2 api
self.assertIsInstance(im.tag_v2[X_RESOLUTION], TiffImagePlugin.IFDRational)
self.assertIsInstance(im.tag_v2[Y_RESOLUTION], TiffImagePlugin.IFDRational)
self.assertIsInstance(
im.tag_v2[X_RESOLUTION], TiffImagePlugin.IFDRational)
self.assertIsInstance(
im.tag_v2[Y_RESOLUTION], TiffImagePlugin.IFDRational)

self.assertEqual(im.info["dpi"], (72.0, 72.0))

Expand All @@ -102,8 +106,10 @@ def test_xyres_fallback_tiff(self):
im = Image.open(filename)

# v2 api
self.assertIsInstance(im.tag_v2[X_RESOLUTION], TiffImagePlugin.IFDRational)
self.assertIsInstance(im.tag_v2[Y_RESOLUTION], TiffImagePlugin.IFDRational)
self.assertIsInstance(
im.tag_v2[X_RESOLUTION], TiffImagePlugin.IFDRational)
self.assertIsInstance(
im.tag_v2[Y_RESOLUTION], TiffImagePlugin.IFDRational)
self.assertRaises(KeyError, lambda: im.tag_v2[RESOLUTION_UNIT])

# Legacy.
Expand Down Expand Up @@ -158,10 +164,12 @@ def test_save_setting_missing_resolution(self):
def test_invalid_file(self):
invalid_file = "Tests/images/flower.jpg"

self.assertRaises(SyntaxError, TiffImagePlugin.TiffImageFile, invalid_file)
self.assertRaises(
SyntaxError, TiffImagePlugin.TiffImageFile, invalid_file)

TiffImagePlugin.PREFIXES.append(b"\xff\xd8\xff\xe0")
self.assertRaises(SyntaxError, TiffImagePlugin.TiffImageFile, invalid_file)
self.assertRaises(
SyntaxError, TiffImagePlugin.TiffImageFile, invalid_file)
TiffImagePlugin.PREFIXES.pop()

def test_bad_exif(self):
Expand Down Expand Up @@ -236,7 +244,8 @@ def test_32bit_float(self):
im.load()

self.assertEqual(im.getpixel((0, 0)), -0.4526388943195343)
self.assertEqual(im.getextrema(), (-3.140936851501465, 3.140684127807617))
self.assertEqual(
im.getextrema(), (-3.140936851501465, 3.140684127807617))

def test_unknown_pixel_mode(self):
self.assertRaises(
Expand Down Expand Up @@ -446,7 +455,8 @@ def test_gray_semibyte_per_pixel(self):
self.assert_image_equal(im, im2)

def test_with_underscores(self):
kwargs = {"resolution_unit": "inch", "x_resolution": 72, "y_resolution": 36}
kwargs = {"resolution_unit": "inch",
"x_resolution": 72, "y_resolution": 36}
filename = self.tempfile("temp.tif")
hopper("RGB").save(filename, **kwargs)
im = Image.open(filename)
Expand Down Expand Up @@ -477,22 +487,25 @@ def test_strip_raw(self):
infile = "Tests/images/tiff_strip_raw.tif"
im = Image.open(infile)

self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
self.assert_image_equal_tofile(
im, "Tests/images/tiff_adobe_deflate.png")

def test_strip_planar_raw(self):
# gdal_translate -of GTiff -co INTERLEAVE=BAND \
# tiff_strip_raw.tif tiff_strip_planar_raw.tiff
infile = "Tests/images/tiff_strip_planar_raw.tif"
im = Image.open(infile)

self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
self.assert_image_equal_tofile(
im, "Tests/images/tiff_adobe_deflate.png")

def test_strip_planar_raw_with_overviews(self):
# gdaladdo tiff_strip_planar_raw2.tif 2 4 8 16
infile = "Tests/images/tiff_strip_planar_raw_with_overviews.tif"
im = Image.open(infile)

self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
self.assert_image_equal_tofile(
im, "Tests/images/tiff_adobe_deflate.png")

def test_tiled_planar_raw(self):
# gdal_translate -of GTiff -co TILED=YES -co BLOCKXSIZE=32 \
Expand All @@ -501,7 +514,8 @@ def test_tiled_planar_raw(self):
infile = "Tests/images/tiff_tiled_planar_raw.tif"
im = Image.open(infile)

self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
self.assert_image_equal_tofile(
im, "Tests/images/tiff_adobe_deflate.png")

def test_palette(self):
for mode in ["P", "PA"]:
Expand All @@ -528,7 +542,8 @@ def test_tiff_save_all(self):
# Test appending images
mp = io.BytesIO()
im = Image.new("RGB", (100, 100), "#f00")
ims = [Image.new("RGB", (100, 100), color) for color in ["#0f0", "#00f"]]
ims = [Image.new("RGB", (100, 100), color)
for color in ["#0f0", "#00f"]]
im.copy().save(mp, format="TIFF", save_all=True, append_images=ims)

mp.seek(0, os.SEEK_SET)
Expand All @@ -541,7 +556,8 @@ def imGenerator(ims):
yield im

mp = io.BytesIO()
im.save(mp, format="TIFF", save_all=True, append_images=imGenerator(ims))
im.save(mp, format="TIFF", save_all=True,
append_images=imGenerator(ims))

mp.seek(0, os.SEEK_SET)
reread = Image.open(mp)
Expand Down Expand Up @@ -607,7 +623,6 @@ def test_fd_leak(self):
"Tests/images/oom-225817ca0f8c663be7ab4b9e717b02c661e66834.tif",
],
)
@pytest.mark.timeout(2)
def test_oom(self, test_file):
with pytest.raises(UnidentifiedImageError):
with Image.open(test_file) as im:
Expand Down

0 comments on commit 734edca

Please sign in to comment.