Method: pylint.testutils.checker_test_case.CheckerTestCase.assertAddsMessages
Calls: 231, Exceptions: 3, Paths: 5Back
Path 1: 162 calls (0.7)
False (162)
tuple (162)
None (162)
1@contextlib.contextmanager
2 def assertAddsMessages(
3 self, *messages: MessageTest, ignore_position: bool = False
4 ) -> Generator[None, None, None]:
5 """Assert that exactly the given method adds the given messages.
6
7 The list of messages must exactly match *all* the messages added by the
8 method. Additionally, we check to see whether the args in each message can
9 actually be substituted into the message string.
10
11 Using the keyword argument `ignore_position`, all checks for position
12 arguments (line, col_offset, ...) will be skipped. This can be used to
13 just test messages for the correct node.
14 """
15 yield
16 got = self.linter.release_messages()
17 no_msg = "No message."
18 expected = "\n".join(repr(m) for m in messages) or no_msg
19 got_str = "\n".join(repr(m) for m in got) or no_msg
20 msg = (
21 "Expected messages did not match actual.\n"
22 f"\nExpected:\n{expected}\n\nGot:\n{got_str}\n"
23 )
24
25 assert len(messages) == len(got), msg
26
27 for expected_msg, gotten_msg in zip(messages, got):
28 assert expected_msg.msg_id == gotten_msg.msg_id, msg
29 assert expected_msg.node == gotten_msg.node, msg
30 assert expected_msg.args == gotten_msg.args, msg
31 assert expected_msg.confidence == gotten_msg.confidence, msg
32
33 if ignore_position:
34 # Do not check for line, col_offset etc...
35 continue
36
37 assert expected_msg.line == gotten_msg.line, msg
38 assert expected_msg.col_offset == gotten_msg.col_offset, msg
39 if PY38_PLUS and not IS_PYPY or PY39_PLUS:
40 # TODO: 3.0: Remove deprecated missing arguments and remove the warning
41 if not expected_msg.end_line == gotten_msg.end_line:
42 warnings.warn( # pragma: no cover
43 f"The end_line attribute of {gotten_msg} does not match "
44 f"the expected value in {expected_msg}. In pylint 3.0 correct end_line "
45 "attributes will be required for MessageTest.",
46 DeprecationWarning,
47 stacklevel=2,
48 )
49 if not expected_msg.end_col_offset == gotten_msg.end_col_offset:
50 warnings.warn( # pragma: no cover
51 f"The end_col_offset attribute of {gotten_msg} does not match "
52 f"the expected value in {expected_msg}. In pylint 3.0 correct end_col_offset "
53 "attributes will be required for MessageTest.",
54 DeprecationWarning,
55 stacklevel=2,
56 )
Path 2: 48 calls (0.21)
False (40) True (8)
() (48)
None (48)
1@contextlib.contextmanager
2 def assertAddsMessages(
3 self, *messages: MessageTest, ignore_position: bool = False
4 ) -> Generator[None, None, None]:
5 """Assert that exactly the given method adds the given messages.
6
7 The list of messages must exactly match *all* the messages added by the
8 method. Additionally, we check to see whether the args in each message can
9 actually be substituted into the message string.
10
11 Using the keyword argument `ignore_position`, all checks for position
12 arguments (line, col_offset, ...) will be skipped. This can be used to
13 just test messages for the correct node.
14 """
15 yield
16 got = self.linter.release_messages()
17 no_msg = "No message."
18 expected = "\n".join(repr(m) for m in messages) or no_msg
19 got_str = "\n".join(repr(m) for m in got) or no_msg
20 msg = (
21 "Expected messages did not match actual.\n"
22 f"\nExpected:\n{expected}\n\nGot:\n{got_str}\n"
23 )
24
25 assert len(messages) == len(got), msg
26
27 for expected_msg, gotten_msg in zip(messages, got):
28 assert expected_msg.msg_id == gotten_msg.msg_id, msg
29 assert expected_msg.node == gotten_msg.node, msg
30 assert expected_msg.args == gotten_msg.args, msg
31 assert expected_msg.confidence == gotten_msg.confidence, msg
32
33 if ignore_position:
34 # Do not check for line, col_offset etc...
35 continue
36
37 assert expected_msg.line == gotten_msg.line, msg
38 assert expected_msg.col_offset == gotten_msg.col_offset, msg
39 if PY38_PLUS and not IS_PYPY or PY39_PLUS:
40 # TODO: 3.0: Remove deprecated missing arguments and remove the warning
41 if not expected_msg.end_line == gotten_msg.end_line:
42 warnings.warn( # pragma: no cover
43 f"The end_line attribute of {gotten_msg} does not match "
44 f"the expected value in {expected_msg}. In pylint 3.0 correct end_line "
45 "attributes will be required for MessageTest.",
46 DeprecationWarning,
47 stacklevel=2,
48 )
49 if not expected_msg.end_col_offset == gotten_msg.end_col_offset:
50 warnings.warn( # pragma: no cover
51 f"The end_col_offset attribute of {gotten_msg} does not match "
52 f"the expected value in {expected_msg}. In pylint 3.0 correct end_col_offset "
53 "attributes will be required for MessageTest.",
54 DeprecationWarning,
55 stacklevel=2,
56 )
Path 3: 18 calls (0.08)
True (18)
tuple (18)
None (18)
1@contextlib.contextmanager
2 def assertAddsMessages(
3 self, *messages: MessageTest, ignore_position: bool = False
4 ) -> Generator[None, None, None]:
5 """Assert that exactly the given method adds the given messages.
6
7 The list of messages must exactly match *all* the messages added by the
8 method. Additionally, we check to see whether the args in each message can
9 actually be substituted into the message string.
10
11 Using the keyword argument `ignore_position`, all checks for position
12 arguments (line, col_offset, ...) will be skipped. This can be used to
13 just test messages for the correct node.
14 """
15 yield
16 got = self.linter.release_messages()
17 no_msg = "No message."
18 expected = "\n".join(repr(m) for m in messages) or no_msg
19 got_str = "\n".join(repr(m) for m in got) or no_msg
20 msg = (
21 "Expected messages did not match actual.\n"
22 f"\nExpected:\n{expected}\n\nGot:\n{got_str}\n"
23 )
24
25 assert len(messages) == len(got), msg
26
27 for expected_msg, gotten_msg in zip(messages, got):
28 assert expected_msg.msg_id == gotten_msg.msg_id, msg
29 assert expected_msg.node == gotten_msg.node, msg
30 assert expected_msg.args == gotten_msg.args, msg
31 assert expected_msg.confidence == gotten_msg.confidence, msg
32
33 if ignore_position:
34 # Do not check for line, col_offset etc...
35 continue
36
37 assert expected_msg.line == gotten_msg.line, msg
38 assert expected_msg.col_offset == gotten_msg.col_offset, msg
39 if PY38_PLUS and not IS_PYPY or PY39_PLUS:
40 # TODO: 3.0: Remove deprecated missing arguments and remove the warning
41 if not expected_msg.end_line == gotten_msg.end_line:
42 warnings.warn( # pragma: no cover
43 f"The end_line attribute of {gotten_msg} does not match "
44 f"the expected value in {expected_msg}. In pylint 3.0 correct end_line "
45 "attributes will be required for MessageTest.",
46 DeprecationWarning,
47 stacklevel=2,
48 )
49 if not expected_msg.end_col_offset == gotten_msg.end_col_offset:
50 warnings.warn( # pragma: no cover
51 f"The end_col_offset attribute of {gotten_msg} does not match "
52 f"the expected value in {expected_msg}. In pylint 3.0 correct end_col_offset "
53 "attributes will be required for MessageTest.",
54 DeprecationWarning,
55 stacklevel=2,
56 )
Path 4: 2 calls (0.01)
False (2)
tuple (2)
None (2)
AssertionError (2)
1@contextlib.contextmanager
2 def assertAddsMessages(
3 self, *messages: MessageTest, ignore_position: bool = False
4 ) -> Generator[None, None, None]:
5 """Assert that exactly the given method adds the given messages.
6
7 The list of messages must exactly match *all* the messages added by the
8 method. Additionally, we check to see whether the args in each message can
9 actually be substituted into the message string.
10
11 Using the keyword argument `ignore_position`, all checks for position
12 arguments (line, col_offset, ...) will be skipped. This can be used to
13 just test messages for the correct node.
14 """
15 yield
16 got = self.linter.release_messages()
17 no_msg = "No message."
18 expected = "\n".join(repr(m) for m in messages) or no_msg
19 got_str = "\n".join(repr(m) for m in got) or no_msg
20 msg = (
21 "Expected messages did not match actual.\n"
22 f"\nExpected:\n{expected}\n\nGot:\n{got_str}\n"
23 )
24
25 assert len(messages) == len(got), msg
26
27 for expected_msg, gotten_msg in zip(messages, got):
28 assert expected_msg.msg_id == gotten_msg.msg_id, msg
29 assert expected_msg.node == gotten_msg.node, msg
30 assert expected_msg.args == gotten_msg.args, msg
31 assert expected_msg.confidence == gotten_msg.confidence, msg
32
33 if ignore_position:
34 # Do not check for line, col_offset etc...
35 continue
36
37 assert expected_msg.line == gotten_msg.line, msg
38 assert expected_msg.col_offset == gotten_msg.col_offset, msg
39 if PY38_PLUS and not IS_PYPY or PY39_PLUS:
40 # TODO: 3.0: Remove deprecated missing arguments and remove the warning
41 if not expected_msg.end_line == gotten_msg.end_line:
42 warnings.warn( # pragma: no cover
43 f"The end_line attribute of {gotten_msg} does not match "
44 f"the expected value in {expected_msg}. In pylint 3.0 correct end_line "
45 "attributes will be required for MessageTest.",
46 DeprecationWarning,
47 stacklevel=2,
48 )
49 if not expected_msg.end_col_offset == gotten_msg.end_col_offset:
50 warnings.warn( # pragma: no cover
51 f"The end_col_offset attribute of {gotten_msg} does not match "
52 f"the expected value in {expected_msg}. In pylint 3.0 correct end_col_offset "
53 "attributes will be required for MessageTest.",
54 DeprecationWarning,
55 stacklevel=2,
56 )
Path 5: 1 calls (0.0)
False (1)
tuple (1)
None (1)
AssertionError (1)
1@contextlib.contextmanager
2 def assertAddsMessages(
3 self, *messages: MessageTest, ignore_position: bool = False
4 ) -> Generator[None, None, None]:
5 """Assert that exactly the given method adds the given messages.
6
7 The list of messages must exactly match *all* the messages added by the
8 method. Additionally, we check to see whether the args in each message can
9 actually be substituted into the message string.
10
11 Using the keyword argument `ignore_position`, all checks for position
12 arguments (line, col_offset, ...) will be skipped. This can be used to
13 just test messages for the correct node.
14 """
15 yield
16 got = self.linter.release_messages()
17 no_msg = "No message."
18 expected = "\n".join(repr(m) for m in messages) or no_msg
19 got_str = "\n".join(repr(m) for m in got) or no_msg
20 msg = (
21 "Expected messages did not match actual.\n"
22 f"\nExpected:\n{expected}\n\nGot:\n{got_str}\n"
23 )
24
25 assert len(messages) == len(got), msg
26
27 for expected_msg, gotten_msg in zip(messages, got):
28 assert expected_msg.msg_id == gotten_msg.msg_id, msg
29 assert expected_msg.node == gotten_msg.node, msg
30 assert expected_msg.args == gotten_msg.args, msg
31 assert expected_msg.confidence == gotten_msg.confidence, msg
32
33 if ignore_position:
34 # Do not check for line, col_offset etc...
35 continue
36
37 assert expected_msg.line == gotten_msg.line, msg
38 assert expected_msg.col_offset == gotten_msg.col_offset, msg
39 if PY38_PLUS and not IS_PYPY or PY39_PLUS:
40 # TODO: 3.0: Remove deprecated missing arguments and remove the warning
41 if not expected_msg.end_line == gotten_msg.end_line:
42 warnings.warn( # pragma: no cover
43 f"The end_line attribute of {gotten_msg} does not match "
44 f"the expected value in {expected_msg}. In pylint 3.0 correct end_line "
45 "attributes will be required for MessageTest.",
46 DeprecationWarning,
47 stacklevel=2,
48 )
49 if not expected_msg.end_col_offset == gotten_msg.end_col_offset:
50 warnings.warn( # pragma: no cover
51 f"The end_col_offset attribute of {gotten_msg} does not match "
52 f"the expected value in {expected_msg}. In pylint 3.0 correct end_col_offset "
53 "attributes will be required for MessageTest.",
54 DeprecationWarning,
55 stacklevel=2,
56 )