[Python-checkins] r85447 - python/branches/release27-maint/Lib/test/test_mailbox.py

brian.curtin python-checkins at python.org
Thu Oct 14 03:14:36 CEST 2010


Author: brian.curtin
Date: Thu Oct 14 03:14:36 2010
New Revision: 85447

Log:
Merged revisions 85401 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85401 | brian.curtin | 2010-10-12 21:29:46 -0500 (Tue, 12 Oct 2010) | 3 lines
  
  Implement #7944. Use `with` throughout the test suite.
........


Modified:
   python/branches/release27-maint/Lib/test/test_mailbox.py

Modified: python/branches/release27-maint/Lib/test/test_mailbox.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_mailbox.py	(original)
+++ python/branches/release27-maint/Lib/test/test_mailbox.py	Thu Oct 14 03:14:36 2010
@@ -598,12 +598,10 @@
         # Remove old files from 'tmp'
         foo_path = os.path.join(self._path, 'tmp', 'foo')
         bar_path = os.path.join(self._path, 'tmp', 'bar')
-        f = open(foo_path, 'w')
-        f.write("@")
-        f.close()
-        f = open(bar_path, 'w')
-        f.write("@")
-        f.close()
+        with open(foo_path, 'w') as f:
+            f.write("@")
+        with open(bar_path, 'w') as f:
+            f.write("@")
         self._box.clean()
         self.assertTrue(os.path.exists(foo_path))
         self.assertTrue(os.path.exists(bar_path))
@@ -1088,13 +1086,12 @@
 
     def test_initialize_with_file(self):
         # Initialize based on contents of file
-        f = open(self._path, 'w+')
-        f.write(_sample_message)
-        f.seek(0)
-        msg = self._factory(f)
-        self._post_initialize_hook(msg)
-        self._check_sample(msg)
-        f.close()
+        with open(self._path, 'w+') as f:
+            f.write(_sample_message)
+            f.seek(0)
+            msg = self._factory(f)
+            self._post_initialize_hook(msg)
+            self._check_sample(msg)
 
     def test_initialize_with_nothing(self):
         # Initialize without arguments
@@ -1812,18 +1809,16 @@
         filename = os.extsep.join((str(t), str(pid), "myhostname", "mydomain"))
         tmpname = os.path.join(self._dir, "tmp", filename)
         newname = os.path.join(self._dir, dir, filename)
-        fp = open(tmpname, "w")
-        self._msgfiles.append(tmpname)
-        if mbox:
-            fp.write(FROM_)
-        fp.write(DUMMY_MESSAGE)
-        fp.close()
+        with open(tmpname, "w") as fp:
+            self._msgfiles.append(tmpname)
+            if mbox:
+                fp.write(FROM_)
+            fp.write(DUMMY_MESSAGE)
         if hasattr(os, "link"):
             os.link(tmpname, newname)
         else:
-            fp = open(newname, "w")
-            fp.write(DUMMY_MESSAGE)
-            fp.close()
+            with open(newname, "w") as fp:
+                fp.write(DUMMY_MESSAGE)
         self._msgfiles.append(newname)
         return tmpname
 


More information about the Python-checkins mailing list