-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #7868: Added lint check for a newline above args in python doc string #7929
Changes from 1 commit
5146994
83a2d38
484c110
7779932
fbb4dba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1143,3 +1143,143 @@ def func3(): | |
|
||
with checker_test_object.assertNoMessages(): | ||
temp_file.close() | ||
|
||
|
||
class SingleNewlineAboveArgsCheckerTests(unittest.TestCase): | ||
kevinlee12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def test_checks_newline_above_docstring(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split up this test and more tests with varying combinations of args/returns/raises with and without spaces. (There should be at least 8 cases to cover all of them). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You still haven't split up the tests yet. Specifically, what I mean is to break this method up so that you have multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
checker_test_object = testutils.CheckerTestCase() | ||
checker_test_object.CHECKER_CLASS = ( | ||
pylint_extensions.SingleNewlineAboveArgsChecker) | ||
checker_test_object.setup_method() | ||
node_single_newline_above_args = astroid.scoped_nodes.Module( | ||
name='test', | ||
doc='Custom test') | ||
temp_file = tempfile.NamedTemporaryFile() | ||
filename = temp_file.name | ||
|
||
with python_utils.open_file(filename, 'w') as tmp: | ||
tmp.write( | ||
u"""def func(arg): | ||
'''Returns something. | ||
Args: | ||
arg: argument | ||
Returns: | ||
returns_something | ||
''' | ||
|
||
return returns_something | ||
""") | ||
node_single_newline_above_args.file = filename | ||
node_single_newline_above_args.path = filename | ||
|
||
checker_test_object.checker.process_module( | ||
node_single_newline_above_args) | ||
|
||
with checker_test_object.assertAddsMessages( | ||
testutils.Message( | ||
msg_id='single-space-above-args', | ||
line=2 | ||
), | ||
testutils.Message( | ||
msg_id='single-space-above-args', | ||
line=4 | ||
), | ||
): | ||
temp_file.close() | ||
|
||
node_with_two_newline = astroid.scoped_nodes.Module( | ||
name='test', | ||
doc='Custom test') | ||
|
||
temp_file = tempfile.NamedTemporaryFile() | ||
filename = temp_file.name | ||
with python_utils.open_file(filename, 'w') as tmp: | ||
tmp.write( | ||
u"""def func(arg): | ||
'''Returns something. | ||
|
||
|
||
Args: | ||
arg: argument | ||
|
||
|
||
Returns: | ||
returns_something | ||
''' | ||
returns something | ||
""") | ||
node_with_two_newline.file = filename | ||
node_with_two_newline.path = filename | ||
|
||
checker_test_object.checker.process_module( | ||
node_with_two_newline) | ||
|
||
with checker_test_object.assertAddsMessages( | ||
testutils.Message( | ||
msg_id='single-space-above-args', | ||
line=4 | ||
), | ||
testutils.Message( | ||
msg_id='single-space-above-args', | ||
line=8 | ||
), | ||
): | ||
temp_file.close() | ||
|
||
node_with_return_in_comment = astroid.scoped_nodes.Module( | ||
name='test', | ||
doc='Custom test') | ||
temp_file = tempfile.NamedTemporaryFile() | ||
filename = temp_file.name | ||
|
||
with python_utils.open_file(filename, 'w') as tmp: | ||
tmp.write( | ||
u"""def func(arg): | ||
'''Returns something. | ||
|
||
Args: | ||
arg: argument | ||
|
||
Returns: | ||
returns_something | ||
''' | ||
"Returns: something" | ||
returns_something | ||
""") | ||
node_with_return_in_comment.file = filename | ||
node_with_return_in_comment.path = filename | ||
|
||
checker_test_object.checker.process_module( | ||
node_with_return_in_comment) | ||
|
||
with checker_test_object.assertNoMessages(): | ||
temp_file.close() | ||
|
||
node_with_no_error_message = astroid.scoped_nodes.Module( | ||
name='test', | ||
doc='Custom test') | ||
|
||
temp_file = tempfile.NamedTemporaryFile() | ||
filename = temp_file.name | ||
with python_utils.open_file(filename, 'w') as tmp: | ||
tmp.write( | ||
u"""def func(arg): | ||
'''Returns something. | ||
|
||
Args: | ||
arg: argument | ||
|
||
Returns: | ||
returns_something | ||
''' | ||
|
||
returns_something | ||
""") | ||
node_with_no_error_message.file = filename | ||
node_with_no_error_message.path = filename | ||
|
||
checker_test_object.checker.process_module(node_with_no_error_message) | ||
|
||
with checker_test_object.assertNoMessages(): | ||
temp_file.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single-space-above-args-raises-returns