~barry/mailman/templatecache

« back to all changes in this revision

Viewing changes to src/mailman/testing/documentation.py

  • Committer: Barry Warsaw
  • Date: 2013-09-01 15:12:51 UTC
  • mfrom: (7184.1.37 3.0)
  • Revision ID: barry@list.org-20130901151251-1jmdsqmvbq1lxxxo
trunk merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
__metaclass__ = type
27
27
__all__ = [
28
 
    'test_suite',
 
28
    'setup',
 
29
    'teardown'
29
30
    ]
30
31
 
31
32
 
32
 
import os
33
 
import sys
34
 
import doctest
35
 
import unittest
36
 
 
37
33
from inspect import isfunction, ismethod
38
34
 
39
 
import mailman
40
 
 
41
35
from mailman.app.lifecycle import create_list
42
36
from mailman.config import config
43
 
from mailman.testing.helpers import (
44
 
    call_api, chdir, specialized_message_from_string)
 
37
from mailman.testing.helpers import call_api, specialized_message_from_string
45
38
from mailman.testing.layers import SMTPLayer
46
39
 
47
40
 
181
174
            cleanup()
182
175
        else:
183
176
            cleanup[0](*cleanup[1:])
184
 
 
185
 
 
186
 
 
187
 
def test_suite():
188
 
    """Create test suites for all .rst documentation tests.
189
 
 
190
 
    .txt files are also tested, but .rst is highly preferred.
191
 
    """
192
 
    suite = unittest.TestSuite()
193
 
    topdir = os.path.dirname(mailman.__file__)
194
 
    packages = []
195
 
    for dirpath, dirnames, filenames in os.walk(topdir):
196
 
        if 'docs' in dirnames:
197
 
            docsdir = os.path.join(dirpath, 'docs')[len(topdir)+1:]
198
 
            packages.append(docsdir)
199
 
    # Under higher verbosity settings, report all doctest errors, not just the
200
 
    # first one.
201
 
    flags = (doctest.ELLIPSIS |
202
 
             doctest.NORMALIZE_WHITESPACE |
203
 
             doctest.REPORT_NDIFF)
204
 
    # Add all the doctests in all subpackages.
205
 
    doctest_files = {}
206
 
    with chdir(topdir):
207
 
        for docsdir in packages:
208
 
            # Look to see if the package defines a test layer, otherwise use
209
 
            # SMTPLayer.
210
 
            package_path = 'mailman.' + DOT.join(docsdir.split(os.sep))
211
 
            try:
212
 
                __import__(package_path)
213
 
            except ImportError:
214
 
                layer = SMTPLayer
215
 
            else:
216
 
                layer = getattr(sys.modules[package_path], 'layer', SMTPLayer)
217
 
            for filename in os.listdir(docsdir):
218
 
                base, extension = os.path.splitext(filename)
219
 
                if os.path.splitext(filename)[1] in ('.txt', '.rst'):
220
 
                    module_path = package_path + '.' + base
221
 
                    doctest_files[module_path] = (
222
 
                        os.path.join(docsdir, filename), layer)
223
 
    for module_path in sorted(doctest_files):
224
 
        path, layer = doctest_files[module_path]
225
 
        test = doctest.DocFileSuite(
226
 
            path,
227
 
            package='mailman',
228
 
            optionflags=flags,
229
 
            setUp=setup,
230
 
            tearDown=teardown)
231
 
        test.layer = layer
232
 
        suite.addTest(test)
233
 
    return suite