Skip to content

Commit a6ea2ff

Browse files
[primer] Add a test for truncating comments
1 parent dcaf178 commit a6ea2ff

File tree

2 files changed

+57
-14
lines changed

2 files changed

+57
-14
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
🤖 **Effect of this PR on checked open source code:** 🤖
2+
3+
4+
5+
**Effect on [astroid](https://github.com/PyCQA/astroid):**
6+
The following messages are now emitted:
7+
8+
<details>
9+
10+
1) locally-disabled:
11+
*Locally disabling redefined-builtin [we added some text in the message] (W0622)*
12+
https://github.com/PyCQA/astroid/blob/main/astroid/__init__.py#L91
13+
14+
</details>
15+
16+
The fol...
17+
18+
*This comment was truncated because GitHub allows only 500 characters in a comment.*
19+
20+
*This comment was generated for commit v2.14.2*

tests/testutils/_primer/test_primer.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@
2020

2121
PRIMER_CURRENT_INTERPRETER = (3, 10)
2222

23-
24-
@pytest.mark.skipif(
25-
sys.platform in {"win32", "darwin"},
26-
reason="Primers are internal will never be run on costly github action (mac or windows)",
23+
OS_SKIP_REASON = (
24+
"Primers are internal will never be run on costly github action (mac or windows)"
2725
)
28-
@pytest.mark.skipif(
29-
sys.version_info[:2] != PRIMER_CURRENT_INTERPRETER or IS_PYPY,
30-
reason=f"Primers are internal will always be run for only one interpreter (currently {PRIMER_CURRENT_INTERPRETER})",
26+
INTERPRETER_SKIP_REASON = (
27+
"Primers are internal will always be run for only one interpreter (currently"
28+
f" {PRIMER_CURRENT_INTERPRETER})"
3129
)
30+
31+
NOT_PRIMER_OS = sys.platform in {"win32", "darwin"}
32+
NOT_PRIMER_INTERPRETER = sys.version_info[:2] != PRIMER_CURRENT_INTERPRETER or IS_PYPY
33+
DEFAULT_ARGS = ["python tests/primer/__main__.py", "compare", "--commit=v2.14.2"]
34+
35+
36+
@pytest.mark.skipif(NOT_PRIMER_OS, reason=OS_SKIP_REASON)
37+
@pytest.mark.skipif(NOT_PRIMER_INTERPRETER, reason=INTERPRETER_SKIP_REASON)
3238
@pytest.mark.parametrize(
3339
"directory",
3440
[
@@ -41,13 +47,7 @@ def test_compare(directory: Path) -> None:
4147
main = directory / "main.json"
4248
pr = directory / "pr.json"
4349
expected_file = directory / "expected.txt"
44-
new_argv = [
45-
"python tests/primer/__main__.py",
46-
"compare",
47-
"--commit=v2.14.2",
48-
f"--base-file={main}",
49-
f"--new-file={pr}",
50-
]
50+
new_argv = DEFAULT_ARGS + [f"--base-file={main}", f"--new-file={pr}"]
5151
with patch("sys.argv", new_argv):
5252
Primer(PRIMER_DIRECTORY, PACKAGES_TO_PRIME_PATH).run()
5353
with open(PRIMER_DIRECTORY / "comment.txt", encoding="utf8") as f:
@@ -56,3 +56,26 @@ def test_compare(directory: Path) -> None:
5656
expected = f.read()
5757
# rstrip so the expected.txt can end with a newline
5858
assert content == expected.rstrip("\n")
59+
60+
61+
@pytest.mark.skipif(NOT_PRIMER_OS, reason=OS_SKIP_REASON)
62+
@pytest.mark.skipif(NOT_PRIMER_INTERPRETER, reason=INTERPRETER_SKIP_REASON)
63+
def test_truncated_compare() -> None:
64+
FAKE_MAX_GITHUB_COMMENT_LENGTH = 500
65+
main = FIXTURES_PATH / "message_changed/main.json"
66+
pr = FIXTURES_PATH / "message_changed/pr.json"
67+
expected_file = FIXTURES_PATH / "message_changed/expected_truncated.txt"
68+
new_argv = DEFAULT_ARGS + [f"--base-file={main}", f"--new-file={pr}"]
69+
with patch("sys.argv", new_argv):
70+
with patch(
71+
"pylint.testutils._primer.primer_compare_command.MAX_GITHUB_COMMENT_LENGTH",
72+
FAKE_MAX_GITHUB_COMMENT_LENGTH,
73+
):
74+
Primer(PRIMER_DIRECTORY, PACKAGES_TO_PRIME_PATH).run()
75+
with open(PRIMER_DIRECTORY / "comment.txt", encoding="utf8") as f:
76+
content = f.read()
77+
assert len(content) < FAKE_MAX_GITHUB_COMMENT_LENGTH
78+
with open(expected_file, encoding="utf8") as f:
79+
expected = f.read()
80+
# rstrip so the expected.txt can end with a newline
81+
assert content == expected.rstrip("\n")

0 commit comments

Comments
 (0)