@@ -123,9 +123,17 @@ def read_last_log(compile_type):
123
123
}
124
124
125
125
126
- # Creates a report json after each compile test
127
126
def report_creator (compile_type , log_entry , log_file ):
127
+ """Creates a report json after each compile.
128
+ `logs`: a list in which all log files located in logs directory are added.
129
+ `logs_to_examine`: the list of all log files located in logs directory sorted.
130
+ `tail`: the two most recent logs in logs directory.
131
+ `diff`: a dictionary where all differences between the two logs are stored.
132
+ `changes`: a counter indicating the number of differences found between the two logs.
133
+ """
134
+
128
135
logs = os .listdir (get_path ('logs' ))
136
+
129
137
logs_re = re .compile (r'.+cb_compile_tester.+' )
130
138
if compile_type == 'library' :
131
139
logs_re = re .compile (r'.+libraries_test.+' )
@@ -134,8 +142,10 @@ def report_creator(compile_type, log_entry, log_file):
134
142
elif compile_type == 'target_library' :
135
143
logs_re = re .compile (r'.+target_libraries.+' )
136
144
137
- logs = sorted ([x for x in logs if x != '.gitignore' and logs_re .match (x )])
145
+ logs = sorted ([x for x in logs if logs_re .match (x )])
138
146
tail = logs [- 2 :]
147
+
148
+ # Opens the last, or the last two log files and gathers all their contents.
139
149
logs_to_examine = []
140
150
for log in tail :
141
151
try :
@@ -146,68 +156,75 @@ def report_creator(compile_type, log_entry, log_file):
146
156
147
157
diff = {}
148
158
changes = 0
159
+
160
+ # We have only one log file, it is the first time we run the test.
161
+ if len (logs_to_examine ) == 1 :
162
+ diff = logs_to_examine [0 ]
163
+ changes += 1
164
+
165
+ # We have more than one log files, it is not the first time we run the test.
149
166
if len (logs_to_examine ) >= 2 :
167
+
150
168
old_log = logs_to_examine [0 ]
151
169
new_log = logs_to_examine [1 ]
152
170
171
+ #Iterate over all new_log keys (urls).
153
172
for url in new_log .keys ():
173
+
174
+ # Check if key (url) is included in `old_log`. If not, add an entry to `diff` dictionary.
154
175
if url not in old_log :
155
176
diff [url ] = new_log [url ]
156
177
changes += 1
157
178
continue
158
179
180
+ """Check if log comes from test test_libraries_fetch.py test.
181
+ If yes, we check if the `old_log[url]`value is the same with
182
+ `new_log[url]`value. If not, add an entry to `diff` dictionary."""
159
183
if compile_type == 'fetch' :
160
184
if old_log [url ] != new_log [url ]:
161
185
diff [url ] = new_log [url ]
162
186
changes += 1
163
187
continue
164
188
165
- for result in new_log [url ].keys ():
166
- if result not in old_log [url ]:
167
- if not url in diff :
189
+ """Iterate over all `new_log[url]` keys. Keys can have one of the following
190
+ values: 'success', 'fail', 'open_fail', 'error', 'comment'."""
191
+ for result in new_log [url ].keys ():
192
+
193
+ """Check if for the specific url, result is included in
194
+ `old_log[url]` keys. If not, check if specific url has an entry in
195
+ `diff` dictionary and if not create one. Then add the `result` value.
196
+ e.g. `result`: success
197
+ `old_log[url].keys()`: ['fail', 'success']"""
198
+
199
+ if result not in old_log [url ].keys ():
200
+ if url not in diff :
168
201
diff [url ] = {}
169
202
diff [url ][result ] = new_log [url ][result ]
170
203
changes += 1
171
204
continue
172
205
173
- if result == 'success' or result == 'fail' :
174
- if result not in old_log [url ]:
175
- if not url in diff :
206
+ # Check if for the specific url, the result is `comment` or `open_fail` or `error`.
207
+ if result == 'comment' or result == 'open_fail' or result == 'error' :
208
+ # Check if the value for the specific result is the same in both logs.
209
+ if old_log [url ][result ] != new_log [url ][result ]:
210
+ # Check if the url is on diff dictionary, if not I add it.
211
+ if url not in diff :
176
212
diff [url ] = {}
177
213
diff [url ][result ] = new_log [url ][result ]
178
214
changes += 1
179
- continue
180
215
216
+ # Check if for the specific url, the result is `success` or `fail`.
217
+ elif result == 'success' or result == 'fail' :
181
218
for board in new_log [url ][result ]:
182
- oposite = 'success'
183
- if result == 'success' :
184
- oposite = 'fail'
185
- if oposite in old_log [url ] and board in old_log [url ][oposite ]:
186
- if not url in diff :
219
+ if board not in old_log [url ][result ]:
220
+ if url not in diff :
187
221
diff [url ] = {}
188
222
if result not in diff [url ]:
189
223
diff [url ][result ] = []
190
224
diff [url ][result ].append (board )
191
225
changes += 1
192
- elif result == 'open_fail' or result == 'error' or result == 'comment' :
193
- if result not in old_log [url ]:
194
- if not url in diff :
195
- diff [url ] = {}
196
- diff [url ][result ] = new_log [url ][result ]
197
- changes += 1
198
- continue
199
- if old_log [url ][result ] != new_log [url ][result ]:
200
- if not url in diff :
201
- diff [url ] = {}
202
- diff [url ][result ] = new_log [url ][result ]
203
- changes += 1
204
- elif len (logs_to_examine ) == 1 :
205
- diff = logs_to_examine [0 ]
206
- changes += 1
207
- else :
208
- diff = log_entry
209
- changes += 1
210
226
227
+ #Create report and write the results.
211
228
filename_tokens = os .path .basename (log_file ).split ('.' )
212
229
filename = '.' .join (filename_tokens [0 :- 1 ])
213
230
extension = filename_tokens [- 1 ]
0 commit comments