Skip to content

Commit 23aaa45

Browse files
committed
Add test for unwrapped Yields validation.
1 parent 9761bc2 commit 23aaa45

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

numpydoc/tests/test_validate.py

+43-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import sys
33
import warnings
44
from contextlib import nullcontext
5-
from functools import cached_property, partial
5+
from functools import cached_property, partial, wraps
66
from inspect import getsourcelines, getsourcefile
77

88
from numpydoc import validate
9+
from numpydoc.validate import Validator
10+
from numpydoc.docscrape import get_doc_object
911
import numpydoc.tests
1012

1113

@@ -1692,3 +1694,43 @@ def test_source_file_name_with_properties(self, property, file_name):
16921694
)
16931695
)
16941696
assert doc.source_file_name == file_name
1697+
1698+
1699+
def test_is_generator_validation_with_decorator():
1700+
"""Ensure that the check for a Yields section when an object is a generator
1701+
(YD01) works with decorated generators."""
1702+
1703+
def tinsel(f):
1704+
@wraps(f)
1705+
def wrapper(*args, **kwargs):
1706+
return f(*args, **kwargs)
1707+
1708+
return wrapper
1709+
1710+
def foo():
1711+
"""A simple generator"""
1712+
yield from range(10)
1713+
1714+
@tinsel
1715+
def bar():
1716+
"""Generator wrapped once"""
1717+
yield from range(10)
1718+
1719+
@tinsel
1720+
@tinsel
1721+
@tinsel
1722+
def baz():
1723+
"""Generator wrapped multiple times"""
1724+
yield from range(10)
1725+
1726+
# foo without wrapper is a generator
1727+
v = Validator(get_doc_object(foo))
1728+
assert v.is_generator_function
1729+
1730+
# Wrapped once
1731+
v = Validator(get_doc_object(bar))
1732+
assert v.is_generator_function
1733+
1734+
# Wrapped multiple times
1735+
v = Validator(get_doc_object(baz))
1736+
assert v.is_generator_function

0 commit comments

Comments
 (0)