1 # Copyright (C) 2007 by the Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 """Harness for testing Mailman's documentation."""
25 from email
import message_from_string
29 from Mailman
.Message
import Message
30 from Mailman
.app
.styles
import style_manager
31 from Mailman
.configuration
import config
38 def specialized_message_from_string(text
):
39 return message_from_string(text
, Message
)
43 """Set up some things for convenience."""
44 testobj
.globs
['config'] = config
45 testobj
.globs
['message_from_string'] = specialized_message_from_string
49 def cleaning_teardown(testobj
):
50 """Clear all persistent data at the end of a doctest."""
51 # Clear the database of all rows.
53 # Remove all but the default style.
54 for style
in style_manager
.styles
:
55 if style
.name
<> 'default':
56 style_manager
.unregister(style
)
57 # Remove all queue files.
58 for dirpath
, dirnames
, filenames
in os
.walk(config
.QUEUE_DIR
):
59 for filename
in filenames
:
60 os
.remove(os
.path
.join(dirpath
, filename
))
61 # Clear out messages in the message store directory.
62 for dirpath
, dirnames
, filenames
in os
.walk(config
.MESSAGES_DIR
):
63 for filename
in filenames
:
64 os
.remove(os
.path
.join(dirpath
, filename
))
69 suite
= unittest
.TestSuite()
70 docsdir
= os
.path
.join(os
.path
.dirname(Mailman
.__file
__), 'docs')
71 # Under higher verbosity settings, report all doctest errors, not just the
73 flags
= (doctest
.ELLIPSIS |
74 doctest
.NORMALIZE_WHITESPACE |
76 if config
.opts
.verbosity
<= 2:
77 flags |
= doctest
.REPORT_ONLY_FIRST_FAILURE
78 for filename
in os
.listdir(docsdir
):
79 if os
.path
.splitext(filename
)[1] == '.txt':
80 test
= doctest
.DocFileSuite(
85 tearDown
=cleaning_teardown
)