Skip to content

Commit fecd8d9

Browse files
committed
Update error message and test validator
1 parent b4f23b4 commit fecd8d9

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

scripts/tests/test_validate_docstrings.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,6 @@ def method(self, foo=None, bar=None):
333333
"""
334334
pass
335335

336-
337-
class BadSeeAlso(object):
338-
339-
def prefix_pandas(self):
340-
"""
341-
Return prefix with `pandas` from See Also sec
342-
"""
343-
pass
344-
345336
class BadSummaries(object):
346337

347338
def wrong_line(self):
@@ -509,6 +500,13 @@ def no_punctuation(self):
509500
"""
510501
return "Hello world!"
511502

503+
class BadSeeAlso(object):
504+
505+
def prefix_pandas(self):
506+
"""
507+
Return prefix with `pandas` from See Also sec
508+
"""
509+
pass
512510

513511
class TestValidator(object):
514512

@@ -572,9 +570,6 @@ def test_bad_generic_functions(self, func):
572570
assert errors
573571

574572
@pytest.mark.parametrize("klass,func,msgs", [
575-
#SeeAlso tests
576-
('BadSeeAlso', 'prefix_pandas',
577-
('Should not start with pandas',)),
578573
# Summary tests
579574
('BadSummaries', 'wrong_line',
580575
('should start in the line immediately after the opening quotes',)),
@@ -611,7 +606,10 @@ def test_bad_generic_functions(self, func):
611606
pytest.param('BadReturns', 'no_description', ('foo',),
612607
marks=pytest.mark.xfail),
613608
pytest.param('BadReturns', 'no_punctuation', ('foo',),
614-
marks=pytest.mark.xfail)
609+
marks=pytest.mark.xfail),
610+
# SeeAlso tests
611+
('BadSeeAlso', 'prefix_pandas',
612+
('Should not start with pandas',)),
615613
])
616614
def test_bad_examples(self, capsys, klass, func, msgs):
617615
result = validate_one(self._import_path(klass=klass, func=func)) # noqa:F821

scripts/validate_docstrings.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,9 @@ def validate_one(func_name):
499499
if not rel_desc:
500500
errs.append('Missing description for '
501501
'See Also "{}" reference'.format(rel_name))
502-
if rel_name[:7].lower() == 'pandas.':
503-
errs.append('{} should not have prefix `pandas`'.format(rel_name))
502+
if rel_name.startswith('pandas.'):
503+
errs.append('{} in the `See Also` section does not need the `pandas` prefix, '
504+
'use {} instead.'.format(rel_name,rel_name.replace('pandas.','')))
504505
for line in doc.raw_doc.splitlines():
505506
if re.match("^ *\t", line):
506507
errs.append('Tabs found at the start of line "{}", '

0 commit comments

Comments
 (0)