~launchpad-pqm/launchpad/devel

9492.1.1 by Karl Fogel
Add utilities/formatdoctest.py and utilities/migrater/, both brought
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""
5
Run the doctests and pagetests.
6
"""
7
8
import logging
9
import os
10
import unittest
11
12
from canonical.database.sqlbase import flush_database_updates
13
from canonical.launchpad.testing.pages import PageTestSuite
14
from canonical.launchpad.testing.systemdocs import (
15
    LayeredDocFileSuite, setUp, tearDown)
16
from canonical.testing import (
17
    DatabaseFunctionalLayer, DatabaseLayer, LaunchpadFunctionalLayer,
18
    LaunchpadZopelessLayer)
19
from lp.registry.tests import mailinglists_helper
20
21
22
here = os.path.dirname(os.path.realpath(__file__))
23
24
25
special = {}
26
27
28
def test_suite():
29
    suite = unittest.TestSuite()
30
31
    stories_dir = os.path.join(os.path.pardir, 'stories')
32
    suite.addTest(PageTestSuite(stories_dir))
33
    stories_path = os.path.join(here, stories_dir)
34
    for story_dir in os.listdir(stories_path):
35
        full_story_dir = os.path.join(stories_path, story_dir)
36
        if not os.path.isdir(full_story_dir):
37
            continue
38
        story_path = os.path.join(stories_dir, story_dir)
39
        suite.addTest(PageTestSuite(story_path))
40
41
    testsdir = os.path.abspath(
42
        os.path.normpath(os.path.join(here, os.path.pardir, 'doc'))
43
        )
44
45
    # Add special needs tests
46
    for key in sorted(special):
47
        special_suite = special[key]
48
        suite.addTest(special_suite)
49
50
    # Add tests using default setup/teardown
51
    filenames = [filename
52
                 for filename in os.listdir(testsdir)
53
                 if filename.endswith('.txt') and filename not in special]
54
    # Sort the list to give a predictable order.
55
    filenames.sort()
56
    for filename in filenames:
57
        path = os.path.join('../doc/', filename)
58
        one_test = LayeredDocFileSuite(
59
            path, setUp=setUp, tearDown=tearDown,
60
            layer=LaunchpadFunctionalLayer,
61
            stdout_logging_level=logging.WARNING
62
            )
63
        suite.addTest(one_test)
64
65
    return suite