Skip to content

Commit 34152ef

Browse files
committed
Add basic tests of validate_docstrings.Docstring
1 parent 4b35573 commit 34152ef

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

scripts/tests/test_validate_docstrings.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import textwrap
55
import pytest
66
import numpy as np
7+
import pandas
8+
79
import validate_docstrings
810
validate_one = validate_docstrings.validate_one
911

@@ -1004,6 +1006,30 @@ def test_item_subsection(self, idx, subsection):
10041006
assert result[idx][3] == subsection
10051007

10061008

1009+
class TestDocstringClass(object):
1010+
@pytest.mark.parametrize('name_and_expected_obj',
1011+
[('pandas.isnull', pandas.isnull),
1012+
('pandas.DataFrame', pandas.DataFrame),
1013+
('pandas.Series.sum', pandas.Series.sum)])
1014+
def test_resolves_class_name(self, name_and_expected_obj):
1015+
name, expected_obj = name_and_expected_obj
1016+
d = validate_docstrings.Docstring(name)
1017+
assert d.obj is expected_obj
1018+
1019+
@pytest.mark.parametrize('invalid_name', ['panda', 'panda.DataFrame'])
1020+
def test_raises_for_invalid_module_name(self, invalid_name):
1021+
# Note that the module names in this test are misspelled.
1022+
with pytest.raises(ImportError):
1023+
validate_docstrings.Docstring(invalid_name)
1024+
1025+
@pytest.mark.parametrize('invalid_name',
1026+
['pandas.BadClassName',
1027+
'pandas.Series.bad_method_name'])
1028+
def test_raises_for_invalid_attribute_name(self, invalid_name):
1029+
with pytest.raises(AttributeError):
1030+
validate_docstrings.Docstring(invalid_name)
1031+
1032+
10071033
class TestMainFunction(object):
10081034
def test_exit_status_for_validate_one(self, monkeypatch):
10091035
monkeypatch.setattr(

0 commit comments

Comments
 (0)