2001-08-09 15:18:08 -03:00
|
|
|
"""
|
|
|
|
Tests for the mhlib module
|
|
|
|
Nick Mathewson
|
|
|
|
"""
|
|
|
|
|
|
|
|
### BUG: This suite doesn't currently test the mime functionality of
|
|
|
|
### mhlib. It should.
|
|
|
|
|
|
|
|
import unittest
|
2002-07-23 16:04:11 -03:00
|
|
|
from test.test_support import run_unittest, TESTFN, TestSkipped
|
2001-08-09 15:18:08 -03:00
|
|
|
import os, StringIO
|
2001-08-09 18:34:54 -03:00
|
|
|
import sys
|
2001-08-09 15:18:08 -03:00
|
|
|
import mhlib
|
|
|
|
|
2002-08-04 19:35:31 -03:00
|
|
|
if (sys.platform.startswith("win") or sys.platform=="riscos" or
|
2002-08-04 19:52:30 -03:00
|
|
|
sys.platform.startswith("atheos")):
|
2002-08-04 19:35:31 -03:00
|
|
|
# mhlib.updateline() renames a file to the name of a file that already
|
|
|
|
# exists. That causes a reasonable OS <wink> to complain in test_sequence
|
|
|
|
# here, like the "OSError: [Errno 17] File exists" raised on Windows.
|
|
|
|
# mhlib's listsubfolders() and listallfolders() do something with
|
|
|
|
# link counts, and that causes test_listfolders() here to get back
|
|
|
|
# an empty list from its call of listallfolders().
|
|
|
|
# The other tests here pass on Windows.
|
2002-08-04 19:55:35 -03:00
|
|
|
raise TestSkipped("skipped on %s -- " % sys.platform +
|
2001-08-09 18:34:54 -03:00
|
|
|
"too many Unix assumptions")
|
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
_mhroot = TESTFN+"_MH"
|
|
|
|
_mhpath = os.path.join(_mhroot, "MH")
|
|
|
|
_mhprofile = os.path.join(_mhroot, ".mh_profile")
|
|
|
|
|
|
|
|
def normF(f):
|
|
|
|
return os.path.join(*f.split('/'))
|
|
|
|
|
|
|
|
def writeFile(fname, contents):
|
|
|
|
dir = os.path.split(fname)[0]
|
|
|
|
if dir and not os.path.exists(dir):
|
|
|
|
mkdirs(dir)
|
|
|
|
f = open(fname, 'w')
|
|
|
|
f.write(contents)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def readFile(fname):
|
|
|
|
f = open(fname)
|
|
|
|
r = f.read()
|
|
|
|
f.close()
|
|
|
|
return r
|
|
|
|
|
|
|
|
def writeProfile(dict):
|
2007-02-11 02:12:03 -04:00
|
|
|
contents = [ "%s: %s\n" % (k, v) for k, v in dict.items() ]
|
2001-08-09 15:18:08 -03:00
|
|
|
writeFile(_mhprofile, "".join(contents))
|
|
|
|
|
|
|
|
def writeContext(folder):
|
|
|
|
folder = normF(folder)
|
2001-08-09 18:40:30 -03:00
|
|
|
writeFile(os.path.join(_mhpath, "context"),
|
2001-08-09 15:18:08 -03:00
|
|
|
"Current-Folder: %s\n" % folder)
|
|
|
|
|
|
|
|
def writeCurMessage(folder, cur):
|
|
|
|
folder = normF(folder)
|
|
|
|
writeFile(os.path.join(_mhpath, folder, ".mh_sequences"),
|
|
|
|
"cur: %s\n"%cur)
|
|
|
|
|
|
|
|
def writeMessage(folder, n, headers, body):
|
|
|
|
folder = normF(folder)
|
2007-02-11 02:12:03 -04:00
|
|
|
headers = "".join([ "%s: %s\n" % (k, v) for k, v in headers.items() ])
|
2001-08-09 15:18:08 -03:00
|
|
|
contents = "%s\n%s\n" % (headers,body)
|
|
|
|
mkdirs(os.path.join(_mhpath, folder))
|
|
|
|
writeFile(os.path.join(_mhpath, folder, str(n)), contents)
|
|
|
|
|
|
|
|
def getMH():
|
|
|
|
return mhlib.MH(os.path.abspath(_mhpath), _mhprofile)
|
|
|
|
|
|
|
|
def sortLines(s):
|
|
|
|
lines = s.split("\n")
|
|
|
|
lines = [ line.strip() for line in lines if len(line) >= 2 ]
|
|
|
|
lines.sort()
|
|
|
|
return lines
|
|
|
|
|
|
|
|
# These next 2 functions are copied from test_glob.py.
|
|
|
|
def mkdirs(fname):
|
|
|
|
if os.path.exists(fname) or fname == '':
|
|
|
|
return
|
|
|
|
base, file = os.path.split(fname)
|
|
|
|
mkdirs(base)
|
|
|
|
os.mkdir(fname)
|
|
|
|
|
|
|
|
def deltree(fname):
|
|
|
|
if not os.path.exists(fname):
|
|
|
|
return
|
|
|
|
for f in os.listdir(fname):
|
|
|
|
fullname = os.path.join(fname, f)
|
|
|
|
if os.path.isdir(fullname):
|
|
|
|
deltree(fullname)
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
os.unlink(fullname)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
os.rmdir(fname)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
class MhlibTests(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
deltree(_mhroot)
|
|
|
|
mkdirs(_mhpath)
|
2001-08-09 18:40:30 -03:00
|
|
|
writeProfile({'Path' : os.path.abspath(_mhpath),
|
2001-08-09 15:18:08 -03:00
|
|
|
'Editor': 'emacs',
|
|
|
|
'ignored-attribute': 'camping holiday'})
|
|
|
|
# Note: These headers aren't really conformant to RFC822, but
|
|
|
|
# mhlib shouldn't care about that.
|
|
|
|
|
|
|
|
# An inbox with a couple of messages.
|
2001-08-09 18:40:30 -03:00
|
|
|
writeMessage('inbox', 1,
|
2001-08-09 15:18:08 -03:00
|
|
|
{'From': 'Mrs. Premise',
|
|
|
|
'To': 'Mrs. Conclusion',
|
|
|
|
'Date': '18 July 2001'}, "Hullo, Mrs. Conclusion!\n")
|
2001-08-09 18:40:30 -03:00
|
|
|
writeMessage('inbox', 2,
|
2001-08-09 15:18:08 -03:00
|
|
|
{'From': 'Mrs. Conclusion',
|
|
|
|
'To': 'Mrs. Premise',
|
|
|
|
'Date': '29 July 2001'}, "Hullo, Mrs. Premise!\n")
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
# A folder with many messages
|
2007-05-07 19:24:25 -03:00
|
|
|
for i in list(range(5, 101))+list(range(101, 201, 2)):
|
2001-08-09 18:40:30 -03:00
|
|
|
writeMessage('wide', i,
|
2001-08-09 15:18:08 -03:00
|
|
|
{'From': 'nowhere', 'Subject': 'message #%s' % i},
|
|
|
|
"This is message number %s\n" % i)
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
# A deeply nested folder
|
|
|
|
def deep(folder, n):
|
2001-08-09 18:40:30 -03:00
|
|
|
writeMessage(folder, n,
|
2001-08-09 15:18:08 -03:00
|
|
|
{'Subject': 'Message %s/%s' % (folder, n) },
|
|
|
|
"This is message number %s in %s\n" % (n, folder) )
|
|
|
|
deep('deep/f1', 1)
|
|
|
|
deep('deep/f1', 2)
|
|
|
|
deep('deep/f1', 3)
|
|
|
|
deep('deep/f2', 4)
|
|
|
|
deep('deep/f2', 6)
|
|
|
|
deep('deep', 3)
|
|
|
|
deep('deep/f2/f3', 1)
|
|
|
|
deep('deep/f2/f3', 2)
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
def tearDown(self):
|
|
|
|
deltree(_mhroot)
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
def test_basic(self):
|
|
|
|
writeContext('inbox')
|
|
|
|
writeCurMessage('inbox', 2)
|
|
|
|
mh = getMH()
|
|
|
|
|
|
|
|
eq = self.assertEquals
|
|
|
|
eq(mh.getprofile('Editor'), 'emacs')
|
|
|
|
eq(mh.getprofile('not-set'), None)
|
|
|
|
eq(mh.getpath(), os.path.abspath(_mhpath))
|
|
|
|
eq(mh.getcontext(), 'inbox')
|
|
|
|
|
|
|
|
mh.setcontext('wide')
|
|
|
|
eq(mh.getcontext(), 'wide')
|
|
|
|
eq(readFile(os.path.join(_mhpath, 'context')),
|
|
|
|
"Current-Folder: wide\n")
|
|
|
|
|
|
|
|
mh.setcontext('inbox')
|
|
|
|
|
|
|
|
inbox = mh.openfolder('inbox')
|
2001-08-09 18:40:30 -03:00
|
|
|
eq(inbox.getfullname(),
|
2001-08-09 15:18:08 -03:00
|
|
|
os.path.join(os.path.abspath(_mhpath), 'inbox'))
|
2001-08-09 18:40:30 -03:00
|
|
|
eq(inbox.getsequencesfilename(),
|
2001-08-09 15:18:08 -03:00
|
|
|
os.path.join(os.path.abspath(_mhpath), 'inbox', '.mh_sequences'))
|
2001-08-09 18:40:30 -03:00
|
|
|
eq(inbox.getmessagefilename(1),
|
2001-08-09 15:18:08 -03:00
|
|
|
os.path.join(os.path.abspath(_mhpath), 'inbox', '1'))
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
def test_listfolders(self):
|
|
|
|
mh = getMH()
|
|
|
|
eq = self.assertEquals
|
|
|
|
|
|
|
|
folders = mh.listfolders()
|
|
|
|
folders.sort()
|
|
|
|
eq(folders, ['deep', 'inbox', 'wide'])
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
folders = mh.listallfolders()
|
|
|
|
folders.sort()
|
Merged revisions 56125-56153 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
r56127 | georg.brandl | 2007-06-30 09:32:49 +0200 (Sat, 30 Jun 2007) | 2 lines
Fix a place where floor division would be in order.
........
r56135 | guido.van.rossum | 2007-07-01 06:13:54 +0200 (Sun, 01 Jul 2007) | 28 lines
Make map() and filter() identical to itertools.imap() and .ifilter(),
respectively.
I fixed two bootstrap issues, due to the dynamic import of itertools:
1. Starting python requires that map() and filter() are not used until
site.py has added build/lib.<arch> to sys.path.
2. Building python requires that setup.py and distutils and everything
they use is free of map() and filter() calls.
Beyond this, I only fixed the tests in test_builtin.py.
Others, please help fixing the remaining tests that are now broken!
The fixes are usually simple:
a. map(None, X) -> list(X)
b. map(F, X) -> list(map(F, X))
c. map(lambda x: F(x), X) -> [F(x) for x in X]
d. filter(F, X) -> list(filter(F, X))
e. filter(lambda x: P(x), X) -> [x for x in X if P(x)]
Someone, please also contribute a fixer for 2to3 to do this.
It can leave map()/filter() calls alone that are already
inside a list() or sorted() call or for-loop.
Only in rare cases have I seen code that depends on map() of lists
of different lengths going to the end of the longest, or on filter()
of a string or tuple returning an object of the same type; these
will need more thought to fix.
........
r56136 | guido.van.rossum | 2007-07-01 06:22:01 +0200 (Sun, 01 Jul 2007) | 3 lines
Make it so that test_decimal fails instead of hangs, to help automated
test runners.
........
r56139 | georg.brandl | 2007-07-01 18:20:58 +0200 (Sun, 01 Jul 2007) | 2 lines
Fix a few test cases after the map->imap change.
........
r56142 | neal.norwitz | 2007-07-02 06:38:12 +0200 (Mon, 02 Jul 2007) | 1 line
Get a bunch more tests passing after converting map/filter to return iterators.
........
r56147 | guido.van.rossum | 2007-07-02 15:32:02 +0200 (Mon, 02 Jul 2007) | 4 lines
Fix the remaining failing unit tests (at least on OSX).
Also tweaked urllib2 so it doesn't raise socket.gaierror when
all network interfaces are turned off.
........
2007-07-03 05:25:58 -03:00
|
|
|
tfolders = sorted(map(normF, ['deep', 'deep/f1', 'deep/f2',
|
|
|
|
'deep/f2/f3', 'inbox', 'wide']))
|
2001-08-11 20:22:43 -03:00
|
|
|
eq(folders, tfolders)
|
2001-08-09 15:18:08 -03:00
|
|
|
|
|
|
|
folders = mh.listsubfolders('deep')
|
|
|
|
folders.sort()
|
Merged revisions 56125-56153 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
r56127 | georg.brandl | 2007-06-30 09:32:49 +0200 (Sat, 30 Jun 2007) | 2 lines
Fix a place where floor division would be in order.
........
r56135 | guido.van.rossum | 2007-07-01 06:13:54 +0200 (Sun, 01 Jul 2007) | 28 lines
Make map() and filter() identical to itertools.imap() and .ifilter(),
respectively.
I fixed two bootstrap issues, due to the dynamic import of itertools:
1. Starting python requires that map() and filter() are not used until
site.py has added build/lib.<arch> to sys.path.
2. Building python requires that setup.py and distutils and everything
they use is free of map() and filter() calls.
Beyond this, I only fixed the tests in test_builtin.py.
Others, please help fixing the remaining tests that are now broken!
The fixes are usually simple:
a. map(None, X) -> list(X)
b. map(F, X) -> list(map(F, X))
c. map(lambda x: F(x), X) -> [F(x) for x in X]
d. filter(F, X) -> list(filter(F, X))
e. filter(lambda x: P(x), X) -> [x for x in X if P(x)]
Someone, please also contribute a fixer for 2to3 to do this.
It can leave map()/filter() calls alone that are already
inside a list() or sorted() call or for-loop.
Only in rare cases have I seen code that depends on map() of lists
of different lengths going to the end of the longest, or on filter()
of a string or tuple returning an object of the same type; these
will need more thought to fix.
........
r56136 | guido.van.rossum | 2007-07-01 06:22:01 +0200 (Sun, 01 Jul 2007) | 3 lines
Make it so that test_decimal fails instead of hangs, to help automated
test runners.
........
r56139 | georg.brandl | 2007-07-01 18:20:58 +0200 (Sun, 01 Jul 2007) | 2 lines
Fix a few test cases after the map->imap change.
........
r56142 | neal.norwitz | 2007-07-02 06:38:12 +0200 (Mon, 02 Jul 2007) | 1 line
Get a bunch more tests passing after converting map/filter to return iterators.
........
r56147 | guido.van.rossum | 2007-07-02 15:32:02 +0200 (Mon, 02 Jul 2007) | 4 lines
Fix the remaining failing unit tests (at least on OSX).
Also tweaked urllib2 so it doesn't raise socket.gaierror when
all network interfaces are turned off.
........
2007-07-03 05:25:58 -03:00
|
|
|
eq(folders, list(map(normF, ['deep/f1', 'deep/f2'])))
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
folders = mh.listallsubfolders('deep')
|
|
|
|
folders.sort()
|
Merged revisions 56125-56153 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
........
r56127 | georg.brandl | 2007-06-30 09:32:49 +0200 (Sat, 30 Jun 2007) | 2 lines
Fix a place where floor division would be in order.
........
r56135 | guido.van.rossum | 2007-07-01 06:13:54 +0200 (Sun, 01 Jul 2007) | 28 lines
Make map() and filter() identical to itertools.imap() and .ifilter(),
respectively.
I fixed two bootstrap issues, due to the dynamic import of itertools:
1. Starting python requires that map() and filter() are not used until
site.py has added build/lib.<arch> to sys.path.
2. Building python requires that setup.py and distutils and everything
they use is free of map() and filter() calls.
Beyond this, I only fixed the tests in test_builtin.py.
Others, please help fixing the remaining tests that are now broken!
The fixes are usually simple:
a. map(None, X) -> list(X)
b. map(F, X) -> list(map(F, X))
c. map(lambda x: F(x), X) -> [F(x) for x in X]
d. filter(F, X) -> list(filter(F, X))
e. filter(lambda x: P(x), X) -> [x for x in X if P(x)]
Someone, please also contribute a fixer for 2to3 to do this.
It can leave map()/filter() calls alone that are already
inside a list() or sorted() call or for-loop.
Only in rare cases have I seen code that depends on map() of lists
of different lengths going to the end of the longest, or on filter()
of a string or tuple returning an object of the same type; these
will need more thought to fix.
........
r56136 | guido.van.rossum | 2007-07-01 06:22:01 +0200 (Sun, 01 Jul 2007) | 3 lines
Make it so that test_decimal fails instead of hangs, to help automated
test runners.
........
r56139 | georg.brandl | 2007-07-01 18:20:58 +0200 (Sun, 01 Jul 2007) | 2 lines
Fix a few test cases after the map->imap change.
........
r56142 | neal.norwitz | 2007-07-02 06:38:12 +0200 (Mon, 02 Jul 2007) | 1 line
Get a bunch more tests passing after converting map/filter to return iterators.
........
r56147 | guido.van.rossum | 2007-07-02 15:32:02 +0200 (Mon, 02 Jul 2007) | 4 lines
Fix the remaining failing unit tests (at least on OSX).
Also tweaked urllib2 so it doesn't raise socket.gaierror when
all network interfaces are turned off.
........
2007-07-03 05:25:58 -03:00
|
|
|
eq(folders, list(map(normF, ['deep/f1', 'deep/f2', 'deep/f2/f3'])))
|
2001-08-09 15:18:08 -03:00
|
|
|
eq(mh.listsubfolders(normF('deep/f2')), [normF('deep/f2/f3')])
|
|
|
|
|
|
|
|
eq(mh.listsubfolders('inbox'), [])
|
|
|
|
eq(mh.listallsubfolders('inbox'), [])
|
|
|
|
|
|
|
|
def test_sequence(self):
|
|
|
|
mh = getMH()
|
|
|
|
eq = self.assertEquals
|
|
|
|
writeCurMessage('wide', 55)
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
f = mh.openfolder('wide')
|
|
|
|
all = f.listmessages()
|
2007-05-07 19:24:25 -03:00
|
|
|
eq(all, list(range(5, 101))+list(range(101, 201, 2)))
|
2001-08-09 15:18:08 -03:00
|
|
|
eq(f.getcurrent(), 55)
|
|
|
|
f.setcurrent(99)
|
2001-08-09 18:40:30 -03:00
|
|
|
eq(readFile(os.path.join(_mhpath, 'wide', '.mh_sequences')),
|
2001-08-09 15:18:08 -03:00
|
|
|
'cur: 99\n')
|
|
|
|
|
|
|
|
def seqeq(seq, val):
|
|
|
|
eq(f.parsesequence(seq), val)
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2007-05-07 19:24:25 -03:00
|
|
|
seqeq('5-55', list(range(5, 56)))
|
|
|
|
seqeq('90-108', list(range(90, 101))+list(range(101, 109, 2)))
|
|
|
|
seqeq('90-108', list(range(90, 101))+list(range(101, 109, 2)))
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2007-05-07 19:24:25 -03:00
|
|
|
seqeq('10:10', list(range(10, 20)))
|
|
|
|
seqeq('10:+10', list(range(10, 20)))
|
|
|
|
seqeq('101:10', list(range(101, 121, 2)))
|
2001-08-09 15:18:08 -03:00
|
|
|
|
|
|
|
seqeq('cur', [99])
|
|
|
|
seqeq('.', [99])
|
|
|
|
seqeq('prev', [98])
|
|
|
|
seqeq('next', [100])
|
|
|
|
seqeq('cur:-3', [97, 98, 99])
|
2007-05-07 19:24:25 -03:00
|
|
|
seqeq('first-cur', list(range(5, 100)))
|
|
|
|
seqeq('150-last', list(range(151, 201, 2)))
|
2001-08-09 15:18:08 -03:00
|
|
|
seqeq('prev-next', [98, 99, 100])
|
|
|
|
|
|
|
|
lowprimes = [5, 7, 11, 13, 17, 19, 23, 29]
|
|
|
|
lowcompos = [x for x in range(5, 31) if not x in lowprimes ]
|
|
|
|
f.putsequences({'cur': [5],
|
|
|
|
'lowprime': lowprimes,
|
|
|
|
'lowcompos': lowcompos})
|
|
|
|
seqs = readFile(os.path.join(_mhpath, 'wide', '.mh_sequences'))
|
|
|
|
seqs = sortLines(seqs)
|
|
|
|
eq(seqs, ["cur: 5",
|
|
|
|
"lowcompos: 6 8-10 12 14-16 18 20-22 24-28 30",
|
|
|
|
"lowprime: 5 7 11 13 17 19 23 29"])
|
|
|
|
|
|
|
|
seqeq('lowprime', lowprimes)
|
|
|
|
seqeq('lowprime:1', [5])
|
|
|
|
seqeq('lowprime:2', [5, 7])
|
|
|
|
seqeq('lowprime:-2', [23, 29])
|
|
|
|
|
|
|
|
## Not supported
|
|
|
|
#seqeq('lowprime:first', [5])
|
|
|
|
#seqeq('lowprime:last', [29])
|
|
|
|
#seqeq('lowprime:prev', [29])
|
|
|
|
#seqeq('lowprime:next', [29])
|
|
|
|
|
|
|
|
def test_modify(self):
|
|
|
|
mh = getMH()
|
|
|
|
eq = self.assertEquals
|
|
|
|
|
|
|
|
mh.makefolder("dummy1")
|
|
|
|
self.assert_("dummy1" in mh.listfolders())
|
|
|
|
path = os.path.join(_mhpath, "dummy1")
|
|
|
|
self.assert_(os.path.exists(path))
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
f = mh.openfolder('dummy1')
|
|
|
|
def create(n):
|
|
|
|
msg = "From: foo\nSubject: %s\n\nDummy Message %s\n" % (n,n)
|
|
|
|
f.createmessage(n, StringIO.StringIO(msg))
|
|
|
|
|
|
|
|
create(7)
|
|
|
|
create(8)
|
|
|
|
create(9)
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
eq(readFile(f.getmessagefilename(9)),
|
|
|
|
"From: foo\nSubject: 9\n\nDummy Message 9\n")
|
|
|
|
|
|
|
|
eq(f.listmessages(), [7, 8, 9])
|
|
|
|
files = os.listdir(path)
|
|
|
|
files.sort()
|
2001-08-09 18:40:30 -03:00
|
|
|
eq(files, ['7', '8', '9'])
|
2001-08-09 15:18:08 -03:00
|
|
|
|
|
|
|
f.removemessages(['7', '8'])
|
|
|
|
files = os.listdir(path)
|
|
|
|
files.sort()
|
|
|
|
eq(files, [',7', ',8', '9'])
|
|
|
|
eq(f.listmessages(), [9])
|
|
|
|
create(10)
|
|
|
|
create(11)
|
|
|
|
create(12)
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
mh.makefolder("dummy2")
|
|
|
|
f2 = mh.openfolder("dummy2")
|
|
|
|
eq(f2.listmessages(), [])
|
|
|
|
f.movemessage(10, f2, 3)
|
|
|
|
f.movemessage(11, f2, 5)
|
|
|
|
eq(f.listmessages(), [9, 12])
|
|
|
|
eq(f2.listmessages(), [3, 5])
|
|
|
|
eq(readFile(f2.getmessagefilename(3)),
|
|
|
|
"From: foo\nSubject: 10\n\nDummy Message 10\n")
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
f.copymessage(9, f2, 4)
|
|
|
|
eq(f.listmessages(), [9, 12])
|
|
|
|
eq(readFile(f2.getmessagefilename(4)),
|
|
|
|
"From: foo\nSubject: 9\n\nDummy Message 9\n")
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
f.refilemessages([9, 12], f2)
|
|
|
|
eq(f.listmessages(), [])
|
|
|
|
eq(f2.listmessages(), [3, 4, 5, 6, 7])
|
|
|
|
eq(readFile(f2.getmessagefilename(7)),
|
|
|
|
"From: foo\nSubject: 12\n\nDummy Message 12\n")
|
|
|
|
# XXX This should check that _copysequences does the right thing.
|
|
|
|
|
|
|
|
mh.deletefolder('dummy1')
|
|
|
|
mh.deletefolder('dummy2')
|
|
|
|
self.assert_('dummy1' not in mh.listfolders())
|
|
|
|
self.assert_(not os.path.exists(path))
|
|
|
|
|
|
|
|
def test_read(self):
|
|
|
|
mh = getMH()
|
|
|
|
eq = self.assertEquals
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
f = mh.openfolder('inbox')
|
|
|
|
msg = f.openmessage(1)
|
|
|
|
# Check some basic stuff from rfc822
|
|
|
|
eq(msg.getheader('From'), "Mrs. Premise")
|
|
|
|
eq(msg.getheader('To'), "Mrs. Conclusion")
|
|
|
|
|
|
|
|
# Okay, we have the right message. Let's check the stuff from
|
|
|
|
# mhlib.
|
|
|
|
lines = sortLines(msg.getheadertext())
|
2001-08-09 18:40:30 -03:00
|
|
|
eq(lines, ["Date: 18 July 2001",
|
2001-08-09 15:18:08 -03:00
|
|
|
"From: Mrs. Premise",
|
|
|
|
"To: Mrs. Conclusion"])
|
|
|
|
lines = sortLines(msg.getheadertext(lambda h: len(h)==4))
|
2001-08-09 18:40:30 -03:00
|
|
|
eq(lines, ["Date: 18 July 2001",
|
2001-08-09 15:18:08 -03:00
|
|
|
"From: Mrs. Premise"])
|
|
|
|
eq(msg.getbodytext(), "Hullo, Mrs. Conclusion!\n\n")
|
|
|
|
eq(msg.getbodytext(0), "Hullo, Mrs. Conclusion!\n\n")
|
2001-08-09 18:40:30 -03:00
|
|
|
|
2001-08-09 15:18:08 -03:00
|
|
|
# XXXX there should be a better way to reclaim the file handle
|
|
|
|
msg.fp.close()
|
|
|
|
del msg
|
|
|
|
|
2001-09-20 18:33:42 -03:00
|
|
|
|
|
|
|
def test_main():
|
|
|
|
run_unittest(MhlibTests)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|