diff options
author | Fred Drake <fdrake@acm.org> | 2001-05-21 20:23:21 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2001-05-21 20:23:21 (GMT) |
commit | c02bc3e81900cf46adb897e76d61f3983607d83d (patch) | |
tree | 3f03dbe8888b8df5b24ddcceff06f2416af55af5 /Lib/test | |
parent | 39d345127e7cdf09024420596136b0b785239199 (diff) | |
download | cpython-c02bc3e81900cf46adb897e76d61f3983607d83d.zip cpython-c02bc3e81900cf46adb897e76d61f3983607d83d.tar.gz cpython-c02bc3e81900cf46adb897e76d61f3983607d83d.tar.bz2 |
Re-write the mailbox test suite to use PyUnit. Cover a lot more ground
for the Maildir mailbox format. This still does not address other mailbox
formats.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/output/test_mailbox | 1 | ||||
-rw-r--r-- | Lib/test/test_mailbox.py | 102 |
2 files changed, 81 insertions, 22 deletions
diff --git a/Lib/test/output/test_mailbox b/Lib/test/output/test_mailbox index eada229..7b0e6be 100644 --- a/Lib/test/output/test_mailbox +++ b/Lib/test/output/test_mailbox @@ -1,2 +1 @@ test_mailbox -newly created maildir contains 0 messages diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index 1d1a063..9858459 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -1,34 +1,94 @@ import mailbox import os import test_support +import time +import unittest -# cleanup +# cleanup earlier tests try: os.unlink(test_support.TESTFN) except os.error: pass -# create a new maildir mailbox to work with: -curdir = os.path.join(test_support.TESTFN, "cur") -newdir = os.path.join(test_support.TESTFN, "new") -try: - os.mkdir(test_support.TESTFN) - os.mkdir(curdir) - os.mkdir(newdir) - # Test for regression on bug #117490: - # http://sourceforge.net/bugs/?func=detailbug&bug_id=117490&group_id=5470 - # Make sure the boxes attribute actually gets set. - mbox = mailbox.Maildir(test_support.TESTFN) - mbox.boxes - print "newly created maildir contains", len(mbox.boxes), "messages" +DUMMY_MESSAGE = """\ +From: some.body@dummy.domain +To: me@my.domain + +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): + t = int(time.time()) + pid = self._counter + self._counter += 1 + filename = "%s.%s.myhostname.mydomain" % (t, pid) + tmpname = os.path.join(self._dir, "tmp", filename) + newname = os.path.join(self._dir, dir, filename) + fp = open(tmpname, "w") + self._msgfiles.append(tmpname) + fp.write(DUMMY_MESSAGE) + fp.close() + os.link(tmpname, newname) + self._msgfiles.append(newname) + + def test_empty_maildir(self): + """Test an empty maildir mailbox""" + # Test for regression on bug #117490: + # Make sure the boxes attribute actually gets set. + self.mbox = mailbox.Maildir(test_support.TESTFN) + self.assert_(hasattr(self.mbox, "boxes")) + self.assert_(len(self.mbox.boxes) == 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.boxes) == 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.boxes) == 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.boxes) == 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) # XXX We still need more tests! -finally: - try: os.rmdir(newdir) - except os.error: pass - try: os.rmdir(curdir) - except os.error: pass - try: os.rmdir(test_support.TESTFN) - except os.error: pass + +test_support.run_unittest(MaildirTestCase) |