diff --git a/pylint/testutils/_primer/primer_compare_command.py b/pylint/testutils/_primer/primer_compare_command.py index 784574a7ee..05aa83a281 100644 --- a/pylint/testutils/_primer/primer_compare_command.py +++ b/pylint/testutils/_primer/primer_compare_command.py @@ -41,7 +41,7 @@ def _create_comment(self, comparator: Comparator) -> str: def _create_comment_for_package( self, package: str, new_messages: PackageData, missing_messages: PackageData ) -> str: - comment = f"\n\n**Effect on [{package}]({self.packages[package].url}):**\n" + comment = f"\n**Effect on [{package}]({self.packages[package].url}):**\n\n" # Create comment for new messages count = 1 astroid_errors = 0 @@ -73,15 +73,15 @@ def _create_comment_for_package( ) if new_non_astroid_messages: comment += ( - "The following messages are now emitted:\n\n
\n\n" + "The following messages are now emitted:\n\n
\n" + new_non_astroid_messages - + "\n
\n\n" + + "
\n\n" ) # Create comment for missing messages count = 1 if missing_messages["messages"]: - comment += "The following messages are no longer emitted:\n\n
\n\n" + comment += "The following messages are no longer emitted:\n\n
\n" print("No longer emitted:") for message in missing_messages["messages"]: comment += f"{count}) {message['symbol']}:\n*{message['message']}*\n" @@ -99,8 +99,8 @@ def _create_comment_for_package( ) count += 1 print(message) - if missing_messages: - comment += "\n
\n\n" + if missing_messages["messages"]: + comment += "
\n\n" return comment def _truncate_comment(self, comment: str) -> str: @@ -113,11 +113,19 @@ def _truncate_comment(self, comment: str) -> str: f"*This comment was truncated because GitHub allows only" f" {MAX_GITHUB_COMMENT_LENGTH} characters in a comment.*" ) + # Reserve space for the suffix and a potential closing tag. + suffix = f"\n{truncation_information}\n\n" + closing_tag = "\n" max_len = ( MAX_GITHUB_COMMENT_LENGTH - len(hash_information) - - len(truncation_information) + - len(suffix) + - len(closing_tag) ) - comment = f"{comment[:max_len - 10]}...\n\n{truncation_information}\n\n" + comment = comment[: max_len - 10] + "...\n" + # Close any
tag left open by the truncation. + if comment.count("
") > comment.count("
"): + comment += closing_tag + comment += suffix comment += hash_information return comment diff --git a/tests/testutils/_primer/batched_cases/expected.txt b/tests/testutils/_primer/batched_cases/expected.txt index 354d23c4cf..1ebef87989 100644 --- a/tests/testutils/_primer/batched_cases/expected.txt +++ b/tests/testutils/_primer/batched_cases/expected.txt @@ -1,19 +1,17 @@ 🤖 **Effect of this PR on checked open source code:** 🤖 - **Effect on [astroid](https://github.com/pylint-dev/astroid):** + The following messages are no longer emitted:
- 1) locally-disabled: *Locally disabling redefined-builtin (W0622)* https://github.com/pylint-dev/astroid/blob/1234567890abcdef/astroid/__init__.py#L91 2) unknown-option-value: *Unknown option value for 'disable', expected a valid pylint message and got 'Ellipsis'* https://github.com/pylint-dev/astroid/blob/1234567890abcdef/astroid/__init__.py#L91 -
*This comment was generated for commit v2.14.2* diff --git a/tests/testutils/_primer/cases/message_changed/expected.txt b/tests/testutils/_primer/cases/message_changed/expected.txt index 676946fd2e..175a20fc25 100644 --- a/tests/testutils/_primer/cases/message_changed/expected.txt +++ b/tests/testutils/_primer/cases/message_changed/expected.txt @@ -1,26 +1,22 @@ 🤖 **Effect of this PR on checked open source code:** 🤖 - **Effect on [astroid](https://github.com/pylint-dev/astroid):** + The following messages are now emitted:
- 1) locally-disabled: *Locally disabling redefined-builtin [we added some text in the message] (W0622)* https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/__init__.py#L91 -
The following messages are no longer emitted:
- 1) locally-disabled: *Locally disabling redefined-builtin (W0622)* https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/__init__.py#L91 -
*This comment was generated for commit v2.14.2* diff --git a/tests/testutils/_primer/cases/message_changed/expected_truncated.txt b/tests/testutils/_primer/cases/message_changed/expected_truncated.txt index 3882b658f0..63ed5bef91 100644 --- a/tests/testutils/_primer/cases/message_changed/expected_truncated.txt +++ b/tests/testutils/_primer/cases/message_changed/expected_truncated.txt @@ -1,19 +1,16 @@ 🤖 **Effect of this PR on checked open source code:** 🤖 - **Effect on [astroid](https://github.com/pylint-dev/astroid):** + The following messages are now emitted:
- 1) locally-disabled: *Locally disabling redefined-builtin [we added some text in the message] (W0622)* https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/__init__.py#L91 -
- -The followi... +... *This comment was truncated because GitHub allows only 525 characters in a comment.* diff --git a/tests/testutils/_primer/cases/message_changed/expected_truncated_in_details.txt b/tests/testutils/_primer/cases/message_changed/expected_truncated_in_details.txt new file mode 100644 index 0000000000..7357fa3702 --- /dev/null +++ b/tests/testutils/_primer/cases/message_changed/expected_truncated_in_details.txt @@ -0,0 +1,15 @@ +🤖 **Effect of this PR on checked open source code:** 🤖 + + +**Effect on [astroid](https://github.com/pylint-dev/astroid):** + +The following messages are now emitted: + +
+1) locally-disabled: +*Locally disabling redefined-builtin [we added some text in the message... +
+ +*This comment was truncated because GitHub allows only 420 characters in a comment.* + +*This comment was generated for commit v2.14.2* diff --git a/tests/testutils/_primer/cases/new_message/expected.txt b/tests/testutils/_primer/cases/new_message/expected.txt index a78322106a..8e937c0817 100644 --- a/tests/testutils/_primer/cases/new_message/expected.txt +++ b/tests/testutils/_primer/cases/new_message/expected.txt @@ -1,19 +1,14 @@ 🤖 **Effect of this PR on checked open source code:** 🤖 - **Effect on [astroid](https://github.com/pylint-dev/astroid):** + The following messages are now emitted:
- 1) locally-disabled: *Locally disabling redefined-builtin [we added some text in the message] (W0622)* https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/__init__.py#L91 - -
- -
*This comment was generated for commit v2.14.2* diff --git a/tests/testutils/_primer/cases/removed_message/expected.txt b/tests/testutils/_primer/cases/removed_message/expected.txt index 1016296adb..4c2528582a 100644 --- a/tests/testutils/_primer/cases/removed_message/expected.txt +++ b/tests/testutils/_primer/cases/removed_message/expected.txt @@ -1,16 +1,14 @@ 🤖 **Effect of this PR on checked open source code:** 🤖 - **Effect on [astroid](https://github.com/pylint-dev/astroid):** + The following messages are no longer emitted:
- 1) unknown-option-value: *Unknown option value for 'disable', expected a valid pylint message and got 'Ellipsis'* https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/__init__.py#L91 -
*This comment was generated for commit v2.14.2* diff --git a/tests/testutils/_primer/test_primer.py b/tests/testutils/_primer/test_primer.py index 6017d297b4..6350bff46c 100644 --- a/tests/testutils/_primer/test_primer.py +++ b/tests/testutils/_primer/test_primer.py @@ -86,6 +86,19 @@ def test_truncated_compare(self) -> None: ) assert len(content) < max_comment_length + def test_truncated_compare_in_details(self) -> None: + """Test for the truncation of comments that are too long inside details.""" + max_comment_length = 420 + directory = CASES_PATH / "message_changed" + with patch( + "pylint.testutils._primer.primer_compare_command.MAX_GITHUB_COMMENT_LENGTH", + max_comment_length, + ): + content = self.__assert_expected( + directory, expected_file=directory / "expected_truncated_in_details.txt" + ) + assert len(content) < max_comment_length + @staticmethod def __assert_expected( directory: Path,