Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Adding tests for parsing one line functions/ Fixing parser bug. #499

Merged
merged 11 commits into from
Sep 5, 2020
4 changes: 3 additions & 1 deletion src/pydocstyle/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,9 @@ def parse_definition(self, class_):
else: # one-liner definition
skipped_error_codes = ''
docstring = self.parse_docstring()
decorators = [] # TODO
decorators = self._accumulated_decorators
self.log.debug("current accumulated decorators: %s", decorators)
self._accumulated_decorators = []
children = []
end = self.line
self.leapfrog(tk.NEWLINE)
Expand Down
13 changes: 13 additions & 0 deletions src/tests/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,19 @@ def test():
def test():
pass
"""),
CodeSnippet("""\
'''Test this'''

@property
theyuvalraz marked this conversation as resolved.
Show resolved Hide resolved
def test(): pass
"""),
CodeSnippet("""\
'''Test this'''

@first_decorator
@property
def test(): pass
"""),
))
def test_parsing_function_decorators(code):
"""Test to ensure we are correctly parsing function decorators."""
Expand Down
27 changes: 27 additions & 0 deletions src/tests/test_cases/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,33 @@ def oneliner_d102(): return
def oneliner_withdoc(): """One liner"""


def ignored_decorator(func): # noqa: D400,D401,D415
"""Runs something"""
func()
pass


def decorator_for_test(func): # noqa: D400,D401,D415
"""Runs something"""
func()
pass


@ignored_decorator
Copy link
Member

@sambhav sambhav Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test case next to this one with a single line definition similar to this one that doesn't have an ignored decorator and raises errors and another one that has a single line definition with a docstring that doesn't raise any errors(again with a non ignored decorator) to check that everything is working as expected in this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea :)
Are the tests I added meet the criteria?

def oneliner_ignored_decorator(): """One liner"""


@decorator_for_test
@expect("D400: First line should end with a period (not 'r')")
@expect("D415: First line should end with a period, question mark,"
" or exclamation point (not 'r')")
def oneliner_with_decorator_expecting_errors(): """One liner"""


@decorator_for_test
def valid_oneliner_with_decorator(): """One liner."""


@expect("D207: Docstring is under-indented")
@expect('D213: Multi-line docstring summary should start at the second line')
def docstring_start_in_same_line(): """First Line.
Expand Down
3 changes: 2 additions & 1 deletion src/tests/test_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def test_complex_file(test_case):
test_case + '.py')
results = list(check([test_case_file],
select=set(ErrorRegistry.get_error_codes()),
ignore_decorators=re.compile('wraps')))
ignore_decorators=re.compile(
'wraps|ignored_decorator')))
for error in results:
assert isinstance(error, Error)
results = {(e.definition.name, e.message) for e in results}
Expand Down