Debian Codegraph @

src/lazr/delegates/tests/test_docs.py

raw symbols SCIP
1 # Copyright 2009-2021 Canonical Ltd. All rights reserved.
2 #
3 # This file is part of lazr.delegates.
4 #
5 # lazr.delegates 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.delegates is distributed in the hope that it will be useful, but WITHOUT
10 # 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.delegates. If not, see <http://www.gnu.org/licenses/>.
16
17 """Test harness for doctests."""
18
19 __all__ = []
20
21 import doctest
22 import importlib.util
23 import os
24 from pathlib import Path
25
26 DOCTEST_FLAGS = (
27 doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF
28 )
29
30
31 def load_tests(loader, tests, pattern):
32 """Load the doc tests (docs/*, if any exist)."""
33 doctest_files = []
34 spec = importlib.util.find_spec("lazr.delegates")
35 if spec and spec.submodule_search_locations:
36 docs_path = Path(list(spec.submodule_search_locations)[0]) / "docs"
37 if docs_path.is_dir():
38 for path in sorted(docs_path.iterdir()):
39 if path.name.endswith(".rst"):
40 doctest_files.append(os.path.abspath(str(path)))
41 tests.addTest(
42 doctest.DocFileSuite(
43 *doctest_files,
44 module_relative=False,
45 optionflags=DOCTEST_FLAGS,
46 encoding="UTF-8",
47 )
48 )
49 return tests