1
# Copyright (C) 2008-2012 Canonical, Ltd.
3
# This program is free software: you can redistribute it and/or modify it
4
# under the terms of the GNU General Public License as published by the Free
5
# Software Foundation, version 3 of the License.
7
# This program is distributed in the hope that it will be useful, but WITHOUT
8
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
# You should have received a copy of the GNU General Public License along with
13
# this program. If not, see <http://www.gnu.org/licenses/>.
16
"""Test harness for doctests."""
18
from __future__ import absolute_import, print_function, unicode_literals
31
from pkg_resources import (
32
resource_filename, resource_exists, resource_listdir, cleanup_resources)
39
doctest.NORMALIZE_WHITESPACE |
40
doctest.REPORT_NDIFF |
41
doctest.IGNORE_EXCEPTION_DETAIL)
44
WHOAMI = 'janitor.plugincore'
49
"""Call into pdb.set_trace()"""
50
# Do the import here so that you get the wacky special hacked pdb instead
51
# of Python's normal pdb.
59
# Make sure future statements in our doctests match the Python code.
61
testobj.globs['absolute_import'] = absolute_import
62
testobj.globs['print_function'] = print_function
63
testobj.globs['unicode_literals'] = unicode_literals
66
testobj.globs['stop'] = stop
67
testobj.globs['cleanups'] = []
70
def teardown(testobj):
71
for cleanup in testobj.globs['cleanups']:
76
def additional_tests():
77
"Run the doc tests (README.rst and docs/*, if any exist)"
79
## os.path.abspath(resource_filename(WHOAMI, 'README.rst')),
81
if resource_exists(WHOAMI, 'docs'):
82
for name in resource_listdir(WHOAMI, 'docs'):
83
if name.endswith('.rst'):
86
resource_filename(WHOAMI, 'docs/%s' % name)))
87
kwargs = dict(module_relative=False,
88
optionflags=DOCTEST_FLAGS,
89
setUp=setup, tearDown=teardown,
91
atexit.register(cleanup_resources)
92
return unittest.TestSuite((
93
doctest.DocFileSuite(*doctest_files, **kwargs)))