Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
augustelalande committed Jul 27, 2024
1 parent fc7feb6 commit 8cd1d0a
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# DOC402
def foo(num: int) -> str:
"""
Do something
Args:
num (int): A number
"""
yield 'test'


# OK
def foo(num: int) -> str:
"""
Do something
Args:
num (int): A number
Yields:
str: A string
"""
yield 'test'


class Bar:

# OK
def foo(self) -> str:
"""
Do something
Args:
num (int): A number
Yields:
str: A string
"""
yield 'test'


# DOC402
def bar(self) -> str:
"""
Do something
Args:
num (int): A number
"""
yield 'test'


# OK
def test():
"""Do something."""
# DOC402
def nested():
"""Do something nested."""
yield 5

print("I never yield")


# DOC402
def test():
"""Do something."""
yield from range(10)

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# DOC402
def foo(num: int) -> str:
"""
Do something
Parameters
----------
num : int
A number
"""
yield 'test'


# OK
def foo(num: int) -> str:
"""
Do something
Parameters
----------
num : int
A number
Yields
-------
str
A string
"""
yield 'test'


class Bar:

# OK
def foo(self) -> str:
"""
Do something
Parameters
----------
num : int
A number
Yields
-------
str
A string
"""
yield 'test'


# DOC402
def bar(self) -> str:
"""
Do something
Parameters
----------
num : int
A number
"""
yield 'test'
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# OK
def foo(num: int) -> str:
"""
Do something
Args:
num (int): A number
"""
print('test')


# DOC403
def foo(num: int) -> str:
"""
Do something
Args:
num (int): A number
Yields:
str: A string
"""
print('test')


class Bar:

# DOC403
def foo(self) -> str:
"""
Do something
Args:
num (int): A number
Yields:
str: A string
"""
print('test')


# OK
def bar(self) -> str:
"""
Do something
Args:
num (int): A number
"""
print('test')
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# OK
def foo(num: int) -> str:
"""
Do something
Parameters
----------
num : int
A number
"""
print('test')


# DOC403
def foo(num: int) -> str:
"""
Do something
Parameters
----------
num : int
A number
Yields
-------
str
A string
"""
print('test')


class Bar:

# DOC403
def foo(self) -> str:
"""
Do something
Parameters
----------
num : int
A number
Yields
-------
str
A string
"""
print('test')


# OK
def bar(self) -> str:
"""
Do something
Parameters
----------
num : int
A number
"""
print('test')
4 changes: 4 additions & 0 deletions crates/ruff_linter/src/rules/pydoclint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ mod tests {

#[test_case(Rule::DocstringMissingReturns, Path::new("DOC201_google.py"))]
#[test_case(Rule::DocstringExtraneousReturns, Path::new("DOC202_google.py"))]
#[test_case(Rule::DocstringMissingYields, Path::new("DOC402_google.py"))]
#[test_case(Rule::DocstringExtraneousYields, Path::new("DOC403_google.py"))]
#[test_case(Rule::DocstringMissingException, Path::new("DOC501_google.py"))]
#[test_case(Rule::DocstringExtraneousException, Path::new("DOC502_google.py"))]
fn rules_google_style(rule_code: Rule, path: &Path) -> Result<()> {
Expand All @@ -49,6 +51,8 @@ mod tests {

#[test_case(Rule::DocstringMissingReturns, Path::new("DOC201_numpy.py"))]
#[test_case(Rule::DocstringExtraneousReturns, Path::new("DOC202_numpy.py"))]
#[test_case(Rule::DocstringMissingYields, Path::new("DOC402_numpy.py"))]
#[test_case(Rule::DocstringExtraneousYields, Path::new("DOC403_numpy.py"))]
#[test_case(Rule::DocstringMissingException, Path::new("DOC501_numpy.py"))]
#[test_case(Rule::DocstringExtraneousException, Path::new("DOC502_numpy.py"))]
fn rules_numpy_style(rule_code: Rule, path: &Path) -> Result<()> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: crates/ruff_linter/src/rules/pydoclint/mod.rs
---
DOC403_google.py:20:1: DOC403 Docstring should not have a yields section because the function doesn't yield anything
|
18 | num (int): A number
19 |
20 | / Yields:
21 | | str: A string
22 | | """
| |____^ DOC403
23 | print('test')
|

DOC403_google.py:36:1: DOC403 Docstring should not have a yields section because the function doesn't yield anything
|
34 | num (int): A number
35 |
36 | / Yields:
37 | | str: A string
38 | | """
| |________^ DOC403
39 | print('test')
|
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: crates/ruff_linter/src/rules/pydoclint/mod.rs
---
DOC403_numpy.py:24:1: DOC403 Docstring should not have a yields section because the function doesn't yield anything
|
22 | A number
23 |
24 | / Yields
25 | | -------
26 | | str
27 | | A string
28 | | """
| |____^ DOC403
29 | print('test')
|

DOC403_numpy.py:44:1: DOC403 Docstring should not have a yields section because the function doesn't yield anything
|
42 | A number
43 |
44 | / Yields
45 | | -------
46 | | str
47 | | A string
48 | | """
| |________^ DOC403
49 | print('test')
|
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
source: crates/ruff_linter/src/rules/pydoclint/mod.rs
---
DOC402_google.py:9:5: DOC402 `yield` is not documented in docstring
|
7 | num (int): A number
8 | """
9 | yield 'test'
| ^^^^^^^^^^^^ DOC402
|

DOC402_google.py:50:9: DOC402 `yield` is not documented in docstring
|
48 | num (int): A number
49 | """
50 | yield 'test'
| ^^^^^^^^^^^^ DOC402
|

DOC402_google.py:59:9: DOC402 `yield` is not documented in docstring
|
57 | def nested():
58 | """Do something nested."""
59 | yield 5
| ^^^^^^^ DOC402
60 |
61 | print("I never yield")
|

DOC402_google.py:67:5: DOC402 `yield` is not documented in docstring
|
65 | def test():
66 | """Do something."""
67 | yield from range(10)
| ^^^^^^^^^^^^^^^^^^^^ DOC402
|
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: crates/ruff_linter/src/rules/pydoclint/mod.rs
---
DOC402_numpy.py:11:5: DOC402 `yield` is not documented in docstring
|
9 | A number
10 | """
11 | yield 'test'
| ^^^^^^^^^^^^ DOC402
|

DOC402_numpy.py:62:9: DOC402 `yield` is not documented in docstring
|
60 | A number
61 | """
62 | yield 'test'
| ^^^^^^^^^^^^ DOC402
|

0 comments on commit 8cd1d0a

Please sign in to comment.