Commit 5253da16 authored by Skip Montanaro's avatar Skip Montanaro

added test for bug #996359.

parent 3414c1ce
...@@ -10,15 +10,15 @@ try: ...@@ -10,15 +10,15 @@ try:
except os.error: except os.error:
pass pass
FROM_ = "From some.body@dummy.domain Sat Jul 24 13:43:35 2004\n"
DUMMY_MESSAGE = """\ DUMMY_MESSAGE = """\
From: some.body@dummy.domain From: some.body@dummy.domain
To: me@my.domain To: me@my.domain
Subject: Simple Test
This is a dummy message. This is a dummy message.
""" """
class MaildirTestCase(unittest.TestCase): class MaildirTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -38,7 +38,7 @@ class MaildirTestCase(unittest.TestCase): ...@@ -38,7 +38,7 @@ class MaildirTestCase(unittest.TestCase):
os.rmdir(os.path.join(self._dir, "new")) os.rmdir(os.path.join(self._dir, "new"))
os.rmdir(self._dir) os.rmdir(self._dir)
def createMessage(self, dir): def createMessage(self, dir, mbox=False):
t = int(time.time() % 1000000) t = int(time.time() % 1000000)
pid = self._counter pid = self._counter
self._counter += 1 self._counter += 1
...@@ -47,6 +47,8 @@ class MaildirTestCase(unittest.TestCase): ...@@ -47,6 +47,8 @@ class MaildirTestCase(unittest.TestCase):
newname = os.path.join(self._dir, dir, filename) newname = os.path.join(self._dir, dir, filename)
fp = open(tmpname, "w") fp = open(tmpname, "w")
self._msgfiles.append(tmpname) self._msgfiles.append(tmpname)
if mbox:
fp.write(FROM_)
fp.write(DUMMY_MESSAGE) fp.write(DUMMY_MESSAGE)
fp.close() fp.close()
if hasattr(os, "link"): if hasattr(os, "link"):
...@@ -56,6 +58,7 @@ class MaildirTestCase(unittest.TestCase): ...@@ -56,6 +58,7 @@ class MaildirTestCase(unittest.TestCase):
fp.write(DUMMY_MESSAGE) fp.write(DUMMY_MESSAGE)
fp.close() fp.close()
self._msgfiles.append(newname) self._msgfiles.append(newname)
return tmpname
def test_empty_maildir(self): def test_empty_maildir(self):
"""Test an empty maildir mailbox""" """Test an empty maildir mailbox"""
...@@ -93,6 +96,18 @@ class MaildirTestCase(unittest.TestCase): ...@@ -93,6 +96,18 @@ class MaildirTestCase(unittest.TestCase):
self.assert_(self.mbox.next() is None) self.assert_(self.mbox.next() is 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)
# XXX We still need more tests! # XXX We still need more tests!
......
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