Commit 04d8b220 authored by Brian Curtin's avatar Brian Curtin

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.
........
parent 31cf8d07
...@@ -598,12 +598,10 @@ class TestMaildir(TestMailbox): ...@@ -598,12 +598,10 @@ class TestMaildir(TestMailbox):
# Remove old files from 'tmp' # Remove old files from 'tmp'
foo_path = os.path.join(self._path, 'tmp', 'foo') foo_path = os.path.join(self._path, 'tmp', 'foo')
bar_path = os.path.join(self._path, 'tmp', 'bar') bar_path = os.path.join(self._path, 'tmp', 'bar')
f = open(foo_path, 'w') with open(foo_path, 'w') as f:
f.write("@") f.write("@")
f.close() with open(bar_path, 'w') as f:
f = open(bar_path, 'w')
f.write("@") f.write("@")
f.close()
self._box.clean() self._box.clean()
self.assertTrue(os.path.exists(foo_path)) self.assertTrue(os.path.exists(foo_path))
self.assertTrue(os.path.exists(bar_path)) self.assertTrue(os.path.exists(bar_path))
...@@ -1088,13 +1086,12 @@ class TestMessage(TestBase): ...@@ -1088,13 +1086,12 @@ class TestMessage(TestBase):
def test_initialize_with_file(self): def test_initialize_with_file(self):
# Initialize based on contents of file # Initialize based on contents of file
f = open(self._path, 'w+') with open(self._path, 'w+') as f:
f.write(_sample_message) f.write(_sample_message)
f.seek(0) f.seek(0)
msg = self._factory(f) msg = self._factory(f)
self._post_initialize_hook(msg) self._post_initialize_hook(msg)
self._check_sample(msg) self._check_sample(msg)
f.close()
def test_initialize_with_nothing(self): def test_initialize_with_nothing(self):
# Initialize without arguments # Initialize without arguments
...@@ -1812,18 +1809,16 @@ class MaildirTestCase(unittest.TestCase): ...@@ -1812,18 +1809,16 @@ class MaildirTestCase(unittest.TestCase):
filename = os.extsep.join((str(t), str(pid), "myhostname", "mydomain")) filename = os.extsep.join((str(t), str(pid), "myhostname", "mydomain"))
tmpname = os.path.join(self._dir, "tmp", filename) tmpname = os.path.join(self._dir, "tmp", filename)
newname = os.path.join(self._dir, dir, filename) newname = os.path.join(self._dir, dir, filename)
fp = open(tmpname, "w") with open(tmpname, "w") as fp:
self._msgfiles.append(tmpname) self._msgfiles.append(tmpname)
if mbox: if mbox:
fp.write(FROM_) fp.write(FROM_)
fp.write(DUMMY_MESSAGE) fp.write(DUMMY_MESSAGE)
fp.close()
if hasattr(os, "link"): if hasattr(os, "link"):
os.link(tmpname, newname) os.link(tmpname, newname)
else: else:
fp = open(newname, "w") with open(newname, "w") as fp:
fp.write(DUMMY_MESSAGE) fp.write(DUMMY_MESSAGE)
fp.close()
self._msgfiles.append(newname) self._msgfiles.append(newname)
return tmpname return tmpname
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment