Changed file opening in tests to use with

This commit is contained in:
Andrew Murray 2017-08-26 10:20:30 +10:00
parent 751a6d1c2d
commit c10ad19a2b
4 changed files with 21 additions and 21 deletions

View File

@ -505,17 +505,17 @@ class TestFilePng(PillowTestCase):
im.convert("P").save(test_file, dpi=(100, 100))
chunks = []
fp = open(test_file, "rb")
fp.read(8)
png = PngImagePlugin.PngStream(fp)
while True:
cid, pos, length = png.read()
chunks.append(cid)
try:
s = png.call(cid, pos, length)
except EOFError:
break
png.crc(cid, s)
with open(test_file, "rb") as fp:
fp.read(8)
png = PngImagePlugin.PngStream(fp)
while True:
cid, pos, length = png.read()
chunks.append(cid)
try:
s = png.call(cid, pos, length)
except EOFError:
break
png.crc(cid, s)
# https://www.w3.org/TR/PNG/#5ChunkOrdering
# IHDR - shall be first

View File

@ -495,12 +495,12 @@ class TestFileTiff(PillowTestCase):
with Image.open("Tests/images/uint16_1_4660.tif") as im:
im.save(tmpfile)
f = open(tmpfile, 'rb')
im = Image.open(f)
fp = im.fp
self.assertFalse(fp.closed)
im.load()
self.assertFalse(fp.closed)
with open(tmpfile, 'rb') as f:
im = Image.open(f)
fp = im.fp
self.assertFalse(fp.closed)
im.load()
self.assertFalse(fp.closed)
@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only")
class TestFileTiffW32(PillowTestCase):

View File

@ -9,8 +9,8 @@ class TestFontBdf(PillowTestCase):
def test_sanity(self):
test_file = open(filename, "rb")
font = BdfFontFile.BdfFontFile(test_file)
with open(filename, "rb") as test_file:
font = BdfFontFile.BdfFontFile(test_file)
self.assertIsInstance(font, FontFile.FontFile)
self.assertEqual(len([_f for _f in font.glyph if _f]), 190)

View File

@ -17,8 +17,8 @@ class TestFontPcf(PillowTestCase):
self.skipTest("zlib support not available")
def save_font(self):
test_file = open(fontname, "rb")
font = PcfFontFile.PcfFontFile(test_file)
with open(fontname, "rb") as test_file:
font = PcfFontFile.PcfFontFile(test_file)
self.assertIsInstance(font, FontFile.FontFile)
self.assertEqual(len([_f for _f in font.glyph if _f]), 192)