@@ -125,13 +125,86 @@ def test_main_commits_error_and_internal(self):
125
125
code = self .v .main ()
126
126
self .assertEqual (code , 1 )
127
127
128
+ def test_main_title_and_body_missing_in_payload (self ):
129
+ # No payload at all
130
+ with mock .patch .object (sys , 'argv' , ["prog" , "--checks" , "title" , "--verbose" ]):
131
+ os .environ .pop ("GITHUB_EVENT_PATH" , None )
132
+ code = self .v .main ()
133
+ self .assertEqual (code , 1 )
134
+ # Payload present but missing title/body triggers error printing branch
135
+ data = {"pull_request" : {"number" : 5 , "title" : "Иванов Иван Иванович — задача" , "body" : "## 1. Full name and group\n Name and group: \n " }}
136
+ with tempfile .NamedTemporaryFile ("w+" , delete = False ) as tf :
137
+ json .dump (data , tf )
138
+ path = tf .name
139
+ try :
140
+ with mock .patch .object (sys , 'argv' , ["prog" , "--checks" , "title" , "--verbose" ]):
141
+ os .environ ["GITHUB_EVENT_PATH" ] = path
142
+ code = self .v .main ()
143
+ self .assertEqual (code , 1 )
144
+ with mock .patch .object (sys , 'argv' , ["prog" , "--checks" , "body" , "--verbose" ]):
145
+ os .environ ["GITHUB_EVENT_PATH" ] = path
146
+ code = self .v .main ()
147
+ self .assertEqual (code , 1 )
148
+ finally :
149
+ os .unlink (path )
150
+
128
151
# Now raise an internal error
129
152
with mock .patch .object (sys , 'argv' , ["prog" , "--checks" , "commits" , "--repo" , "o/r" , "--pr" , "1" ]):
130
153
os .environ ["GITHUB_TOKEN" ] = "token"
131
154
with mock .patch .object (self .v , "fetch_pr_commits" , side_effect = RuntimeError ("boom" )):
132
155
code = self .v .main ()
133
156
self .assertEqual (code , 2 )
134
157
158
+ def test_main_body_none_and_ok (self ):
159
+ v = _import_validator ()
160
+ # Body None path (no payload)
161
+ with mock .patch .object (sys , 'argv' , ["prog" , "--checks" , "body" , "--verbose" ]):
162
+ os .environ .pop ("GITHUB_EVENT_PATH" , None )
163
+ code = v .main ()
164
+ self .assertEqual (code , 1 )
165
+ # Body OK path
166
+ body = (
167
+ "## 1. Full name and group\n Name and group: A\n \n "
168
+ "## 2. Assignment / Topic / Task\n Assignment: A\n \n "
169
+ "## 3. Technology / Platform used\n Technology: omp\n \n "
170
+ "## 4. Goals of the work\n Goals: A\n \n "
171
+ "## 5. Solution description and structure\n Description: A\n \n "
172
+ "## 6. System requirements and build instructions\n Build & Run: A\n \n "
173
+ "## 7. Testing and verification\n Testing: A\n \n "
174
+ "## 8. Results\n Results: A\n \n "
175
+ "## 9. Performance analysis\n Analysis: A\n \n "
176
+ "## 10. Conclusions and possible improvements\n Conclusions: A\n \n "
177
+ "## 11. Limitations / known issues\n Limitations: A\n \n "
178
+ "## 12. CI / static analysis / code style\n CI & Style: A\n "
179
+ )
180
+ data = {"pull_request" : {"number" : 7 , "title" : "x" , "body" : body }}
181
+ with tempfile .NamedTemporaryFile ("w+" , delete = False ) as tf :
182
+ json .dump (data , tf )
183
+ path = tf .name
184
+ try :
185
+ with mock .patch .object (sys , 'argv' , ["prog" , "--checks" , "body" , "--verbose" ]):
186
+ os .environ ["GITHUB_EVENT_PATH" ] = path
187
+ code = v .main ()
188
+ self .assertEqual (code , 0 )
189
+ finally :
190
+ os .unlink (path )
191
+
192
+ def test_main_title_print_branch_else (self ):
193
+ v = _import_validator ()
194
+ data = {"pull_request" : {"number" : 8 , "title" : "bad" , "body" : "" }}
195
+ with tempfile .NamedTemporaryFile ("w+" , delete = False ) as tf :
196
+ json .dump (data , tf )
197
+ path = tf .name
198
+ try :
199
+ with mock .patch .object (sys , 'argv' , ["prog" , "--checks" , "title" ]):
200
+ # Force errs starting with '✗' to hit print(e)
201
+ with mock .patch .object (v , 'validate_title' , return_value = ["✗ forced-error" ]):
202
+ os .environ ["GITHUB_EVENT_PATH" ] = path
203
+ code = v .main ()
204
+ self .assertEqual (code , 1 )
205
+ finally :
206
+ os .unlink (path )
207
+
135
208
136
209
class TestRunAsMain (unittest .TestCase ):
137
210
def test_run_module_as_main_with_verbose (self ):
@@ -171,6 +244,24 @@ def test_run_module_as_main_with_verbose(self):
171
244
finally :
172
245
os .unlink (path )
173
246
247
+ def test_systemexit_branch_in_try (self ):
248
+ # Force validate_title to raise SystemExit inside try block to hit 'except SystemExit: raise'
249
+ v = _import_validator ()
250
+ with mock .patch .object (sys , 'argv' , ["prog" , "--checks" , "title" ]):
251
+ with mock .patch .object (v , 'validate_title' , side_effect = SystemExit (5 )):
252
+ # Provide minimal payload with title
253
+ data = {"pull_request" : {"number" : 1 , "title" : "bad" , "body" : "" }}
254
+ with tempfile .NamedTemporaryFile ("w+" , delete = False ) as tf :
255
+ json .dump (data , tf )
256
+ path = tf .name
257
+ try :
258
+ os .environ ["GITHUB_EVENT_PATH" ] = path
259
+ with self .assertRaises (SystemExit ) as cm :
260
+ v .main ()
261
+ self .assertEqual (cm .exception .code , 5 )
262
+ finally :
263
+ os .unlink (path )
264
+
174
265
175
266
if __name__ == "__main__" :
176
267
unittest .main (verbosity = 2 )
0 commit comments