|
1 | 1 | import pytest
|
| 2 | +from collections import defaultdict |
2 | 3 | from io import StringIO
|
| 4 | +from pathlib import PosixPath |
3 | 5 | from copy import deepcopy
|
4 | 6 | from numpydoc.numpydoc import mangle_docstrings, _clean_text_signature, update_config
|
5 | 7 | from numpydoc.xref import DEFAULT_LINKS
|
@@ -41,7 +43,7 @@ def __init__(self):
|
41 | 43 | self.warningiserror = False
|
42 | 44 |
|
43 | 45 |
|
44 |
| -def test_mangle_docstrings(): |
| 46 | +def test_mangle_docstrings_basic(): |
45 | 47 | s = """
|
46 | 48 | A top section before
|
47 | 49 |
|
@@ -69,6 +71,35 @@ def test_mangle_docstrings():
|
69 | 71 | assert "upper" not in [x.strip() for x in lines]
|
70 | 72 |
|
71 | 73 |
|
| 74 | +def test_mangle_docstrings_inherited_class_members(): |
| 75 | + # if subclass docs are rendered, this PosixPath should have Path.samefile |
| 76 | + p = """ |
| 77 | +A top section before |
| 78 | +
|
| 79 | +.. autoclass:: pathlib.PosixPath |
| 80 | +""" |
| 81 | + lines = p.split("\n") |
| 82 | + app = MockApp() |
| 83 | + mangle_docstrings(app, "class", "pathlib.PosixPath", PosixPath, {}, lines) |
| 84 | + lines = [x.strip() for x in lines] |
| 85 | + assert "samefile" in lines |
| 86 | + app.config.numpydoc_show_inherited_class_members = False |
| 87 | + lines = p.split("\n") |
| 88 | + mangle_docstrings(app, "class", "pathlib.PosixPath", PosixPath, {}, lines) |
| 89 | + lines = [x.strip() for x in lines] |
| 90 | + assert "samefile" not in lines |
| 91 | + app.config.numpydoc_show_inherited_class_members = dict() |
| 92 | + lines = p.split("\n") |
| 93 | + mangle_docstrings(app, "class", "pathlib.PosixPath", PosixPath, {}, lines) |
| 94 | + lines = [x.strip() for x in lines] |
| 95 | + assert "samefile" in lines |
| 96 | + app.config.numpydoc_show_inherited_class_members = defaultdict(lambda: False) |
| 97 | + lines = p.split("\n") |
| 98 | + mangle_docstrings(app, "class", "pathlib.PosixPath", PosixPath, {}, lines) |
| 99 | + lines = [x.strip() for x in lines] |
| 100 | + assert "samefile" not in lines |
| 101 | + |
| 102 | + |
72 | 103 | def test_clean_text_signature():
|
73 | 104 | assert _clean_text_signature(None) is None
|
74 | 105 | assert _clean_text_signature("func($self)") == "func()"
|
|
0 commit comments