Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 16 additions & 8 deletions pylint/testutils/_primer/primer_compare_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,15 +73,15 @@ def _create_comment_for_package(
)
if new_non_astroid_messages:
comment += (
"The following messages are now emitted:\n\n<details>\n\n"
"The following messages are now emitted:\n\n<details>\n"
+ new_non_astroid_messages
+ "\n</details>\n\n"
+ "</details>\n\n"
)

# Create comment for missing messages
count = 1
if missing_messages["messages"]:
comment += "The following messages are no longer emitted:\n\n<details>\n\n"
comment += "The following messages are no longer emitted:\n\n<details>\n"
print("No longer emitted:")
for message in missing_messages["messages"]:
comment += f"{count}) {message['symbol']}:\n*{message['message']}*\n"
Expand All @@ -99,8 +99,8 @@ def _create_comment_for_package(
)
count += 1
print(message)
if missing_messages:
comment += "\n</details>\n\n"
if missing_messages["messages"]:
comment += "</details>\n\n"
return comment

def _truncate_comment(self, comment: str) -> str:
Expand All @@ -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 </details> closing tag.
suffix = f"\n{truncation_information}\n\n"
closing_tag = "</details>\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 <details> tag left open by the truncation.
if comment.count("<details>") > comment.count("</details>"):
comment += closing_tag
comment += suffix
comment += hash_information
return comment
4 changes: 1 addition & 3 deletions tests/testutils/_primer/batched_cases/expected.txt
Original file line number Diff line number Diff line change
@@ -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:

<details>

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

</details>

*This comment was generated for commit v2.14.2*
6 changes: 1 addition & 5 deletions tests/testutils/_primer/cases/message_changed/expected.txt
Original file line number Diff line number Diff line change
@@ -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:

<details>

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

</details>

The following messages are no longer emitted:

<details>

1) locally-disabled:
*Locally disabling redefined-builtin (W0622)*
https://github.com/pylint-dev/astroid/blob/123456789abcdef/astroid/__init__.py#L91

</details>

*This comment was generated for commit v2.14.2*
Original file line number Diff line number Diff line change
@@ -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:

<details>

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

</details>

The followi...
...

*This comment was truncated because GitHub allows only 525 characters in a comment.*

Expand Down
Original file line number Diff line number Diff line change
@@ -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:

<details>
1) locally-disabled:
*Locally disabling redefined-builtin [we added some text in the message...
</details>
Comment on lines +8 to +11
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would not have been closed properly previousely.


*This comment was truncated because GitHub allows only 420 characters in a comment.*

*This comment was generated for commit v2.14.2*
7 changes: 1 addition & 6 deletions tests/testutils/_primer/cases/new_message/expected.txt
Original file line number Diff line number Diff line change
@@ -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:

<details>

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

</details>


Comment on lines -13 to -16
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual bug, everything else is "style"

</details>

*This comment was generated for commit v2.14.2*
4 changes: 1 addition & 3 deletions tests/testutils/_primer/cases/removed_message/expected.txt
Original file line number Diff line number Diff line change
@@ -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:

<details>

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

</details>

*This comment was generated for commit v2.14.2*
13 changes: 13 additions & 0 deletions tests/testutils/_primer/test_primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading