7 # cleanup earlier tests
9 os
.unlink(test_support
.TESTFN
)
15 From: some.body@dummy.domain
18 This is a dummy message.
22 class MaildirTestCase(unittest
.TestCase
):
25 # create a new maildir mailbox to work with:
26 self
._dir
= test_support
.TESTFN
28 os
.mkdir(os
.path
.join(self
._dir
, "cur"))
29 os
.mkdir(os
.path
.join(self
._dir
, "tmp"))
30 os
.mkdir(os
.path
.join(self
._dir
, "new"))
35 map(os
.unlink
, self
._msgfiles
)
36 os
.rmdir(os
.path
.join(self
._dir
, "cur"))
37 os
.rmdir(os
.path
.join(self
._dir
, "tmp"))
38 os
.rmdir(os
.path
.join(self
._dir
, "new"))
41 def createMessage(self
, dir):
42 t
= int(time
.time() % 1000000)
45 filename
= "%s.%s.myhostname.mydomain" % (t
, pid
)
46 tmpname
= os
.path
.join(self
._dir
, "tmp", filename
)
47 newname
= os
.path
.join(self
._dir
, dir, filename
)
48 fp
= open(tmpname
, "w")
49 self
._msgfiles
.append(tmpname
)
50 fp
.write(DUMMY_MESSAGE
)
52 if hasattr(os
, "link"):
53 os
.link(tmpname
, newname
)
55 fp
= open(newname
, "w")
56 fp
.write(DUMMY_MESSAGE
)
58 self
._msgfiles
.append(newname
)
60 def test_empty_maildir(self
):
61 """Test an empty maildir mailbox"""
62 # Test for regression on bug #117490:
63 # Make sure the boxes attribute actually gets set.
64 self
.mbox
= mailbox
.Maildir(test_support
.TESTFN
)
65 self
.assert_(hasattr(self
.mbox
, "boxes"))
66 self
.assert_(len(self
.mbox
.boxes
) == 0)
67 self
.assert_(self
.mbox
.next() is None)
68 self
.assert_(self
.mbox
.next() is None)
70 def test_nonempty_maildir_cur(self
):
71 self
.createMessage("cur")
72 self
.mbox
= mailbox
.Maildir(test_support
.TESTFN
)
73 self
.assert_(len(self
.mbox
.boxes
) == 1)
74 self
.assert_(self
.mbox
.next() is not None)
75 self
.assert_(self
.mbox
.next() is None)
76 self
.assert_(self
.mbox
.next() is None)
78 def test_nonempty_maildir_new(self
):
79 self
.createMessage("new")
80 self
.mbox
= mailbox
.Maildir(test_support
.TESTFN
)
81 self
.assert_(len(self
.mbox
.boxes
) == 1)
82 self
.assert_(self
.mbox
.next() is not None)
83 self
.assert_(self
.mbox
.next() is None)
84 self
.assert_(self
.mbox
.next() is None)
86 def test_nonempty_maildir_both(self
):
87 self
.createMessage("cur")
88 self
.createMessage("new")
89 self
.mbox
= mailbox
.Maildir(test_support
.TESTFN
)
90 self
.assert_(len(self
.mbox
.boxes
) == 2)
91 self
.assert_(self
.mbox
.next() is not None)
92 self
.assert_(self
.mbox
.next() is not None)
93 self
.assert_(self
.mbox
.next() is None)
94 self
.assert_(self
.mbox
.next() is None)
96 # XXX We still need more tests!
100 test_support
.run_unittest(MaildirTestCase
)
103 if __name__
== "__main__":