Skip to content

Commit

Permalink
Merge pull request #65 from NelleV/64_section_twice
Browse files Browse the repository at this point in the history
Raise an error when a section is present twice
  • Loading branch information
stefanv authored Oct 4, 2016
2 parents 4835c31 + cb9c29d commit 22e5080
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
*.pyc
*.pyo
*.egg-info
*.swp
*.swo
build
dist
5 changes: 5 additions & 0 deletions numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ def _parse(self):
if not section.startswith('..'):
section = (s.capitalize() for s in section.split(' '))
section = ' '.join(section)
if self.get(section):
msg = ("The section %s appears twice in the docstring." %
section)
raise ValueError(msg)

if section in ('Parameters', 'Returns', 'Yields', 'Raises',
'Warns', 'Other Parameters', 'Attributes',
'Methods'):
Expand Down
16 changes: 16 additions & 0 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ def test_returnyield():
"""
assert_raises(ValueError, NumpyDocString, doc_text)


def test_section_twice():
doc_text = """
Test having a section Notes twice
Notes
-----
See the next note for more information
Notes
-----
That should break...
"""
assert_raises(ValueError, NumpyDocString, doc_text)


def test_notes():
assert doc['Notes'][0].startswith('Instead')
assert doc['Notes'][-1].endswith('definite.')
Expand Down

0 comments on commit 22e5080

Please sign in to comment.