Debian Codegraph @

src/lazr/config/tests/test_docs.py

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