Skip to content

Commit c7da072

Browse files
committed
test(validate.py): Added a test to check nested class docstring when checking for initialisation docstring
Test written due to bug missed in numpy#592.
1 parent d8f05e6 commit c7da072

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

numpydoc/tests/test_validate.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,69 @@ def __init__(self, param1: int):
13051305
pass
13061306

13071307

1308+
class ConstructorDocumentedinEmbeddedClass: # ignore Gl08, ES01
1309+
"""
1310+
Class to test the initialisation behaviour of a embedded class.
1311+
"""
1312+
1313+
class EmbeddedClass1: # ignore GL08, ES01
1314+
"""
1315+
An additional level for embedded class documentation checking.
1316+
"""
1317+
1318+
class EmbeddedClass2:
1319+
"""
1320+
This is an embedded class.
1321+
1322+
Extended summary.
1323+
1324+
Parameters
1325+
----------
1326+
param1 : int
1327+
Description of param1.
1328+
1329+
See Also
1330+
--------
1331+
otherclass : A class that does something else.
1332+
1333+
Examples
1334+
--------
1335+
This is an example of how to use EmbeddedClass.
1336+
"""
1337+
1338+
def __init__(self, param1: int) -> None:
1339+
pass
1340+
1341+
1342+
class IncompleteConstructorDocumentedinEmbeddedClass:
1343+
"""
1344+
Class to test the initialisation behaviour of a embedded class.
1345+
"""
1346+
1347+
class EmbeddedClass1:
1348+
"""
1349+
An additional level for embedded class documentation checking.
1350+
"""
1351+
1352+
class EmbeddedClass2:
1353+
"""
1354+
This is an embedded class.
1355+
1356+
Extended summary.
1357+
1358+
See Also
1359+
--------
1360+
otherclass : A class that does something else.
1361+
1362+
Examples
1363+
--------
1364+
This is an example of how to use EmbeddedClass.
1365+
"""
1366+
1367+
def __init__(self, param1: int) -> None:
1368+
pass
1369+
1370+
13081371
class TestValidator:
13091372
def _import_path(self, klass=None, func=None):
13101373
"""
@@ -1660,6 +1723,18 @@ def test_bad_docstrings(self, capsys, klass, func, msgs):
16601723
tuple(),
16611724
("PR01"), # Parameter not documented in class constructor
16621725
),
1726+
(
1727+
"ConstructorDocumentedinEmbeddedClass.EmbeddedClass1.EmbeddedClass2",
1728+
tuple(),
1729+
("GL08",),
1730+
tuple(),
1731+
),
1732+
(
1733+
"IncompleteConstructorDocumentedinEmbeddedClass.EmbeddedClass1.EmbeddedClass2",
1734+
("GL08",),
1735+
tuple(),
1736+
("PR01",),
1737+
),
16631738
],
16641739
)
16651740
def test_constructor_docstrings(
@@ -1677,6 +1752,11 @@ def test_constructor_docstrings(
16771752
for code in exc_init_codes:
16781753
assert code not in " ".join(err[0] for err in result["errors"])
16791754

1755+
if klass == "ConstructorDocumentedinEmbeddedClass":
1756+
raise NotImplementedError(
1757+
"Test for embedded class constructor docstring not implemented yet."
1758+
)
1759+
16801760

16811761
def decorator(x):
16821762
"""Test decorator."""

0 commit comments

Comments
 (0)