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)) im.convert("P").save(test_file, dpi=(100, 100))
chunks = [] chunks = []
fp = open(test_file, "rb") with open(test_file, "rb") as fp:
fp.read(8) fp.read(8)
png = PngImagePlugin.PngStream(fp) png = PngImagePlugin.PngStream(fp)
while True: while True:
cid, pos, length = png.read() cid, pos, length = png.read()
chunks.append(cid) chunks.append(cid)
try: try:
s = png.call(cid, pos, length) s = png.call(cid, pos, length)
except EOFError: except EOFError:
break break
png.crc(cid, s) png.crc(cid, s)
# https://www.w3.org/TR/PNG/#5ChunkOrdering # https://www.w3.org/TR/PNG/#5ChunkOrdering
# IHDR - shall be first # IHDR - shall be first

View File

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

View File

@ -9,8 +9,8 @@ class TestFontBdf(PillowTestCase):
def test_sanity(self): def test_sanity(self):
test_file = open(filename, "rb") with open(filename, "rb") as test_file:
font = BdfFontFile.BdfFontFile(test_file) font = BdfFontFile.BdfFontFile(test_file)
self.assertIsInstance(font, FontFile.FontFile) self.assertIsInstance(font, FontFile.FontFile)
self.assertEqual(len([_f for _f in font.glyph if _f]), 190) 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") self.skipTest("zlib support not available")
def save_font(self): def save_font(self):
test_file = open(fontname, "rb") with open(fontname, "rb") as test_file:
font = PcfFontFile.PcfFontFile(test_file) font = PcfFontFile.PcfFontFile(test_file)
self.assertIsInstance(font, FontFile.FontFile) self.assertIsInstance(font, FontFile.FontFile)
self.assertEqual(len([_f for _f in font.glyph if _f]), 192) self.assertEqual(len([_f for _f in font.glyph if _f]), 192)