Fix ResourceWarning emitted during tests

Appeared in the form:

    ResourceWarning: unclosed file <_io.BufferedReader name='Tests/images/invalid-exif-without-x-resolution.jpg'>

Enable all warnings to always display during tests to help catch these
warnings earlier.
This commit is contained in:
Jon Dufresne 2020-01-26 15:59:20 -08:00
parent 22a6738a81
commit 2b84221edf
3 changed files with 22 additions and 22 deletions

View File

@ -640,11 +640,11 @@ class TestFileJpeg(PillowTestCase):
def test_invalid_exif_x_resolution(self):
# When no x or y resolution is defined in EXIF
im = Image.open("Tests/images/invalid-exif-without-x-resolution.jpg")
with Image.open("Tests/images/invalid-exif-without-x-resolution.jpg") as im:
# This should return the default, and not a ValueError or
# OSError for an unidentified image.
self.assertEqual(im.info.get("dpi"), (72, 72))
# This should return the default, and not a ValueError or
# OSError for an unidentified image.
self.assertEqual(im.info.get("dpi"), (72, 72))
def test_ifd_offset_exif(self):
# Arrange

View File

@ -231,9 +231,9 @@ class TestFileTiffMetadata(PillowTestCase):
out = self.tempfile("temp.tiff")
im.save(out, tiffinfo=info, compression="raw")
reloaded = Image.open(out)
self.assertEqual(max_long, reloaded.tag_v2[41493].numerator)
self.assertEqual(1, reloaded.tag_v2[41493].denominator)
with Image.open(out) as reloaded:
self.assertEqual(max_long, reloaded.tag_v2[41493].numerator)
self.assertEqual(1, reloaded.tag_v2[41493].denominator)
# out of bounds of 4 byte unsigned long
numerator = max_long + 1
@ -243,9 +243,9 @@ class TestFileTiffMetadata(PillowTestCase):
out = self.tempfile("temp.tiff")
im.save(out, tiffinfo=info, compression="raw")
reloaded = Image.open(out)
self.assertEqual(max_long, reloaded.tag_v2[41493].numerator)
self.assertEqual(1, reloaded.tag_v2[41493].denominator)
with Image.open(out) as reloaded:
self.assertEqual(max_long, reloaded.tag_v2[41493].numerator)
self.assertEqual(1, reloaded.tag_v2[41493].denominator)
def test_ifd_signed_rational(self):
im = hopper()
@ -260,9 +260,9 @@ class TestFileTiffMetadata(PillowTestCase):
out = self.tempfile("temp.tiff")
im.save(out, tiffinfo=info, compression="raw")
reloaded = Image.open(out)
self.assertEqual(numerator, reloaded.tag_v2[37380].numerator)
self.assertEqual(denominator, reloaded.tag_v2[37380].denominator)
with Image.open(out) as reloaded:
self.assertEqual(numerator, reloaded.tag_v2[37380].numerator)
self.assertEqual(denominator, reloaded.tag_v2[37380].denominator)
numerator = -(2 ** 31)
denominator = 2 ** 31 - 1
@ -272,9 +272,9 @@ class TestFileTiffMetadata(PillowTestCase):
out = self.tempfile("temp.tiff")
im.save(out, tiffinfo=info, compression="raw")
reloaded = Image.open(out)
self.assertEqual(numerator, reloaded.tag_v2[37380].numerator)
self.assertEqual(denominator, reloaded.tag_v2[37380].denominator)
with Image.open(out) as reloaded:
self.assertEqual(numerator, reloaded.tag_v2[37380].numerator)
self.assertEqual(denominator, reloaded.tag_v2[37380].denominator)
# out of bounds of 4 byte signed long
numerator = -(2 ** 31) - 1
@ -285,9 +285,9 @@ class TestFileTiffMetadata(PillowTestCase):
out = self.tempfile("temp.tiff")
im.save(out, tiffinfo=info, compression="raw")
reloaded = Image.open(out)
self.assertEqual(2 ** 31 - 1, reloaded.tag_v2[37380].numerator)
self.assertEqual(-1, reloaded.tag_v2[37380].denominator)
with Image.open(out) as reloaded:
self.assertEqual(2 ** 31 - 1, reloaded.tag_v2[37380].numerator)
self.assertEqual(-1, reloaded.tag_v2[37380].denominator)
def test_ifd_signed_long(self):
im = hopper()
@ -298,8 +298,8 @@ class TestFileTiffMetadata(PillowTestCase):
out = self.tempfile("temp.tiff")
im.save(out, tiffinfo=info, compression="raw")
reloaded = Image.open(out)
self.assertEqual(reloaded.tag_v2[37000], -60000)
with Image.open(out) as reloaded:
self.assertEqual(reloaded.tag_v2[37000], -60000)
def test_empty_values(self):
data = io.BytesIO(

View File

@ -14,7 +14,7 @@ commands =
{envpython} setup.py clean
{envpython} setup.py build_ext --inplace
{envpython} selftest.py
{envpython} -m pytest {posargs}
{envpython} -W always -m pytest {posargs}
deps =
cffi
numpy