[pypy-commit] pypy win32-stdlib: finish test_mailbox
mattip
noreply at buildbot.pypy.org
Wed Apr 11 15:30:33 CEST 2012
Author: Matti Picus <matti.picus at gmail.com>
Branch: win32-stdlib
Changeset: r54286:5e1e95bc2659
Date: 2012-04-11 16:00 +0300
http://bitbucket.org/pypy/pypy/changeset/5e1e95bc2659/
Log: finish test_mailbox
diff --git a/lib-python/modified-2.7/mailbox.py b/lib-python/modified-2.7/mailbox.py
--- a/lib-python/modified-2.7/mailbox.py
+++ b/lib-python/modified-2.7/mailbox.py
@@ -619,7 +619,9 @@
"""Write any pending changes to disk."""
if not self._pending:
return
-
+ if self._file.closed:
+ self._pending = False
+ return
# In order to be writing anything out at all, self._toc must
# already have been generated (and presumably has been modified
# by adding or deleting an item).
@@ -747,6 +749,7 @@
"""Return a file-like representation or raise a KeyError."""
start, stop = self._lookup(key)
self._file.seek(start)
+
if not from_:
self._file.readline()
return _PartialFile(self._file, self._file.tell(), stop)
diff --git a/lib-python/modified-2.7/test/test_mailbox.py b/lib-python/modified-2.7/test/test_mailbox.py
--- a/lib-python/modified-2.7/test/test_mailbox.py
+++ b/lib-python/modified-2.7/test/test_mailbox.py
@@ -44,7 +44,7 @@
for name in dirs:
os.rmdir(os.path.join(path, name))
os.rmdir(target)
- elif os.pathtexists(target):
+ elif os.path.exists(target):
os.remove(target)
@@ -60,6 +60,8 @@
def tearDown(self):
self._box.close()
+ if os.name == 'nt':
+ time.sleep(0.1) #Allow all syncing to take place
self._delete_recursively(self._path)
def test_add(self):
@@ -170,12 +172,12 @@
# Get file representations of messages
key0 = self._box.add(self._template % 0)
key1 = self._box.add(_sample_message)
- msg = self._box.get_file(key0)
- self.assertEqual(msg.read().replace(os.linesep, '\n'), self._template % 0)
- msg.close()
- msg = self._box.get_file(key1)
- self.assertEqual(msg.read().replace(os.linesep, '\n'), _sample_message)
- msg.close()
+ msg0 = self._box.get_file(key0)
+ self.assertEqual(msg0.read().replace(os.linesep, '\n'), self._template % 0)
+ msg1 = self._box.get_file(key1)
+ self.assertEqual(msg1.read().replace(os.linesep, '\n'), _sample_message)
+ msg0.close()
+ msg1.close()
def test_iterkeys(self):
# Get keys using iterkeys()
@@ -789,6 +791,8 @@
class _TestMboxMMDF(TestMailbox):
def tearDown(self):
+ if os.name == 'nt':
+ time.sleep(0.1) #Allow os to sync files
self._box.close()
self._delete_recursively(self._path)
for lock_remnant in glob.glob(self._path + '.*'):
@@ -1840,7 +1844,9 @@
self.createMessage("cur")
self.mbox = mailbox.Maildir(test_support.TESTFN)
#self.assertTrue(len(self.mbox.boxes) == 1)
- self.assertIsNot(self.mbox.next(), None)
+ msg = self.mbox.next()
+ self.assertIsNot(msg, None)
+ msg.fp.close()
self.assertIs(self.mbox.next(), None)
self.assertIs(self.mbox.next(), None)
@@ -1848,7 +1854,9 @@
self.createMessage("new")
self.mbox = mailbox.Maildir(test_support.TESTFN)
#self.assertTrue(len(self.mbox.boxes) == 1)
- self.assertIsNot(self.mbox.next(), None)
+ msg = self.mbox.next()
+ self.assertIsNot(msg, None)
+ msg.fp.close()
self.assertIs(self.mbox.next(), None)
self.assertIs(self.mbox.next(), None)
@@ -1857,8 +1865,12 @@
self.createMessage("new")
self.mbox = mailbox.Maildir(test_support.TESTFN)
#self.assertTrue(len(self.mbox.boxes) == 2)
- self.assertIsNot(self.mbox.next(), None)
- self.assertIsNot(self.mbox.next(), None)
+ msg = self.mbox.next()
+ self.assertIsNot(msg, None)
+ msg.fp.close()
+ msg = self.mbox.next()
+ self.assertIsNot(msg, None)
+ msg.fp.close()
self.assertIs(self.mbox.next(), None)
self.assertIs(self.mbox.next(), None)
@@ -1867,11 +1879,13 @@
import email.parser
fname = self.createMessage("cur", True)
n = 0
- for msg in mailbox.PortableUnixMailbox(open(fname),
+ fid = open(fname)
+ for msg in mailbox.PortableUnixMailbox(fid,
email.parser.Parser().parse):
n += 1
self.assertEqual(msg["subject"], "Simple Test")
self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE))
+ fid.close()
self.assertEqual(n, 1)
## End: classes from the original module (for backward compatibility).
More information about the pypy-commit
mailing list