Skip to content

Commit

Permalink
Add test for unwrapped Yields validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbar committed Apr 15, 2024
1 parent 54496d0 commit 78b2043
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion numpydoc/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import sys
import warnings
from contextlib import nullcontext
from functools import cached_property, partial
from functools import cached_property, partial, wraps
from inspect import getsourcelines, getsourcefile

from numpydoc import validate
from numpydoc.validate import Validator
from numpydoc.docscrape import get_doc_object
import numpydoc.tests


Expand Down Expand Up @@ -1692,3 +1694,43 @@ def test_source_file_name_with_properties(self, property, file_name):
)
)
assert doc.source_file_name == file_name


def test_is_generator_validation_with_decorator():
"""Ensure that the check for a Yields section when an object is a generator
(YD01) works with decorated generators."""

def tinsel(f):
@wraps(f)
def wrapper(*args, **kwargs):
return f(*args, **kwargs)

return wrapper

def foo():
"""A simple generator"""
yield from range(10)

@tinsel
def bar():
"""Generator wrapped once"""
yield from range(10)

@tinsel
@tinsel
@tinsel
def baz():
"""Generator wrapped multiple times"""
yield from range(10)

# foo without wrapper is a generator
v = Validator(get_doc_object(foo))
assert v.is_generator_function

# Wrapped once
v = Validator(get_doc_object(bar))
assert v.is_generator_function

# Wrapped multiple times
v = Validator(get_doc_object(baz))
assert v.is_generator_function

0 comments on commit 78b2043

Please sign in to comment.