mirror of
https://github.com/python/cpython.git
synced 2024-12-14 04:17:19 +08:00
9fe394c1be
svn+ssh://pythondev@svn.python.org/python/trunk ........ r53545 | andrew.kuchling | 2007-01-24 21:06:41 +0100 (Wed, 24 Jan 2007) | 1 line Strengthen warning about using lock() ........ r53556 | thomas.heller | 2007-01-25 19:34:14 +0100 (Thu, 25 Jan 2007) | 3 lines Fix for #1643874: When calling SysAllocString, create a PyCObject which will eventually call SysFreeString to free the BSTR resource. ........ r53563 | andrew.kuchling | 2007-01-25 21:02:13 +0100 (Thu, 25 Jan 2007) | 1 line Add item ........ r53564 | brett.cannon | 2007-01-25 21:22:02 +0100 (Thu, 25 Jan 2007) | 8 lines Fix time.strptime's %U support. Basically rewrote the algorithm to be more generic so that one only has to shift certain values based on whether the week was specified to start on Monday or Sunday. Cut out a lot of edge case code compared to the previous version. Also broke algorithm out into its own function (that is private to the module). Fixes bug #1643943 (thanks Biran Nahas for the report). ........ r53570 | brett.cannon | 2007-01-26 00:30:39 +0100 (Fri, 26 Jan 2007) | 4 lines Remove specific mention of my name and email address from modules. Not really needed and all bug reports should go to the bug tracker, not directly to me. Plus I am not the only person to have edited these files at this point. ........ r53573 | fred.drake | 2007-01-26 17:28:44 +0100 (Fri, 26 Jan 2007) | 1 line fix typo (extraneous ")") ........ r53575 | georg.brandl | 2007-01-27 18:43:02 +0100 (Sat, 27 Jan 2007) | 4 lines Patch #1638243: the compiler package is now able to correctly compile a with statement; previously, executing code containing a with statement compiled by the compiler package crashed the interpreter. ........ r53578 | georg.brandl | 2007-01-27 18:59:42 +0100 (Sat, 27 Jan 2007) | 3 lines Patch #1634778: add missing encoding aliases for iso8859_15 and iso8859_16. ........ r53579 | georg.brandl | 2007-01-27 20:38:50 +0100 (Sat, 27 Jan 2007) | 2 lines Bug #1645944: os.access now returns bool but docstring is not updated ........ r53590 | brett.cannon | 2007-01-28 21:58:00 +0100 (Sun, 28 Jan 2007) | 2 lines Use the thread lock's context manager instead of a try/finally statement. ........ r53591 | brett.cannon | 2007-01-29 05:41:44 +0100 (Mon, 29 Jan 2007) | 2 lines Add a test for slicing an exception. ........ r53594 | andrew.kuchling | 2007-01-29 21:21:43 +0100 (Mon, 29 Jan 2007) | 1 line Minor edits to the curses HOWTO ........ r53596 | andrew.kuchling | 2007-01-29 21:55:40 +0100 (Mon, 29 Jan 2007) | 1 line Various minor edits ........ r53597 | andrew.kuchling | 2007-01-29 22:28:48 +0100 (Mon, 29 Jan 2007) | 1 line More edits ........ r53601 | tim.peters | 2007-01-30 04:03:46 +0100 (Tue, 30 Jan 2007) | 2 lines Whitespace normalization. ........ r53603 | georg.brandl | 2007-01-30 21:21:30 +0100 (Tue, 30 Jan 2007) | 2 lines Bug #1648191: typo in docs. ........ r53605 | brett.cannon | 2007-01-30 22:34:36 +0100 (Tue, 30 Jan 2007) | 8 lines No more raising of string exceptions! The next step of PEP 352 (for 2.6) causes raising a string exception to trigger a TypeError. Trying to catch a string exception raises a DeprecationWarning. References to string exceptions has been removed from the docs since they are now just an error. ........ r53618 | raymond.hettinger | 2007-02-01 22:02:59 +0100 (Thu, 01 Feb 2007) | 1 line Bug #1648179: set.update() not recognizing __iter__ overrides in dict subclasses. ........
154 lines
4.5 KiB
Python
154 lines
4.5 KiB
Python
# This set of tests exercises the backward-compatibility class
|
|
# in mailbox.py (the ones without write support).
|
|
|
|
import mailbox
|
|
import os
|
|
import time
|
|
import unittest
|
|
from test import test_support
|
|
|
|
# cleanup earlier tests
|
|
try:
|
|
os.unlink(test_support.TESTFN)
|
|
except os.error:
|
|
pass
|
|
|
|
FROM_ = "From some.body@dummy.domain Sat Jul 24 13:43:35 2004\n"
|
|
DUMMY_MESSAGE = """\
|
|
From: some.body@dummy.domain
|
|
To: me@my.domain
|
|
Subject: Simple Test
|
|
|
|
This is a dummy message.
|
|
"""
|
|
|
|
class MaildirTestCase(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
# create a new maildir mailbox to work with:
|
|
self._dir = test_support.TESTFN
|
|
os.mkdir(self._dir)
|
|
os.mkdir(os.path.join(self._dir, "cur"))
|
|
os.mkdir(os.path.join(self._dir, "tmp"))
|
|
os.mkdir(os.path.join(self._dir, "new"))
|
|
self._counter = 1
|
|
self._msgfiles = []
|
|
|
|
def tearDown(self):
|
|
map(os.unlink, self._msgfiles)
|
|
os.rmdir(os.path.join(self._dir, "cur"))
|
|
os.rmdir(os.path.join(self._dir, "tmp"))
|
|
os.rmdir(os.path.join(self._dir, "new"))
|
|
os.rmdir(self._dir)
|
|
|
|
def createMessage(self, dir, mbox=False):
|
|
t = int(time.time() % 1000000)
|
|
pid = self._counter
|
|
self._counter += 1
|
|
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()
|
|
if hasattr(os, "link"):
|
|
os.link(tmpname, newname)
|
|
else:
|
|
fp = open(newname, "w")
|
|
fp.write(DUMMY_MESSAGE)
|
|
fp.close()
|
|
self._msgfiles.append(newname)
|
|
return tmpname
|
|
|
|
def test_empty_maildir(self):
|
|
"""Test an empty maildir mailbox"""
|
|
# Test for regression on bug #117490:
|
|
self.mbox = mailbox.Maildir(test_support.TESTFN)
|
|
self.assert_(len(self.mbox) == 0)
|
|
self.assert_(self.mbox.next() is None)
|
|
self.assert_(self.mbox.next() is None)
|
|
|
|
def test_nonempty_maildir_cur(self):
|
|
self.createMessage("cur")
|
|
self.mbox = mailbox.Maildir(test_support.TESTFN)
|
|
self.assert_(len(self.mbox) == 1)
|
|
self.assert_(self.mbox.next() is not None)
|
|
self.assert_(self.mbox.next() is None)
|
|
self.assert_(self.mbox.next() is None)
|
|
|
|
def test_nonempty_maildir_new(self):
|
|
self.createMessage("new")
|
|
self.mbox = mailbox.Maildir(test_support.TESTFN)
|
|
self.assert_(len(self.mbox) == 1)
|
|
self.assert_(self.mbox.next() is not None)
|
|
self.assert_(self.mbox.next() is None)
|
|
self.assert_(self.mbox.next() is None)
|
|
|
|
def test_nonempty_maildir_both(self):
|
|
self.createMessage("cur")
|
|
self.createMessage("new")
|
|
self.mbox = mailbox.Maildir(test_support.TESTFN)
|
|
self.assert_(len(self.mbox) == 2)
|
|
self.assert_(self.mbox.next() is not None)
|
|
self.assert_(self.mbox.next() is not None)
|
|
self.assert_(self.mbox.next() is None)
|
|
self.assert_(self.mbox.next() is None)
|
|
|
|
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),
|
|
email.Parser.Parser().parse):
|
|
n += 1
|
|
self.assertEqual(msg["subject"], "Simple Test")
|
|
self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE))
|
|
self.assertEqual(n, 1)
|
|
|
|
class MboxTestCase(unittest.TestCase):
|
|
def setUp(self):
|
|
# create a new maildir mailbox to work with:
|
|
self._path = test_support.TESTFN
|
|
|
|
def tearDown(self):
|
|
os.unlink(self._path)
|
|
|
|
def test_from_regex (self):
|
|
# Testing new regex from bug #1633678
|
|
f = open(self._path, 'w')
|
|
f.write("""From fred@example.com Mon May 31 13:24:50 2004 +0200
|
|
Subject: message 1
|
|
|
|
body1
|
|
From fred@example.com Mon May 31 13:24:50 2004 -0200
|
|
Subject: message 2
|
|
|
|
body2
|
|
From fred@example.com Mon May 31 13:24:50 2004
|
|
Subject: message 3
|
|
|
|
body3
|
|
From fred@example.com Mon May 31 13:24:50 2004
|
|
Subject: message 4
|
|
|
|
body4
|
|
""")
|
|
f.close()
|
|
box = mailbox.UnixMailbox(open(self._path, 'r'))
|
|
self.assert_(len(list(iter(box))) == 4)
|
|
|
|
|
|
# XXX We still need more tests!
|
|
|
|
|
|
def test_main():
|
|
test_support.run_unittest(MaildirTestCase, MboxTestCase)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_main()
|