Skip to content

Commit

Permalink
Fix pylint copyright checker
Browse files Browse the repository at this point in the history
  • Loading branch information
maffoo committed Mar 29, 2022
1 parent 160fd10 commit d5e509a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions dev_tools/pylint_copyright_checker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from astroid import parse
from pylint.testutils import CheckerTestCase, Message
from pylint.testutils import CheckerTestCase, MessageTest

from dev_tools.pylint_copyright_checker import CopyrightChecker

Expand All @@ -27,42 +27,49 @@ def test_missing_copyright(self) -> None:
r"""Report message when no copyright notice at the beginning of a file."""
node = parse("import os")
with self.assertAddsMessages(
Message(
MessageTest(
msg_id='wrong-or-nonexistent-copyright-notice',
line=1,
col_offset=0,
),
):
self.checker.process_module(node)

def test_wrong_copyright(self) -> None:
r"""Report message when the copyright notice is incorrect."""
node = parse("# Copyright 2021 Someone else")
comment = "# Copyright 2021 Someone else"
node = parse(comment)
with self.assertAddsMessages(
Message(
MessageTest(
msg_id='wrong-or-nonexistent-copyright-notice',
line=1,
col_offset=comment.index("Someone"),
),
):
self.checker.process_module(node)

def test_shorter_copyright(self) -> None:
r"""Report message when the copyright notice is incorrect."""
node = parse("# Copyright 2021 The")
comment = "# Copyright 2021 The"
node = parse(comment)
with self.assertAddsMessages(
Message(
MessageTest(
msg_id='wrong-or-nonexistent-copyright-notice',
line=1,
col_offset=len(comment),
),
):
self.checker.process_module(node)

def test_longer_copyright(self) -> None:
r"""Report message when the copyright notice is incorrect."""
node = parse("# Copyright 2021 The Cirq Developers and extra")
comment = "# Copyright 2021 The Cirq Developers and extra"
node = parse(comment)
with self.assertAddsMessages(
Message(
MessageTest(
msg_id='wrong-or-nonexistent-copyright-notice',
line=1,
col_offset=comment.index(" and extra"),
),
):
self.checker.process_module(node)
Expand Down

0 comments on commit d5e509a

Please sign in to comment.