Skip to content

Commit 8f0bef9

Browse files
committed
Add unit test for Yields section.
1 parent 246b440 commit 8f0bef9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

numpydoc/docscrape.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ def _parse(self):
292292
for (section,content) in self._read_sections():
293293
if not section.startswith('..'):
294294
section = ' '.join([s.capitalize() for s in section.split(' ')])
295-
if section in ('Parameters', 'Returns', 'Raises', 'Warns',
296-
'Other Parameters', 'Attributes', 'Methods'):
295+
if section in ('Parameters', 'Returns', 'Yields', 'Raises',
296+
'Warns', 'Other Parameters', 'Attributes',
297+
'Methods'):
297298
self[section] = self._parse_param_list(content)
298299
elif section.startswith('.. index::'):
299300
self['index'] = self._parse_index(section, content)

numpydoc/tests/test_docscrape.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,29 @@ def test_returns():
164164
assert desc[0].startswith('This is not a real')
165165
assert desc[-1].endswith('anonymous return values.')
166166

167+
def test_yields():
168+
doc_text = """
169+
Test generator
170+
171+
Yields
172+
------
173+
a : int
174+
The number of apples.
175+
b : int
176+
The number of bananas.
177+
178+
"""
179+
doc = NumpyDocString(doc_text)
180+
section = doc['Yields']
181+
print(section)
182+
assert_equal(len(section), 2)
183+
truth = [('a', 'apples.'), ('b', 'bananas.')]
184+
for (arg, arg_type, desc), (arg_true, ending) in zip(section, truth):
185+
assert_equal(arg, arg_true)
186+
assert_equal(arg_type, 'int')
187+
assert desc[0].startswith('The number of')
188+
assert desc[0].endswith(ending)
189+
167190
def test_notes():
168191
assert doc['Notes'][0].startswith('Instead')
169192
assert doc['Notes'][-1].endswith('definite.')

0 commit comments

Comments
 (0)