~lazr-developers/lazr.authentication/trunk

« back to all changes in this revision

Viewing changes to src/lazr/authentication/tests/test_docs.py

  • Committer: Jürgen Gmach
  • Date: 2021-11-05 14:27:41 UTC
  • Revision ID: juergen.gmach@canonical.com-20211105142741-crqrjqm3dhkcy9wd
Moved to git

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009 Canonical Ltd.  All rights reserved.
2
 
#
3
 
# This file is part of lazr.authentication
4
 
#
5
 
# lazr.authentication is free software: you can redistribute it and/or modify it
6
 
# under the terms of the GNU Lesser General Public License as published by
7
 
# the Free Software Foundation, version 3 of the License.
8
 
#
9
 
# lazr.authentication is distributed in the hope that it will be useful, but
10
 
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
12
 
# License for more details.
13
 
#
14
 
# You should have received a copy of the GNU Lesser General Public License
15
 
# along with lazr.authentication.  If not, see <http://www.gnu.org/licenses/>.
16
 
"Test harness for doctests."
17
 
 
18
 
# pylint: disable=E0611
19
 
 
20
 
__metaclass__ = type
21
 
__all__ = [
22
 
    'load_tests',
23
 
    ]
24
 
 
25
 
import atexit
26
 
import doctest
27
 
import os
28
 
 
29
 
# pylint: disable=F0401
30
 
from pkg_resources import (
31
 
    resource_filename, resource_exists, resource_listdir, cleanup_resources)
32
 
 
33
 
DOCTEST_FLAGS = (
34
 
    doctest.ELLIPSIS |
35
 
    doctest.NORMALIZE_WHITESPACE |
36
 
    doctest.REPORT_NDIFF)
37
 
 
38
 
 
39
 
# pylint: disable=W0613
40
 
def load_tests(loader, tests, pattern):
41
 
    """Load all the doctests."""
42
 
    doctest_files = []
43
 
    if resource_exists('lazr.authentication', 'docs'):
44
 
        for name in resource_listdir('lazr.authentication', 'docs'):
45
 
            if name.endswith('.rst'):
46
 
                doctest_files.append(
47
 
                    os.path.abspath(resource_filename(
48
 
                        'lazr.authentication', 'docs/%s' % name)))
49
 
    atexit.register(cleanup_resources)
50
 
    tests.addTest(doctest.DocFileSuite(
51
 
        *doctest_files, module_relative=False, optionflags=DOCTEST_FLAGS))
52
 
    return tests