]> granicus.if.org Git - python/commitdiff
Properly close files used by test_email.
authorBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 23:08:36 +0000 (23:08 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 23:08:36 +0000 (23:08 +0000)
Lib/email/test/test_email.py

index f40d77081d0dbcd3f9deefcefb66c9afb9b76c4f..34af77740a59805b9d9c5ac2fc88a4b95fe90e1f 100644 (file)
@@ -182,8 +182,8 @@ class TestMessageAPI(TestEmailBase):
     def test_message_rfc822_only(self):
         # Issue 7970: message/rfc822 not in multipart parsed by
         # HeaderParser caused an exception when flattened.
-        fp = openfile(findfile('msg_46.txt'))
-        msgdata = fp.read()
+        with openfile(findfile('msg_46.txt')) as fp:
+            msgdata = fp.read()
         parser = HeaderParser()
         msg = parser.parsestr(msgdata)
         out = StringIO()
@@ -2897,7 +2897,8 @@ class Test8BitBytesHandling(unittest.TestCase):
         self.addCleanup(unlink, fn)
         with open(fn, 'wb') as testfile:
             testfile.write(self.non_latin_bin_msg)
-        m = email.parser.BytesParser().parse(open(fn, 'rb'))
+        with open(fn, 'rb') as testfile:
+            m = email.parser.BytesParser().parse(testfile)
         self.assertEqual(str(m), self.non_latin_bin_msg_as7bit)
 
     latin_bin_msg = textwrap.dedent("""\