Skip to content

Changes to validate_docstring script to be able to check all docstrings at once #22408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 13, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions pandas/tests/scripts/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,25 +490,25 @@ def _import_path(self, klass=None, func=None):
return base_path

def test_good_class(self):
assert validate_one(self._import_path( # noqa: F821
klass='GoodDocStrings')) == 0
assert len(validate_one(self._import_path( # noqa: F821
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For PEP8 can just use implicit truthiness of empty list, so just not ...['errors'] instead of len(...['errors']) == 0. Applicable to other tests below

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general that is true, however in this case I think it is good to test it is actually a zero-length list and not something else Falsey?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on both comments, I'll change as @WillAyd suggests, and will also assert that the result is a list.

klass='GoodDocStrings'))['errors']) == 0

@pytest.mark.parametrize("func", [
'plot', 'sample', 'random_letters', 'sample_values', 'head', 'head1',
'contains'])
def test_good_functions(self, func):
assert validate_one(self._import_path( # noqa: F821
klass='GoodDocStrings', func=func)) == 0
assert len(validate_one(self._import_path( # noqa: F821
klass='GoodDocStrings', func=func))['errors']) == 0

def test_bad_class(self):
assert validate_one(self._import_path( # noqa: F821
klass='BadGenericDocStrings')) > 0
assert len(validate_one(self._import_path( # noqa: F821
klass='BadGenericDocStrings'))['errors']) > 0

@pytest.mark.parametrize("func", [
'func', 'astype', 'astype1', 'astype2', 'astype3', 'plot', 'method'])
def test_bad_generic_functions(self, func):
assert validate_one(self._import_path( # noqa:F821
klass='BadGenericDocStrings', func=func)) > 0
assert len(validate_one(self._import_path( # noqa:F821
klass='BadGenericDocStrings', func=func))['errors']) > 0

@pytest.mark.parametrize("klass,func,msgs", [
# Summary tests
Expand Down Expand Up @@ -546,7 +546,6 @@ def test_bad_generic_functions(self, func):
marks=pytest.mark.xfail)
])
def test_bad_examples(self, capsys, klass, func, msgs):
validate_one(self._import_path(klass=klass, func=func)) # noqa:F821
err = capsys.readouterr().err
res = validate_one(self._import_path(klass=klass, func=func)) # noqa:F821
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency let's use result instead of res

for msg in msgs:
assert msg in err
assert msg in ''.join(res['errors'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to join as a string here or can we just check for inclusion in the list?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not wrong, the messages we're checking are no the whole error message, but part of it. So, this is equivalent to something like:

assert 'error in summary' in ''.join(['there is a error in summary for this doc', 'some other error'])

I think it makes more sense to use the join, as the error message will be clearer if this fails. Compared to checking all in a comprehension and them doing an any (which I guess will just say False is not True).

Loading