Skip to content
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

Merged
merged 5 commits into from
Nov 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Split test in modules
  • Loading branch information
Hudda committed Nov 11, 2019
commit fbb4dba59c8940b8e9b438b68eecd9766a2d4fa5
59 changes: 35 additions & 24 deletions scripts/pylint_extensions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,11 +1147,14 @@ def func3():

class SingleNewlineAboveArgsCheckerTests(unittest.TestCase):
kevinlee12 marked this conversation as resolved.
Show resolved Hide resolved

def test_checks_newline_above_docstring(self):
checker_test_object = testutils.CheckerTestCase()
checker_test_object.CHECKER_CLASS = (
def setUp(self):
super(SingleNewlineAboveArgsCheckerTests, self).setUp()
self.checker_test_object = testutils.CheckerTestCase()
self.checker_test_object.CHECKER_CLASS = (
pylint_extensions.SingleNewlineAboveArgsChecker)
checker_test_object.setup_method()
self.checker_test_object.setup_method()

def test_no_newline_above_args(self):
node_single_newline_above_args = astroid.scoped_nodes.Module(
name='test',
doc='Custom test')
Expand All @@ -1170,17 +1173,18 @@ def test_checks_newline_above_docstring(self):
node_single_newline_above_args.file = filename
node_single_newline_above_args.path = filename

checker_test_object.checker.process_module(
self.checker_test_object.checker.process_module(
node_single_newline_above_args)

with checker_test_object.assertAddsMessages(
with self.checker_test_object.assertAddsMessages(
testutils.Message(
msg_id='single-space-above-args',
line=2
),
):
temp_file.close()

def test_no_newline_above_raises(self):
node_single_newline_above_raises = astroid.scoped_nodes.Module(
name='test',
doc='Custom test')
Expand All @@ -1199,17 +1203,18 @@ def test_checks_newline_above_docstring(self):
node_single_newline_above_raises.file = filename
node_single_newline_above_raises.path = filename

checker_test_object.checker.process_module(
self.checker_test_object.checker.process_module(
node_single_newline_above_raises)

with checker_test_object.assertAddsMessages(
with self.checker_test_object.assertAddsMessages(
testutils.Message(
msg_id='single-space-above-raises',
line=2
),
):
temp_file.close()

def test_no_newline_above_return(self):
node_with_no_space_above_return = astroid.scoped_nodes.Module(
name='test',
doc='Custom test')
Expand All @@ -1228,17 +1233,18 @@ def test_checks_newline_above_docstring(self):
node_with_no_space_above_return.file = filename
node_with_no_space_above_return.path = filename

checker_test_object.checker.process_module(
self.checker_test_object.checker.process_module(
node_with_no_space_above_return)

with checker_test_object.assertAddsMessages(
with self.checker_test_object.assertAddsMessages(
testutils.Message(
msg_id='single-space-above-returns',
line=2
),
):
temp_file.close()

def test_varying_combination_of_newline_above_args(self):
node_newline_above_args_raises = astroid.scoped_nodes.Module(
name='test',
doc='Custom test')
Expand All @@ -1260,10 +1266,10 @@ def test_checks_newline_above_docstring(self):
node_newline_above_args_raises.file = filename
node_newline_above_args_raises.path = filename

checker_test_object.checker.process_module(
self.checker_test_object.checker.process_module(
node_newline_above_args_raises)

with checker_test_object.assertAddsMessages(
with self.checker_test_object.assertAddsMessages(
testutils.Message(
msg_id='single-space-above-raises',
line=5
Expand Down Expand Up @@ -1292,10 +1298,10 @@ def test_checks_newline_above_docstring(self):
node_newline_above_args_returns.file = filename
node_newline_above_args_returns.path = filename

checker_test_object.checker.process_module(
self.checker_test_object.checker.process_module(
node_newline_above_args_returns)

with checker_test_object.assertAddsMessages(
with self.checker_test_object.assertAddsMessages(
testutils.Message(
msg_id='single-space-above-returns',
line=5
Expand Down Expand Up @@ -1328,17 +1334,18 @@ def test_checks_newline_above_docstring(self):
node_newline_above_returns_raises.file = filename
node_newline_above_returns_raises.path = filename

checker_test_object.checker.process_module(
self.checker_test_object.checker.process_module(
node_newline_above_returns_raises)

with checker_test_object.assertAddsMessages(
with self.checker_test_object.assertAddsMessages(
testutils.Message(
msg_id='single-space-above-raises',
line=5
),
):
temp_file.close()

def test_excessive_newline_above_args(self):
node_with_two_newline = astroid.scoped_nodes.Module(
name='test',
doc='Custom test')
Expand All @@ -1363,10 +1370,10 @@ def test_checks_newline_above_docstring(self):
node_with_two_newline.file = filename
node_with_two_newline.path = filename

checker_test_object.checker.process_module(
self.checker_test_object.checker.process_module(
node_with_two_newline)

with checker_test_object.assertAddsMessages(
with self.checker_test_object.assertAddsMessages(
testutils.Message(
msg_id='single-space-above-args',
line=4
Expand All @@ -1378,6 +1385,7 @@ def test_checks_newline_above_docstring(self):
):
temp_file.close()

def test_return_in_comment(self):
node_with_return_in_comment = astroid.scoped_nodes.Module(
name='test',
doc='Custom test')
Expand All @@ -1401,12 +1409,13 @@ def test_checks_newline_above_docstring(self):
node_with_return_in_comment.file = filename
node_with_return_in_comment.path = filename

checker_test_object.checker.process_module(
self.checker_test_object.checker.process_module(
node_with_return_in_comment)

with checker_test_object.assertNoMessages():
with self.checker_test_object.assertNoMessages():
temp_file.close()

def test_function_with_no_args(self):
node_with_no_args = astroid.scoped_nodes.Module(
name='test',
doc='Custom test')
Expand All @@ -1422,12 +1431,13 @@ def test_checks_newline_above_docstring(self):
node_with_no_args.file = filename
node_with_no_args.path = filename

checker_test_object.checker.process_module(
self.checker_test_object.checker.process_module(
node_with_no_args)

with checker_test_object.assertNoMessages():
with self.checker_test_object.assertNoMessages():
temp_file.close()

def test_well_placed_newline(self):
node_with_no_error_message = astroid.scoped_nodes.Module(
name='test',
doc='Custom test')
Expand All @@ -1454,7 +1464,8 @@ def test_checks_newline_above_docstring(self):
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)
self.checker_test_object.checker.process_module(
node_with_no_error_message)

with checker_test_object.assertNoMessages():
with self.checker_test_object.assertNoMessages():
temp_file.close()