Skip to content

MAINT,TST: use inspect.cleandoc ind docstring prep. #287

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class NumpyDocString(Mapping):

def __init__(self, docstring, config={}):
orig_docstring = docstring
docstring = textwrap.dedent(docstring).split('\n')
docstring = inspect.cleandoc(docstring).split('\n')

self._doc = Reader(docstring)
self._parsed_data = copy.deepcopy(self.sections)
Expand Down
20 changes: 13 additions & 7 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@

'''
doc = NumpyDocString(doc_txt)
doc_firstline_dedent = NumpyDocString(doc_txt.lstrip())

doc_yields_txt = """
Test generator
Expand Down Expand Up @@ -168,22 +169,25 @@
"""
doc_sent = NumpyDocString(doc_sent_txt)


def test_signature():
@pytest.mark.parametrize('doc', (doc, doc_firstline_dedent))
def test_signature(doc):
assert doc['Signature'].startswith('numpy.multivariate_normal(')
assert doc['Signature'].endswith('spam=None)')


def test_summary():
@pytest.mark.parametrize('doc', (doc, doc_firstline_dedent))
def test_summary(doc):
assert doc['Summary'][0].startswith('Draw values')
assert doc['Summary'][-1].endswith('covariance.')


def test_extended_summary():
@pytest.mark.parametrize('doc', (doc, doc_firstline_dedent))
def test_extended_summary(doc):
assert doc['Extended Summary'][0].startswith('The multivariate normal')


def test_parameters():
@pytest.mark.parametrize('doc', (doc, doc_firstline_dedent))
def test_parameters(doc):
assert len(doc['Parameters']) == 4
names = [n for n, _, _ in doc['Parameters']]
assert all(a == b for a, b in zip(names, ['mean', 'cov', 'shape']))
Expand All @@ -205,15 +209,17 @@ def test_parameters():
assert desc[0].startswith('The type and size')


def test_other_parameters():
@pytest.mark.parametrize('doc', (doc, doc_firstline_dedent))
def test_other_parameters(doc):
assert len(doc['Other Parameters']) == 1
assert [n for n, _, _ in doc['Other Parameters']] == ['spam']
arg, arg_type, desc = doc['Other Parameters'][0]
assert arg_type == 'parrot'
assert desc[0].startswith('A parrot off its mortal coil')


def test_returns():
@pytest.mark.parametrize('doc', (doc, doc_firstline_dedent))
def test_returns(doc):
assert len(doc['Returns']) == 3
arg, arg_type, desc = doc['Returns'][0]
assert arg == 'out'
Expand Down