20
20
21
21
PRIMER_CURRENT_INTERPRETER = (3 , 10 )
22
22
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)"
27
25
)
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 } )"
31
29
)
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 )
32
38
@pytest .mark .parametrize (
33
39
"directory" ,
34
40
[
@@ -41,13 +47,7 @@ def test_compare(directory: Path) -> None:
41
47
main = directory / "main.json"
42
48
pr = directory / "pr.json"
43
49
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 } " ]
51
51
with patch ("sys.argv" , new_argv ):
52
52
Primer (PRIMER_DIRECTORY , PACKAGES_TO_PRIME_PATH ).run ()
53
53
with open (PRIMER_DIRECTORY / "comment.txt" , encoding = "utf8" ) as f :
@@ -56,3 +56,26 @@ def test_compare(directory: Path) -> None:
56
56
expected = f .read ()
57
57
# rstrip so the expected.txt can end with a newline
58
58
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