1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
# type: ignore
import inspect
from doctest import DocTestFinder, DocTestSuite
import pyoxigraph
class ExtendedDocTestFinder(DocTestFinder):
"""
More aggressive doctest lookup
"""
def _find(self, tests, obj, name, module, source_lines, globs, seen):
# If we've already processed this object, then ignore it.
if id(obj) in seen:
return
seen[id(obj)] = 1
# Find a test for this object, and add it to the list of tests.
test = self._get_test(obj, name, module, globs, source_lines)
if test is not None:
tests.append(test)
# Look for tests in a module's contained objects.
if inspect.ismodule(obj) or inspect.isclass(obj):
for valname, val in obj.__dict__.items():
if valname == "__doc__":
continue
# Special handling for staticmethod/classmethod.
if isinstance(val, (staticmethod, classmethod)):
val = val.__func__
self._find(tests, val, f"{name}.{valname}", module, source_lines, globs, seen)
def load_tests(_loader, tests, _ignore):
tests.addTests(DocTestSuite(pyoxigraph, test_finder=ExtendedDocTestFinder()))
return tests
|