[pypy-svn] r62801 - in pypy/trunk/lib-python: 2.5.2/test modified-2.5.2
afa at codespeak.net
afa at codespeak.net
Tue Mar 10 11:34:05 CET 2009
Author: afa
Date: Tue Mar 10 11:34:04 2009
New Revision: 62801
Added:
pypy/trunk/lib-python/modified-2.5.2/mailbox.py
- copied, changed from r62778, pypy/trunk/lib-python/2.5.2/mailbox.py
Modified:
pypy/trunk/lib-python/2.5.2/test/test_mailbox.py
Log:
Fix test_mailbox on windows by carefully closing every opened file.
Phew. I'm not sure I got it right everywhere.
Modified: pypy/trunk/lib-python/2.5.2/test/test_mailbox.py
==============================================================================
--- pypy/trunk/lib-python/2.5.2/test/test_mailbox.py (original)
+++ pypy/trunk/lib-python/2.5.2/test/test_mailbox.py Tue Mar 10 11:34:04 2009
@@ -135,6 +135,7 @@
msg = self._box.get(key1)
self.assert_(msg['from'] == 'foo')
self.assert_(msg.fp.read() == '1')
+ msg.fp.close()
def test_getitem(self):
# Retrieve message using __getitem__()
@@ -167,10 +168,12 @@
# Get file representations of messages
key0 = self._box.add(self._template % 0)
key1 = self._box.add(_sample_message)
- self.assert_(self._box.get_file(key0).read().replace(os.linesep, '\n')
- == self._template % 0)
- self.assert_(self._box.get_file(key1).read().replace(os.linesep, '\n')
- == _sample_message)
+ f0 = self._box.get_file(key0)
+ self.assert_(f0.read().replace(os.linesep, '\n') == self._template % 0)
+ f0.close()
+ f1 = self._box.get_file(key1)
+ self.assert_(f1.read().replace(os.linesep, '\n') == _sample_message)
+ f1.close()
def test_iterkeys(self):
# Get keys using iterkeys()
@@ -398,6 +401,11 @@
self._box.add(contents[1])
self._box.add(contents[2])
method()
+
+ # XXX this makes some tests not useful any more,
+ # but the mailbox really must closed before we replace the variable.
+ self._box.close()
+
self._box = self._factory(self._path)
keys = self._box.keys()
self.assert_(len(keys) == 3)
@@ -757,7 +765,10 @@
self._box._file.seek(0)
contents = self._box._file.read()
self._box.close()
- self.assert_(contents == open(self._path, 'rb').read())
+ f = open(self._path, 'rb')
+ initial = f.read()
+ f.close()
+ self.assert_(contents == initial)
self._box = self._factory(self._path)
def test_lock_conflict(self):
@@ -1736,43 +1747,57 @@
#self.assert_(len(self.mbox.boxes) == 0)
self.assert_(self.mbox.next() is None)
self.assert_(self.mbox.next() is None)
+ self.mbox.close()
def test_nonempty_maildir_cur(self):
self.createMessage("cur")
self.mbox = mailbox.Maildir(test_support.TESTFN)
#self.assert_(len(self.mbox.boxes) == 1)
- self.assert_(self.mbox.next() is not None)
+ msg = self.mbox.next()
+ self.assert_(msg is not None)
+ msg.fp.close()
self.assert_(self.mbox.next() is None)
self.assert_(self.mbox.next() is None)
+ self.mbox.close()
def test_nonempty_maildir_new(self):
self.createMessage("new")
self.mbox = mailbox.Maildir(test_support.TESTFN)
#self.assert_(len(self.mbox.boxes) == 1)
- self.assert_(self.mbox.next() is not None)
+ msg = self.mbox.next()
+ self.assert_(msg is not None)
+ msg.fp.close()
self.assert_(self.mbox.next() is None)
self.assert_(self.mbox.next() is None)
+ self.mbox.close()
def test_nonempty_maildir_both(self):
self.createMessage("cur")
self.createMessage("new")
self.mbox = mailbox.Maildir(test_support.TESTFN)
#self.assert_(len(self.mbox.boxes) == 2)
- self.assert_(self.mbox.next() is not None)
- self.assert_(self.mbox.next() is not None)
+ msg = self.mbox.next()
+ self.assert_(msg is not None)
+ msg.fp.close()
+ msg = self.mbox.next()
+ self.assert_(msg is not None)
+ msg.fp.close()
self.assert_(self.mbox.next() is None)
self.assert_(self.mbox.next() is None)
+ self.mbox.close()
def test_unix_mbox(self):
### should be better!
import email.Parser
fname = self.createMessage("cur", True)
n = 0
- for msg in mailbox.PortableUnixMailbox(open(fname),
+ fp = open(fname)
+ for msg in mailbox.PortableUnixMailbox(fp,
email.Parser.Parser().parse):
n += 1
self.assertEqual(msg["subject"], "Simple Test")
self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE))
+ fp.close()
self.assertEqual(n, 1)
## End: classes from the original module (for backward compatibility).
Copied: pypy/trunk/lib-python/modified-2.5.2/mailbox.py (from r62778, pypy/trunk/lib-python/2.5.2/mailbox.py)
==============================================================================
--- pypy/trunk/lib-python/2.5.2/mailbox.py (original)
+++ pypy/trunk/lib-python/modified-2.5.2/mailbox.py Tue Mar 10 11:34:04 2009
@@ -1780,6 +1780,7 @@
def close(self):
"""Close the file."""
+ self._file.close()
del self._file
def _read(self, size, read_method):
@@ -1801,6 +1802,11 @@
self._start = start
self._stop = stop
+ def close(self):
+ """Close the file."""
+ # But do not close the underlying file
+ del self._file
+
def tell(self):
"""Return the position with respect to start."""
return _ProxyFile.tell(self) - self._start
More information about the Pypy-commit
mailing list