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 param parsing. #286

Merged
merged 5 commits into from
Aug 10, 2020
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
6 changes: 4 additions & 2 deletions numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ def _read_sections(self):
yield name, self._strip(data[2:])

def _parse_param_list(self, content, single_element_is_type=False):
content = dedent_lines(content)
r = Reader(content)
params = []
while not r.eof():
header = r.read().strip()
if ' : ' in header:
arg_name, arg_type = header.split(' : ', maxsplit=1)
if ' :' in header:
arg_name, arg_type = header.split(' :', maxsplit=1)
arg_name, arg_type = arg_name.strip(), arg_type.strip()
else:
if single_element_is_type:
arg_name, arg_type = '', header
Expand Down
44 changes: 32 additions & 12 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@
:refguide: random;distributions, random;gauss

'''
doc = NumpyDocString(doc_txt)

@pytest.fixture(params=['','\n '], ids=["flush", "newline_indented"])
def doc(request):
return NumpyDocString(request.param+doc_txt)


doc_yields_txt = """
Test generator
Expand Down Expand Up @@ -169,21 +173,21 @@
doc_sent = NumpyDocString(doc_sent_txt)


def test_signature():
def test_signature(doc):
assert doc['Signature'].startswith('numpy.multivariate_normal(')
assert doc['Signature'].endswith('spam=None)')


def test_summary():
def test_summary(doc):
assert doc['Summary'][0].startswith('Draw values')
assert doc['Summary'][-1].endswith('covariance.')


def test_extended_summary():
def test_extended_summary(doc):
assert doc['Extended Summary'][0].startswith('The multivariate normal')


def test_parameters():
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,16 @@ def test_parameters():
assert desc[0].startswith('The type and size')


def test_other_parameters():
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():

def test_returns(doc):
assert len(doc['Returns']) == 3
arg, arg_type, desc = doc['Returns'][0]
assert arg == 'out'
Expand Down Expand Up @@ -342,23 +347,23 @@ def dummy_func(arg):
or 'function dummy_func' in str(e))


def test_notes():
def test_notes(doc):
assert doc['Notes'][0].startswith('Instead')
assert doc['Notes'][-1].endswith('definite.')
assert len(doc['Notes']) == 17


def test_references():
def test_references(doc):
assert doc['References'][0].startswith('..')
assert doc['References'][-1].endswith('2001.')


def test_examples():
def test_examples(doc):
assert doc['Examples'][0].startswith('>>>')
assert doc['Examples'][-1].endswith('True]')


def test_index():
def test_index(doc):
assert doc['index']['default'] == 'random'
assert len(doc['index']) == 2
assert len(doc['index']['refguide']) == 2
Expand All @@ -382,7 +387,7 @@ def line_by_line_compare(a, b, n_lines=None):
assert aa == bb


def test_str():
def test_str(doc):
# doc_txt has the order of Notes and See Also sections flipped.
# This should be handled automatically, and so, one thing this test does
# is to make sure that See Also precedes Notes in the output.
Expand Down Expand Up @@ -921,6 +926,21 @@ class BadSection:
def test_empty_first_line():
assert doc7['Summary'][0].startswith('Doc starts')

doc8 = NumpyDocString("""

Parameters with colon and no types:

Parameters
----------

data :
some stuff, technically invalid
""")


def test_trailing_colon():
assert doc8['Parameters'][0].name == 'data'
Carreau marked this conversation as resolved.
Show resolved Hide resolved


def test_no_summary():
str(SphinxDocString("""
Expand Down