annotate Lib/test/test_mhlib.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 614c84670c63
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 """
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 Tests for the mhlib module
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 Nick Mathewson
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 """
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 ### BUG: This suite doesn't currently test the mime functionality of
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 ### mhlib. It should.
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 import unittest
52355
228cfb6e2900 fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 52353
diff changeset
10 from test.test_support import run_unittest, TESTFN, import_module
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 import os, StringIO
19118
91299418b72d Skip test_mhlib on Windows -- too many Unix assumptions.
Tim Peters <tim.peters@gmail.com>
parents: 19106
diff changeset
12 import sys
46858
2cac31fc17c2 Deprecated the mhlib module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 24556
diff changeset
13 mhlib = import_module('mhlib', deprecated=True)
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
24554
df4a9d3abc56 Finally got around to figuring out and documenting why this test fails
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
15 if (sys.platform.startswith("win") or sys.platform=="riscos" or
24555
5d6e470ce05c Oops! Forgot the closing paren.
Tim Peters <tim.peters@gmail.com>
parents: 24554
diff changeset
16 sys.platform.startswith("atheos")):
24554
df4a9d3abc56 Finally got around to figuring out and documenting why this test fails
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
17 # mhlib.updateline() renames a file to the name of a file that already
df4a9d3abc56 Finally got around to figuring out and documenting why this test fails
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
18 # exists. That causes a reasonable OS <wink> to complain in test_sequence
df4a9d3abc56 Finally got around to figuring out and documenting why this test fails
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
19 # here, like the "OSError: [Errno 17] File exists" raised on Windows.
df4a9d3abc56 Finally got around to figuring out and documenting why this test fails
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
20 # mhlib's listsubfolders() and listallfolders() do something with
df4a9d3abc56 Finally got around to figuring out and documenting why this test fails
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
21 # link counts, and that causes test_listfolders() here to get back
df4a9d3abc56 Finally got around to figuring out and documenting why this test fails
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
22 # an empty list from its call of listallfolders().
df4a9d3abc56 Finally got around to figuring out and documenting why this test fails
Tim Peters <tim.peters@gmail.com>
parents: 24364
diff changeset
23 # The other tests here pass on Windows.
52355
228cfb6e2900 fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 52353
diff changeset
24 raise unittest.SkipTest("skipped on %s -- " % sys.platform +
228cfb6e2900 fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents: 52353
diff changeset
25 "too many Unix assumptions")
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 _mhroot = TESTFN+"_MH"
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 _mhpath = os.path.join(_mhroot, "MH")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 _mhprofile = os.path.join(_mhroot, ".mh_profile")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 def normF(f):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 return os.path.join(*f.split('/'))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 def writeFile(fname, contents):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 dir = os.path.split(fname)[0]
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 if dir and not os.path.exists(dir):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 mkdirs(dir)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 f = open(fname, 'w')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 f.write(contents)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 f.close()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 def readFile(fname):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 f = open(fname)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 r = f.read()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 f.close()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 return r
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 def writeProfile(dict):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 contents = [ "%s: %s\n" % (k, v) for k, v in dict.iteritems() ]
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 writeFile(_mhprofile, "".join(contents))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 def writeContext(folder):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 folder = normF(folder)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
54 writeFile(os.path.join(_mhpath, "context"),
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 "Current-Folder: %s\n" % folder)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 def writeCurMessage(folder, cur):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 folder = normF(folder)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 writeFile(os.path.join(_mhpath, folder, ".mh_sequences"),
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 "cur: %s\n"%cur)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 def writeMessage(folder, n, headers, body):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 folder = normF(folder)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 headers = "".join([ "%s: %s\n" % (k, v) for k, v in headers.iteritems() ])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 contents = "%s\n%s\n" % (headers,body)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 mkdirs(os.path.join(_mhpath, folder))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 writeFile(os.path.join(_mhpath, folder, str(n)), contents)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
68
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 def getMH():
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 return mhlib.MH(os.path.abspath(_mhpath), _mhprofile)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
71
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 def sortLines(s):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 lines = s.split("\n")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 lines = [ line.strip() for line in lines if len(line) >= 2 ]
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 lines.sort()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 return lines
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
77
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 # These next 2 functions are copied from test_glob.py.
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 def mkdirs(fname):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 if os.path.exists(fname) or fname == '':
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 return
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 base, file = os.path.split(fname)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 mkdirs(base)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 os.mkdir(fname)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
85
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 def deltree(fname):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 if not os.path.exists(fname):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 return
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 for f in os.listdir(fname):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 fullname = os.path.join(fname, f)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 if os.path.isdir(fullname):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 deltree(fullname)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 else:
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 try:
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 os.unlink(fullname)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 except:
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 pass
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 try:
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 os.rmdir(fname)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 except:
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 pass
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 class MhlibTests(unittest.TestCase):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 def setUp(self):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 deltree(_mhroot)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 mkdirs(_mhpath)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
107 writeProfile({'Path' : os.path.abspath(_mhpath),
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 'Editor': 'emacs',
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 'ignored-attribute': 'camping holiday'})
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 # Note: These headers aren't really conformant to RFC822, but
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 # mhlib shouldn't care about that.
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 # An inbox with a couple of messages.
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
114 writeMessage('inbox', 1,
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 {'From': 'Mrs. Premise',
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 'To': 'Mrs. Conclusion',
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 'Date': '18 July 2001'}, "Hullo, Mrs. Conclusion!\n")
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
118 writeMessage('inbox', 2,
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 {'From': 'Mrs. Conclusion',
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 'To': 'Mrs. Premise',
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 'Date': '29 July 2001'}, "Hullo, Mrs. Premise!\n")
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
122
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 # A folder with many messages
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 for i in range(5, 101)+range(101, 201, 2):
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
125 writeMessage('wide', i,
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 {'From': 'nowhere', 'Subject': 'message #%s' % i},
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 "This is message number %s\n" % i)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
128
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 # A deeply nested folder
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 def deep(folder, n):
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
131 writeMessage(folder, n,
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 {'Subject': 'Message %s/%s' % (folder, n) },
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 "This is message number %s in %s\n" % (n, folder) )
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 deep('deep/f1', 1)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 deep('deep/f1', 2)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 deep('deep/f1', 3)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 deep('deep/f2', 4)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 deep('deep/f2', 6)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 deep('deep', 3)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 deep('deep/f2/f3', 1)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 deep('deep/f2/f3', 2)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
142
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 def tearDown(self):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 deltree(_mhroot)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
145
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 def test_basic(self):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 writeContext('inbox')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 writeCurMessage('inbox', 2)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 mh = getMH()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
150
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
151 eq = self.assertEqual
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 eq(mh.getprofile('Editor'), 'emacs')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 eq(mh.getprofile('not-set'), None)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 eq(mh.getpath(), os.path.abspath(_mhpath))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 eq(mh.getcontext(), 'inbox')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 mh.setcontext('wide')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 eq(mh.getcontext(), 'wide')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 eq(readFile(os.path.join(_mhpath, 'context')),
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 "Current-Folder: wide\n")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 mh.setcontext('inbox')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 inbox = mh.openfolder('inbox')
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
165 eq(inbox.getfullname(),
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 os.path.join(os.path.abspath(_mhpath), 'inbox'))
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
167 eq(inbox.getsequencesfilename(),
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 os.path.join(os.path.abspath(_mhpath), 'inbox', '.mh_sequences'))
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
169 eq(inbox.getmessagefilename(1),
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 os.path.join(os.path.abspath(_mhpath), 'inbox', '1'))
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
171
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 def test_listfolders(self):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 mh = getMH()
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
174 eq = self.assertEqual
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 folders = mh.listfolders()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 folders.sort()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 eq(folders, ['deep', 'inbox', 'wide'])
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
179
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 folders = mh.listallfolders()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 folders.sort()
19182
fc39c22b5a7a The test assumed that the local pathname convention for "foo" would sort before "foo/bar", which is not true on the mac (where they are "foo" and ":foo:bar", respectively; ":foo" would be fine too, but "foo" is the preferred spelling). Fixed by sorting the output.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19119
diff changeset
182 tfolders = map(normF, ['deep', 'deep/f1', 'deep/f2', 'deep/f2/f3',
fc39c22b5a7a The test assumed that the local pathname convention for "foo" would sort before "foo/bar", which is not true on the mac (where they are "foo" and ":foo:bar", respectively; ":foo" would be fine too, but "foo" is the preferred spelling). Fixed by sorting the output.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19119
diff changeset
183 'inbox', 'wide'])
fc39c22b5a7a The test assumed that the local pathname convention for "foo" would sort before "foo/bar", which is not true on the mac (where they are "foo" and ":foo:bar", respectively; ":foo" would be fine too, but "foo" is the preferred spelling). Fixed by sorting the output.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19119
diff changeset
184 tfolders.sort()
fc39c22b5a7a The test assumed that the local pathname convention for "foo" would sort before "foo/bar", which is not true on the mac (where they are "foo" and ":foo:bar", respectively; ":foo" would be fine too, but "foo" is the preferred spelling). Fixed by sorting the output.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19119
diff changeset
185 eq(folders, tfolders)
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
186
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 folders = mh.listsubfolders('deep')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 folders.sort()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 eq(folders, map(normF, ['deep/f1', 'deep/f2']))
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
190
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 folders = mh.listallsubfolders('deep')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 folders.sort()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 eq(folders, map(normF, ['deep/f1', 'deep/f2', 'deep/f2/f3']))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 eq(mh.listsubfolders(normF('deep/f2')), [normF('deep/f2/f3')])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
195
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 eq(mh.listsubfolders('inbox'), [])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 eq(mh.listallsubfolders('inbox'), [])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 def test_sequence(self):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 mh = getMH()
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
201 eq = self.assertEqual
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 writeCurMessage('wide', 55)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
203
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 f = mh.openfolder('wide')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 all = f.listmessages()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 eq(all, range(5, 101)+range(101, 201, 2))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 eq(f.getcurrent(), 55)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 f.setcurrent(99)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
209 eq(readFile(os.path.join(_mhpath, 'wide', '.mh_sequences')),
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 'cur: 99\n')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
211
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 def seqeq(seq, val):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 eq(f.parsesequence(seq), val)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
214
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 seqeq('5-55', range(5, 56))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 seqeq('90-108', range(90, 101)+range(101, 109, 2))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 seqeq('90-108', range(90, 101)+range(101, 109, 2))
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
218
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 seqeq('10:10', range(10, 20))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 seqeq('10:+10', range(10, 20))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 seqeq('101:10', range(101, 121, 2))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
222
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 seqeq('cur', [99])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 seqeq('.', [99])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 seqeq('prev', [98])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 seqeq('next', [100])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 seqeq('cur:-3', [97, 98, 99])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 seqeq('first-cur', range(5, 100))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 seqeq('150-last', range(151, 201, 2))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 seqeq('prev-next', [98, 99, 100])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
231
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 lowprimes = [5, 7, 11, 13, 17, 19, 23, 29]
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 lowcompos = [x for x in range(5, 31) if not x in lowprimes ]
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 f.putsequences({'cur': [5],
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 'lowprime': lowprimes,
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 'lowcompos': lowcompos})
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 seqs = readFile(os.path.join(_mhpath, 'wide', '.mh_sequences'))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 seqs = sortLines(seqs)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 eq(seqs, ["cur: 5",
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 "lowcompos: 6 8-10 12 14-16 18 20-22 24-28 30",
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 "lowprime: 5 7 11 13 17 19 23 29"])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
242
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 seqeq('lowprime', lowprimes)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 seqeq('lowprime:1', [5])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 seqeq('lowprime:2', [5, 7])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 seqeq('lowprime:-2', [23, 29])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
247
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 ## Not supported
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 #seqeq('lowprime:first', [5])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 #seqeq('lowprime:last', [29])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 #seqeq('lowprime:prev', [29])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 #seqeq('lowprime:next', [29])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
253
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 def test_modify(self):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 mh = getMH()
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
256 eq = self.assertEqual
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
257
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 mh.makefolder("dummy1")
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 55002
diff changeset
259 self.assertIn("dummy1", mh.listfolders())
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 path = os.path.join(_mhpath, "dummy1")
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 52355
diff changeset
261 self.assertTrue(os.path.exists(path))
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
262
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 f = mh.openfolder('dummy1')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 def create(n):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 msg = "From: foo\nSubject: %s\n\nDummy Message %s\n" % (n,n)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 f.createmessage(n, StringIO.StringIO(msg))
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
267
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 create(7)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 create(8)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 create(9)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
271
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 eq(readFile(f.getmessagefilename(9)),
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 "From: foo\nSubject: 9\n\nDummy Message 9\n")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
274
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 eq(f.listmessages(), [7, 8, 9])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 files = os.listdir(path)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 files.sort()
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
278 eq(files, ['7', '8', '9'])
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
279
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 f.removemessages(['7', '8'])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 files = os.listdir(path)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 files.sort()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 eq(files, [',7', ',8', '9'])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 eq(f.listmessages(), [9])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 create(10)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 create(11)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 create(12)
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
288
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 mh.makefolder("dummy2")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 f2 = mh.openfolder("dummy2")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 eq(f2.listmessages(), [])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 f.movemessage(10, f2, 3)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 f.movemessage(11, f2, 5)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 eq(f.listmessages(), [9, 12])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 eq(f2.listmessages(), [3, 5])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 eq(readFile(f2.getmessagefilename(3)),
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 "From: foo\nSubject: 10\n\nDummy Message 10\n")
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
298
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 f.copymessage(9, f2, 4)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 eq(f.listmessages(), [9, 12])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 eq(readFile(f2.getmessagefilename(4)),
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 "From: foo\nSubject: 9\n\nDummy Message 9\n")
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
303
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 f.refilemessages([9, 12], f2)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 eq(f.listmessages(), [])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 eq(f2.listmessages(), [3, 4, 5, 6, 7])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 eq(readFile(f2.getmessagefilename(7)),
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 "From: foo\nSubject: 12\n\nDummy Message 12\n")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 # XXX This should check that _copysequences does the right thing.
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
310
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 mh.deletefolder('dummy1')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 mh.deletefolder('dummy2')
58460
17891566a478 use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents: 55002
diff changeset
313 self.assertNotIn('dummy1', mh.listfolders())
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 52355
diff changeset
314 self.assertTrue(not os.path.exists(path))
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
315
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 def test_read(self):
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 mh = getMH()
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 58460
diff changeset
318 eq = self.assertEqual
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
319
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 f = mh.openfolder('inbox')
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 msg = f.openmessage(1)
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 # Check some basic stuff from rfc822
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 eq(msg.getheader('From'), "Mrs. Premise")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 eq(msg.getheader('To'), "Mrs. Conclusion")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
325
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 # Okay, we have the right message. Let's check the stuff from
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 # mhlib.
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 lines = sortLines(msg.getheadertext())
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
329 eq(lines, ["Date: 18 July 2001",
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 "From: Mrs. Premise",
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 "To: Mrs. Conclusion"])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 lines = sortLines(msg.getheadertext(lambda h: len(h)==4))
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
333 eq(lines, ["Date: 18 July 2001",
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 "From: Mrs. Premise"])
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 eq(msg.getbodytext(), "Hullo, Mrs. Conclusion!\n\n")
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 eq(msg.getbodytext(0), "Hullo, Mrs. Conclusion!\n\n")
19119
600a9a2b7a18 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 19118
diff changeset
337
19106
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 # XXXX there should be a better way to reclaim the file handle
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 msg.fp.close()
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 del msg
10ec3968428d Unittests for mhlib, by Nick Mathewson.
Guido van Rossum <guido@python.org>
parents:
diff changeset
341
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19182
diff changeset
342
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19182
diff changeset
343 def test_main():
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19182
diff changeset
344 run_unittest(MhlibTests)
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19182
diff changeset
345
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19182
diff changeset
346
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19182
diff changeset
347 if __name__ == "__main__":
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19182
diff changeset
348 test_main()