|
4 | 4 | import textwrap
|
5 | 5 | import pytest
|
6 | 6 | import numpy as np
|
| 7 | +import pandas as pd |
| 8 | + |
7 | 9 | import validate_docstrings
|
8 | 10 | validate_one = validate_docstrings.validate_one
|
9 | 11 |
|
@@ -1004,6 +1006,32 @@ def test_item_subsection(self, idx, subsection):
|
1004 | 1006 | assert result[idx][3] == subsection
|
1005 | 1007 |
|
1006 | 1008 |
|
| 1009 | +class TestDocstringClass(object): |
| 1010 | + @pytest.mark.parametrize('name, expected_obj', |
| 1011 | + [('pandas.isnull', pd.isnull), |
| 1012 | + ('pandas.DataFrame', pd.DataFrame), |
| 1013 | + ('pandas.Series.sum', pd.Series.sum)]) |
| 1014 | + def test_resolves_class_name(self, name, expected_obj): |
| 1015 | + d = validate_docstrings.Docstring(name) |
| 1016 | + assert d.obj is expected_obj |
| 1017 | + |
| 1018 | + @pytest.mark.parametrize('invalid_name', ['panda', 'panda.DataFrame']) |
| 1019 | + def test_raises_for_invalid_module_name(self, invalid_name): |
| 1020 | + msg = 'No module can be imported from "{}"'.format(invalid_name) |
| 1021 | + with pytest.raises(ImportError, match=msg): |
| 1022 | + validate_docstrings.Docstring(invalid_name) |
| 1023 | + |
| 1024 | + @pytest.mark.parametrize('invalid_name', |
| 1025 | + ['pandas.BadClassName', |
| 1026 | + 'pandas.Series.bad_method_name']) |
| 1027 | + def test_raises_for_invalid_attribute_name(self, invalid_name): |
| 1028 | + name_components = invalid_name.split('.') |
| 1029 | + obj_name, invalid_attr_name = name_components[-2], name_components[-1] |
| 1030 | + msg = "'{}' has no attribute '{}'".format(obj_name, invalid_attr_name) |
| 1031 | + with pytest.raises(AttributeError, match=msg): |
| 1032 | + validate_docstrings.Docstring(invalid_name) |
| 1033 | + |
| 1034 | + |
1007 | 1035 | class TestMainFunction(object):
|
1008 | 1036 | def test_exit_status_for_validate_one(self, monkeypatch):
|
1009 | 1037 | monkeypatch.setattr(
|
|
0 commit comments