@@ -1198,6 +1198,113 @@ def missing_whitespace_after_comma(self):
1198
1198
"""
1199
1199
1200
1200
1201
+ class ConstructorDocumentedInClassAndInit :
1202
+ """
1203
+ Class to test constructor documented via class and constructor docstrings.
1204
+
1205
+ A case where both the class docstring and the constructor docstring are
1206
+ defined.
1207
+
1208
+ Parameters
1209
+ ----------
1210
+ param1 : int
1211
+ Description of param1.
1212
+
1213
+ See Also
1214
+ --------
1215
+ otherclass : A class that does something else.
1216
+
1217
+ Examples
1218
+ --------
1219
+ This is an example of how to use ConstructorDocumentedInClassAndInit.
1220
+ """
1221
+
1222
+ def __init__ (self , param1 : int ) -> None :
1223
+ """
1224
+ Constructor docstring with additional information.
1225
+
1226
+ Extended information.
1227
+
1228
+ Parameters
1229
+ ----------
1230
+ param1 : int
1231
+ Description of param1 with extra details.
1232
+
1233
+ See Also
1234
+ --------
1235
+ otherclass : A class that does something else.
1236
+
1237
+ Examples
1238
+ --------
1239
+ This is an example of how to use ConstructorDocumentedInClassAndInit.
1240
+ """
1241
+
1242
+
1243
+ class ConstructorDocumentedInClass :
1244
+ """
1245
+ Class to test constructor documented via class docstring.
1246
+
1247
+ Useful to ensure that validation of `__init__` does not signal GL08,
1248
+ when the class docstring properly documents the `__init__` constructor.
1249
+
1250
+ Parameters
1251
+ ----------
1252
+ param1 : int
1253
+ Description of param1.
1254
+
1255
+ See Also
1256
+ --------
1257
+ otherclass : A class that does something else.
1258
+
1259
+ Examples
1260
+ --------
1261
+ This is an example of how to use ConstructorDocumentedInClass.
1262
+ """
1263
+
1264
+ def __init__ (self , param1 : int ) -> None :
1265
+ pass
1266
+
1267
+
1268
+ class ConstructorDocumentedInClassWithNoParameters :
1269
+ """
1270
+ Class to test constructor documented via class docstring with no parameters.
1271
+
1272
+ Useful to ensure that validation of `__init__` does not signal GL08,
1273
+ when the class docstring properly documents the `__init__` constructor.
1274
+
1275
+ See Also
1276
+ --------
1277
+ otherclass : A class that does something else.
1278
+
1279
+ Examples
1280
+ --------
1281
+ This is an example of how to use ConstructorDocumentedInClassWithNoParameters.
1282
+ """
1283
+
1284
+ def __init__ (self ) -> None :
1285
+ pass
1286
+
1287
+
1288
+ class IncompleteConstructorDocumentedInClass :
1289
+ """
1290
+ Class to test an incomplete constructor docstring.
1291
+
1292
+ This class does not properly document parameters.
1293
+ Unnecessary extended summary.
1294
+
1295
+ See Also
1296
+ --------
1297
+ otherclass : A class that does something else.
1298
+
1299
+ Examples
1300
+ --------
1301
+ This is an example of how to use IncompleteConstructorDocumentedInClass.
1302
+ """
1303
+
1304
+ def __init__ (self , param1 : int ):
1305
+ pass
1306
+
1307
+
1201
1308
class TestValidator :
1202
1309
def _import_path (self , klass = None , func = None ):
1203
1310
"""
@@ -1536,6 +1643,40 @@ def test_bad_docstrings(self, capsys, klass, func, msgs):
1536
1643
for msg in msgs :
1537
1644
assert msg in " " .join (err [1 ] for err in result ["errors" ])
1538
1645
1646
+ @pytest .mark .parametrize (
1647
+ "klass,exp_init_codes,exc_init_codes,exp_klass_codes" ,
1648
+ [
1649
+ ("ConstructorDocumentedInClass" , tuple (), ("GL08" ,), tuple ()),
1650
+ ("ConstructorDocumentedInClassAndInit" , tuple (), ("GL08" ,), tuple ()),
1651
+ (
1652
+ "ConstructorDocumentedInClassWithNoParameters" ,
1653
+ tuple (),
1654
+ ("GL08" ,),
1655
+ tuple (),
1656
+ ),
1657
+ (
1658
+ "IncompleteConstructorDocumentedInClass" ,
1659
+ ("GL08" ,),
1660
+ tuple (),
1661
+ ("PR01" ), # Parameter not documented in class constructor
1662
+ ),
1663
+ ],
1664
+ )
1665
+ def test_constructor_docstrings (
1666
+ self , klass , exp_init_codes , exc_init_codes , exp_klass_codes
1667
+ ):
1668
+ # First test the class docstring itself, checking expected_klass_codes match
1669
+ result = validate_one (self ._import_path (klass = klass ))
1670
+ for err in result ["errors" ]:
1671
+ assert err [0 ] in exp_klass_codes
1672
+
1673
+ # Then test the constructor docstring
1674
+ result = validate_one (self ._import_path (klass = klass , func = "__init__" ))
1675
+ for code in exp_init_codes :
1676
+ assert code in " " .join (err [0 ] for err in result ["errors" ])
1677
+ for code in exc_init_codes :
1678
+ assert code not in " " .join (err [0 ] for err in result ["errors" ])
1679
+
1539
1680
1540
1681
def decorator (x ):
1541
1682
"""Test decorator."""
0 commit comments