Skip to content

Commit

Permalink
BUG: collect methods from private superclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
ev-br committed Dec 17, 2024
1 parent 855b4da commit 37cf07d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scipy_doctest/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def find_doctests(module, strategy=None,
t = _finder.find(item, name, globs=globs, extraglobs=extraglobs)
else:
t = finder.find(item, full_name, globs=globs, extraglobs=extraglobs)

if hasattr(item, '__mro__'):
# is a class, inspect superclasses
# cf https://github.com/scipy/scipy_doctest/issues/177
# item.__mro__ starts with itself, ends with `object`
for item_ in item.__mro__[1:-1]:
t_ = finder.find(item_, full_name, globs=globs, extraglobs=extraglobs)
t += t_
tests += t

# If the skiplist contains methods of objects, their doctests may have been
Expand Down
22 changes: 22 additions & 0 deletions scipy_doctest/tests/finder_cases_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Private method in subclasses
"""

__all__ = ["Klass"]

class _PrivateKlass:
def private_method(self):
"""
>>> 2 / 3
0.667
"""
pass


class Klass(_PrivateKlass):
def public_method(self):
"""
>>> 3 / 4
0.74
"""
pass
11 changes: 11 additions & 0 deletions scipy_doctest/tests/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np

from . import finder_cases
from . import finder_cases_2
from ..util import get_all_list, get_public_objects
from ..impl import DTFinder, DTConfig
from ..frontend import find_doctests
Expand Down Expand Up @@ -183,3 +184,13 @@ def test_descriptors_get_collected():
names = [test.name for test in tests]
assert 'numpy.dtype.kind' in names # was previously missing


@pytest.mark.parametrize('strategy', [None, 'api'])
def test_private_superclasses(strategy):
# Test that methods from inherited private superclasses get collected
tests = find_doctests(finder_cases_2, strategy=strategy)

names = set(test.name.split('.')[-1] for test in tests)
assert len(tests) == 3
assert names == {'finder_cases_2', 'public_method', 'private_method'}

0 comments on commit 37cf07d

Please sign in to comment.