~launchpad-pqm/launchpad/devel

8687.15.18 by Karl Fogel
Add the copyright header block to files under lib/canonical/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
3
6493.7.4 by Barry Warsaw
Refactor the launchpadlib test shim so that it'll be easy to use it for the
4
"""Run the standalone tests in an opensource package.
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
5
6286.2.7 by Barry Warsaw
Review changes.
6
XXX BarryWarsaw 14-May-2008: This shim is here so that the tests within the
6493.7.4 by Barry Warsaw
Refactor the launchpadlib test shim so that it'll be easy to use it for the
7
launchpadlib and wadllib packages (living in the opensource directory) will
8
run as part of Launchpad's standard test suite.  Those tests cannot yet be run
9
on their own, since they require a running Launchpad appserver, but not the
10
real Launchpad!.  Eventually, there will be mock objects in the packages' test
11
suites so that they can be run on their own outside the Launchpad development
12
environment.
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
13
"""
14
15
__metaclass__ = type
6286.2.5 by Barry Warsaw
__all__
16
__all__ = ['test_suite']
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
17
18
8777.2.7 by Francis J. Lacoste
Silence lazr.smtptest when running launchpadlib tests.
19
import logging
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
20
import os
21
import unittest
6527.6.3 by Barry Warsaw
Complete refactoring of test_launchpadlib.py, test_wadllib.py and
22
11403.1.4 by Henning Eggers
Reformatted imports using format-imports script r32.
23
import launchpadlib
6527.6.3 by Barry Warsaw
Complete refactoring of test_launchpadlib.py, test_wadllib.py and
24
import wadllib
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
25
14604.1.1 by Curtis Hovey
Separate test-authoring classes from test-running classes.
26
from lp.testing.layers import AppServerLayer
14578.4.1 by William Grant
Move the remains of canonical.launchpad.testing to lp.testing.
27
from lp.testing.systemdocs import LayeredDocFileSuite
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
28
6493.7.4 by Barry Warsaw
Refactor the launchpadlib test shim so that it'll be easy to use it for the
29
30
def add_testable_opensource_package(suite, package):
31
    """Sniff out all the doctests in `package` and add them to `suite`."""
32
    topdir = os.path.dirname(package.__file__)
33
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
34
    packages = []
35
    for dirpath, dirnames, filenames in os.walk(topdir):
36
        if 'docs' in dirnames:
37
            docsdir = os.path.join(dirpath, 'docs')[len(topdir)+1:]
38
            packages.append(docsdir)
39
    doctest_files = {}
40
    for docsdir in packages:
41
        for filename in os.listdir(os.path.join(topdir, docsdir)):
42
            if os.path.splitext(filename)[1] == '.txt':
43
                doctest_files[filename] = os.path.join(docsdir, filename)
44
    # Sort the tests.
45
    for filename in sorted(doctest_files):
46
        path = doctest_files[filename]
6493.7.4 by Barry Warsaw
Refactor the launchpadlib test shim so that it'll be easy to use it for the
47
        doctest = LayeredDocFileSuite(
8777.2.7 by Francis J. Lacoste
Silence lazr.smtptest when running launchpadlib tests.
48
            path, package=package, layer=AppServerLayer,
49
            stdout_logging_level=logging.WARNING)
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
50
        suite.addTest(doctest)
51
6493.7.4 by Barry Warsaw
Refactor the launchpadlib test shim so that it'll be easy to use it for the
52
53
def test_suite():
54
    suite = unittest.TestSuite()
55
    add_testable_opensource_package(suite, launchpadlib)
6527.6.3 by Barry Warsaw
Complete refactoring of test_launchpadlib.py, test_wadllib.py and
56
    add_testable_opensource_package(suite, wadllib)
6286.2.3 by Barry Warsaw
Add a minimal harness for running the launchpadlib doctests. For now, this
57
    return suite