2
2
import pyparsing
3
3
import re
4
4
import unidiff
5
+ from patchtest2 .tests .results import patchtest_result
5
6
6
-
7
- class PatchtestResult :
8
- def __init__ (self , patch , testname , result , reason ):
9
- self .patch = patch
10
- self .testname = testname
11
- self .result = result
12
- self .reason = reason
13
- self .pass_string = f"{ self .result } : { self .testname } on { self .patch } "
14
- self .skip_or_fail_string = (
15
- f"{ self .result } : { self .testname } on { self .patch } ({ self .reason } )"
16
- )
17
-
18
- def __str__ (self ):
19
- if self .result == "PASS" :
20
- return self .pass_string
21
- else :
22
- return self .skip_or_fail_string
23
-
24
-
25
- class PatchtestResults :
26
- def __init__ (self , target_repo , series ):
27
- self .target_repo = target_repo
28
- self .series = series
29
- self .mbox_results = dict (
30
- [
31
- (
32
- "signed_off_by" ,
33
- self ._results (test_mbox_has_signed_off_by ),
34
- ),
35
- (
36
- "shortlog_format" ,
37
- self ._results (test_mbox_shortlog_format ),
38
- ),
39
- (
40
- "shortlog_length" ,
41
- self ._results (test_mbox_shortlog_length ),
42
- ),
43
- (
44
- "has_commit_message" ,
45
- self ._results (test_mbox_has_commit_message ),
46
- ),
47
- (
48
- "diff_parse" ,
49
- self ._results (test_mbox_unidiff_parse_error ),
50
- ),
51
- ]
52
- )
53
-
54
- self .results = dict (
55
- [
56
- (
57
- "mbox" ,
58
- self .mbox_results ,
59
- ),
60
- ]
61
- )
62
-
63
- def _results (self , testname ):
64
- return [testname (patch ) for patch in self .series .patchdata ]
65
-
66
- def _print_result (self , category , tag ):
67
- for value in self .results [category ][tag ]:
68
- print (value )
69
-
70
- def _print_results (self , category ):
71
- for tag in self .results [category ].keys ():
72
- self ._print_result (category , tag )
73
-
74
- def print_results (self ):
75
- for category in self .results .keys ():
76
- self ._print_results (category )
77
-
78
-
79
- # test_for_pattern()
80
- # @pattern: a pyparsing regex object
81
- # @string: a string (patch subject, commit message, author, etc. to
82
- # search for
83
- def test_for_pattern (pattern , string ):
84
- if pattern .search_string (string ):
85
- return "PASS"
86
- else :
87
- return "FAIL"
88
-
89
-
7
+ @patchtest_result
90
8
def test_mbox_has_signed_off_by (target ):
91
- test_name = "test_mbox_has_signed_off_by"
92
- result = test_for_pattern (patterns .signed_off_by , target .commit_message )
9
+ result = "FAIL"
10
+ if patterns .signed_off_by .search_string (target .commit_message ):
11
+ result = "PASS"
93
12
reason = "mbox was missing a signed-off-by tag"
94
- return PatchtestResult (target .subject , test_name , result , reason )
95
-
13
+ return target .subject , result , reason
96
14
15
+ @patchtest_result
97
16
def test_mbox_shortlog_format (target ):
98
- test_name = "test_mbox_shortlog_format"
99
17
result = "PASS"
100
18
reason = None
101
19
if not target .shortlog .strip ():
@@ -112,13 +30,12 @@ def test_mbox_shortlog_format(target):
112
30
result = "FAIL"
113
31
reason = 'Commit shortlog (first line of commit message) should follow the format "<target>: <summary>"'
114
32
115
- return PatchtestResult (target .subject , test_name , result , reason )
116
-
33
+ return target .subject , result , reason
117
34
35
+ @patchtest_result
118
36
def test_mbox_shortlog_length (target ):
119
37
shortlog = re .sub ("^(\[.*?\])+ " , "" , target .shortlog )
120
38
shortlog_len = len (shortlog )
121
- test_name = "test_mbox_shortlog_length"
122
39
result = "PASS"
123
40
reason = f"Edit shortlog so that it is { patterns .mbox_shortlog_maxlength } characters or less (currently { shortlog_len } characters)"
124
41
@@ -130,11 +47,10 @@ def test_mbox_shortlog_length(target):
130
47
if shortlog_len > patterns .mbox_shortlog_maxlength :
131
48
result = "FAIL"
132
49
133
- return PatchtestResult (target .subject , test_name , result , reason )
134
-
50
+ return target .subject , result , reason
135
51
52
+ @patchtest_result
136
53
def test_mbox_has_commit_message (target ):
137
- test_name = "test_mbox_has_commit_message"
138
54
result = "PASS"
139
55
reason = "Please include a commit message on your patch explaining the change"
140
56
@@ -149,11 +65,10 @@ def test_mbox_has_commit_message(target):
149
65
if not commit_lines :
150
66
result = "FAIL"
151
67
152
- return PatchtestResult (target .subject , test_name , result , reason )
153
-
68
+ return target .subject , result , reason
154
69
70
+ @patchtest_result
155
71
def test_mbox_unidiff_parse_error (target ):
156
- test_name = "test_mbox_unidiff_parse_error"
157
72
result = "PASS"
158
73
reason = f'Patch "{ target .shortlog } " contains malformed diff lines.'
159
74
@@ -162,4 +77,4 @@ def test_mbox_unidiff_parse_error(target):
162
77
except unidiff .UnidiffParseError as upe :
163
78
result = "FAIL"
164
79
165
- return PatchtestResult ( target .subject , test_name , result , reason )
80
+ return target .subject , result , reason
0 commit comments