Skip to content

Commit

Permalink
Add basic tests of validate_docstrings.Docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
nmusolino committed Feb 21, 2019
1 parent 4b35573 commit ce32ba2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 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

import validate_docstrings
validate_one = validate_docstrings.validate_one

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


class TestDocstringClass(object):
@pytest.mark.parametrize('name_and_expected_obj',
[('pandas.isnull', pandas.isnull),
('pandas.DataFrame', pandas.DataFrame),
('pandas.Series.sum', pandas.Series.sum),])
def test_resolves_class_name(self, name_and_expected_obj):
name, expected_obj = name_and_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):
# Note that the module names in this test are misspelled.
with pytest.raises(ImportError):
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):
with pytest.raises(AttributeError):
validate_docstrings.Docstring(invalid_name)


class TestMainFunction(object):
def test_exit_status_for_validate_one(self, monkeypatch):
monkeypatch.setattr(
Expand Down

0 comments on commit ce32ba2

Please sign in to comment.