| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |