Skip to content

Commit

Permalink
BUG: collect doctests from docstrings of data descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
ev-br committed Dec 15, 2024
1 parent 5113870 commit b296523
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scipy_doctest/impl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import warnings
import inspect
import doctest
from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, IGNORE_EXCEPTION_DETAIL
from itertools import zip_longest
Expand Down Expand Up @@ -538,6 +539,19 @@ def find(self, obj, name=None, module=None, globs=None, extraglobs=None):
# XXX: does this make similar checks in testmod/testfile duplicate?
if module not in self.config.skiplist:
tests = super().find(obj, name, module, globs, extraglobs)

if inspect.isclass(obj):
descriptors = [
(name_, method)
for name_, method in inspect.getmembers(obj)
if inspect.isdatadescriptor(method)
]

for name_, method in descriptors:
tests += super().find(
method, f'{name}.{name_}', module, globs, extraglobs
)

return tests


Expand Down
11 changes: 11 additions & 0 deletions scipy_doctest/tests/test_finder.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import pytest

import numpy as np

from . import finder_cases
from ..util import get_all_list, get_public_objects
from ..impl import DTFinder, DTConfig
from ..frontend import find_doctests


def test_get_all_list():
items, depr, other = get_all_list(finder_cases)
assert sorted(items) == ['Klass', 'func']
Expand Down Expand Up @@ -168,3 +171,11 @@ def test_dtfinder_config():
config = DTConfig()
finder = DTFinder(config=config)
assert finder.config is config


@pytest.mark.skipif(np.__version__ < '2', reason="XXX check if works on numpy 1.x")
def test_descriptors_get_collected():
tests = find_doctests(np, strategy=[np.dtype])
names = [test.name for test in tests]
assert 'numpy.dtype.kind' in names # was previously missing

0 comments on commit b296523

Please sign in to comment.