Skip to content
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

Fix minor error in dynamic load function #25256

Merged
merged 7 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import textwrap
import pytest
import numpy as np
import pandas as pd

import validate_docstrings
validate_one = validate_docstrings.validate_one

Expand Down Expand Up @@ -1004,6 +1006,32 @@ def test_item_subsection(self, idx, subsection):
assert result[idx][3] == subsection


class TestDocstringClass(object):
@pytest.mark.parametrize('name, expected_obj',
[('pandas.isnull', pd.isnull),
('pandas.DataFrame', pd.DataFrame),
('pandas.Series.sum', pd.Series.sum)])
def test_resolves_class_name(self, name, expected_obj):
d = validate_docstrings.Docstring(name)
assert d.obj is expected_obj

@pytest.mark.parametrize('invalid_name', ['panda', 'panda.DataFrame'])
def test_raises_for_invalid_module_name(self, invalid_name):
msg = 'No module can be imported from "{}"'.format(invalid_name)
with pytest.raises(ImportError, match=msg):
nmusolino marked this conversation as resolved.
Show resolved Hide resolved
validate_docstrings.Docstring(invalid_name)

@pytest.mark.parametrize('invalid_name',
['pandas.BadClassName',
'pandas.Series.bad_method_name'])
def test_raises_for_invalid_attribute_name(self, invalid_name):
name_components = invalid_name.split('.')
obj_name, invalid_attr_name = name_components[-2], name_components[-1]
msg = "'{}' has no attribute '{}'".format(obj_name, invalid_attr_name)
with pytest.raises(AttributeError, match=msg):
validate_docstrings.Docstring(invalid_name)


class TestMainFunction(object):
def test_exit_status_for_validate_one(self, monkeypatch):
monkeypatch.setattr(
Expand Down
2 changes: 1 addition & 1 deletion scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _load_obj(name):
else:
continue

if 'module' not in locals():
if 'obj' not in locals():
raise ImportError('No module can be imported '
'from "{}"'.format(name))

Expand Down