Fix two doctests: addresses.txt and mlist-addresses.txt
[mailman.git] / Mailman / tests / test_documentation.py
blob575d8e6bddec8cd4e372fb2cf494cf1367ee098c
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,
16 # USA.
18 """Harness for testing Mailman's documentation."""
20 import os
21 import pdb
22 import doctest
23 import unittest
25 from email import message_from_string
27 import Mailman
29 from Mailman.Message import Message
30 from Mailman.app.styles import style_manager
31 from Mailman.configuration import config
34 COMMASPACE = ', '
38 def specialized_message_from_string(text):
39 return message_from_string(text, Message)
42 def setup(testobj):
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.
52 config.db._reset()
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))
68 def test_suite():
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
72 # first one.
73 flags = (doctest.ELLIPSIS |
74 doctest.NORMALIZE_WHITESPACE |
75 doctest.REPORT_NDIFF)
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(
81 'docs/' + filename,
82 package=Mailman,
83 optionflags=flags,
84 setUp=setup,
85 tearDown=cleaning_teardown)
86 suite.addTest(test)
87 return suite