| 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 |
"load_tests", |
| 21 |
] |
| 22 |
|
| 23 |
import doctest |
| 24 |
import importlib.util |
| 25 |
from pathlib import Path |
| 26 |
|
| 27 |
DOCTEST_FLAGS = ( |
| 28 |
doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF |
| 29 |
) |
| 30 |
|
| 31 |
|
| 32 |
def find_doctests(suffix): |
| 33 |
"""Find doctests matching a certain suffix.""" |
| 34 |
doctest_files = [] |
| 35 |
spec = importlib.util.find_spec("lazr.uri") |
| 36 |
if not spec or not spec.submodule_search_locations: |
| 37 |
return doctest_files |
| 38 |
docs_path = Path(list(spec.submodule_search_locations)[0]) / "docs" |
| 39 |
for path in docs_path.iterdir(): |
| 40 |
if path.name.endswith(suffix): |
| 41 |
doctest_files.append(str(path.resolve())) |
| 42 |
return doctest_files |
| 43 |
|
| 44 |
|
| 45 |
def load_tests(loader, tests, pattern): |
| 46 |
"""Load all the doctests.""" |
| 47 |
tests.addTest( |
| 48 |
doctest.DocFileSuite( |
| 49 |
*find_doctests(".rst"), |
| 50 |
module_relative=False, |
| 51 |
optionflags=DOCTEST_FLAGS, |
| 52 |
) |
| 53 |
) |
| 54 |
return tests |