1
# Copyright 2005-2011 Canonical Ltd. All rights reserved.
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (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 Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
from django.test.simple import DjangoTestSuiteRunner
27
doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS |doctest.REPORT_NDIFF)
29
class CustomTestRunner(DjangoTestSuiteRunner):
31
def __init__(self, verbosity=3, interactive=False, failfast=True):
32
super(CustomTestRunner, self).__init__(verbosity=verbosity,
33
interactive=interactive, failfast=failfast)
35
def build_suite(self, test_labels, extra_tests=None, **kwargs):
36
# XXX: matsubara 2010-02-19 bug 524440: Adding a sort here to
37
# guarantee we'll have the doctests in the same order. Ideally tests
38
# should be contained and not need to be run on a specific order.
39
doctests = sorted(glob(path.join(path.dirname(__file__), '*.txt')))
40
filtered_doctests = set([])
41
for label in test_labels:
42
# regular expression match.
43
test_name = re.compile(label)
44
filtered_doctests.update(filter(test_name.search, doctests))
45
# XXX: According to Python Library Reference:
46
# Changed in version 2.5: The global __file__ was added to the
47
# globals provided to doctests loaded from a text file using
48
# DocFileSuite(). This is a hack to make tests work on 2.4
49
globs = {'__file__': __file__}
50
filtered_doctests = sorted(list(filtered_doctests))
51
suite = doctest.DocFileSuite(module_relative=False,
52
optionflags=DEFAULT_OPTIONS, globs=globs,
55
# Add the unit tests as well.
57
glob(path.join(path.dirname(__file__), 'test_*.py')))
58
unittests = filter(lambda x: x != __file__, unittests)
59
for test in unittests:
60
mod_name, ext = os.path.splitext(os.path.basename(test))
61
mod_data = imp.find_module(mod_name, [os.path.dirname(test)])
62
test_module = imp.load_module(mod_name, *mod_data)
64
unittest.defaultTestLoader.loadTestsFromModule(test_module))