From 969feeb627e60c1f7993ba2acf8785f44d80f092 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Wed, 7 Nov 2018 09:04:19 +0000 Subject: [PATCH] Fixing bug in validate_docstrings.py, where a bracket closed in the wrong place, raised a KeyError when a private class was found in a docstrings (and adding test for that case --- scripts/tests/test_validate_docstrings.py | 11 ++++++++++- scripts/validate_docstrings.py | 5 +++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index cf8abd1680341..271c7c3021905 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -345,6 +345,11 @@ def method(self, foo=None, bar=None): """ pass + def private_classes(self): + """ + This mentions NDFrame, which is not correct. + """ + class BadSummaries(object): @@ -688,7 +693,8 @@ def test_bad_class(self): @capture_stderr @pytest.mark.parametrize("func", [ - 'func', 'astype', 'astype1', 'astype2', 'astype3', 'plot', 'method']) + 'func', 'astype', 'astype1', 'astype2', 'astype3', 'plot', 'method', + 'private_classes']) def test_bad_generic_functions(self, func): errors = validate_one(self._import_path( # noqa:F821 klass='BadGenericDocStrings', func=func))['errors'] @@ -697,6 +703,9 @@ def test_bad_generic_functions(self, func): @pytest.mark.parametrize("klass,func,msgs", [ # See Also tests + ('BadGenericDocStrings', 'private_classes', + ("Private classes (NDFrame) should not be mentioned in public " + 'docstrings',)), ('BadSeeAlso', 'desc_no_period', ('Missing period at end of description for See Also "Series.iloc"',)), ('BadSeeAlso', 'desc_first_letter_lowercase', diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 08fd3a4ce54d4..67ad21ab80b97 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -57,7 +57,7 @@ 'quotes)', 'GL03': 'Use only one blank line to separate sections or paragraphs', 'GL04': 'Private classes ({mentioned_private_classes}) should not be ' - 'mentioned in public docstring', + 'mentioned in public docstrings', 'GL05': 'Tabs found at the start of line "{line_with_tabs}", please use ' 'whitespace only', 'SS01': 'No summary found (a short summary in a single line should be ' @@ -562,7 +562,8 @@ def validate_one(func_name): errs.append(error('GL03')) mentioned_errs = doc.mentioned_private_classes if mentioned_errs: - errs.append(error('GL04'), mentioned_private_classes=mentioned_errs) + errs.append(error('GL04', + mentioned_private_classes=', '.join(mentioned_errs))) for line in doc.raw_doc.splitlines(): if re.match("^ *\t", line): errs.append(error('GL05', line_with_tabs=line.lstrip()))