@@ -149,8 +149,8 @@ def test_render_templates(self):
149149 for view in views :
150150 try :
151151 self .env ['ir.qweb' ]._render (view .id )
152- except Exception :
153- errors .append ("View %s cannot be rendered" % view .key )
152+ except Exception as e : # noqa: BLE001
153+ errors .append ("View %s cannot be rendered (%r) " % ( view .key , e ) )
154154 _logger .info ("Tested %s views" , len (view_ids ))
155155 self .assertGreater (len (view_ids ), 1250 , "Test should have encountered a lot of views" )
156156 self .assertFalse (errors , "No error should have been collected" )
@@ -186,30 +186,47 @@ def check(theme_name, website):
186186 if blocks_el :
187187 # Only look at blocks in website.snippets
188188 html_tree = blocks_el [0 ]
189+
189190 for el in html_tree .xpath ('//*[@class]' ):
190191 classes = el .attrib ['class' ].split ()
191192 classes_inventory .update (classes )
192193 if len (classes ) != len (set (classes )):
193- errors .append ("Using %r, view %r contains duplicate classes: %r" % (theme_name , view .key , classes ))
194+ errors .append (
195+ "Using %r, view %r contains duplicate classes: %r"
196+ % (theme_name , view .key , classes )
197+ )
194198 for conflicting_classes in CONFLICTUAL_CLASSES :
195199 conflict = set (classes ).intersection (conflicting_classes )
196200 if len (conflict ) > 1 :
197- errors .append ("Using %r, view %r contains conflicting classes: %r in %r" % (theme_name , view .key , conflict , classes ))
198- for conflicting_classes_re in CONFLICTUAL_CLASSES_RE :
199- conflict = {cl for cl in filter (conflicting_classes_re .findall , set (classes ))}
200- white_list = CONFLICTUAL_CLASSES_RE [conflicting_classes_re ]
201+ errors .append (
202+ "Using %r, view %r contains conflicting classes: %r in %r"
203+ % (theme_name , view .key , conflict , classes )
204+ )
205+ for conflicting_classes_re , white_list in CONFLICTUAL_CLASSES_RE .items ():
206+ conflict = set (filter (conflicting_classes_re .findall , set (classes )))
201207 conflict .difference_update (white_list )
202208 if len (conflict ) > 1 :
203- errors .append ("Using %r, view %r contains conflicting classes: %r in %r (according to pattern %r)" % (theme_name , view .key , conflict , classes , conflicting_classes_re .pattern ))
209+ errors .append (
210+ "Using %r, view %r contains conflicting classes: %r in %r (according to pattern %r)"
211+ % (theme_name , view .key , conflict , classes , conflicting_classes_re .pattern )
212+ )
213+
204214 for el in html_tree .xpath ('//*[@style]' ):
205215 styles = el .attrib ['style' ].split (';' )
206216 non_empty_styles = filter (lambda style : style , styles )
207- property_names = list ( map ( lambda style : style .split (':' )[0 ].strip (), non_empty_styles ))
217+ property_names = [ style .split (':' )[0 ].strip () for style in non_empty_styles ]
208218 if len (property_names ) != len (set (property_names )):
209- errors .append ("Using %r, view %r contains duplicate style properties: %r" % (theme_name , view .key , el .attrib ['style' ]))
219+ errors .append (
220+ "Using %r, view %r contains duplicate style properties: %r"
221+ % (theme_name , view .key , el .attrib ['style' ])
222+ )
223+
210224 for grid_el in html_tree .xpath ("//div[contains(concat(' ', normalize-space(@class), ' '), ' o_grid_mode ')]" ):
211225 if 'data-row-count' not in grid_el .attrib :
212- errors .append ("Using %r, view %r defines a grid mode row without row count" % (theme_name , view .key ))
226+ errors .append (
227+ "Using %r, view %r defines a grid mode row without row count"
228+ % (theme_name , view .key )
229+ )
213230 continue
214231 row_count = int (grid_el .attrib ['data-row-count' ])
215232 max_row = 0
@@ -218,32 +235,54 @@ def check(theme_name, website):
218235 styles = item_el .attrib ['style' ].split (';' )
219236 grid_area_style = list (filter (lambda style : style .strip ().startswith ('grid-area:' ), styles ))
220237 if not grid_area_style :
221- errors .append ("Using %r, view %r does not specify a grid-area for its grid item" % (theme_name , view .key ))
238+ errors .append (
239+ "Using %r, view %r does not specify a grid-area for its grid item"
240+ % (theme_name , view .key )
241+ )
222242 continue
223243 grid_area = grid_area_style [0 ].split (':' )[1 ].strip ()
224244 top , left , bottom , right = map (int , grid_area .split ('/' ))
225245 max_row = max (max_row , bottom )
226246 height_class = f'g-height-{ bottom - top } '
227247 if height_class not in classes :
228- errors .append ("Using %r, view %r does not specify %r for grid item %r (%r)" % (theme_name , view .key , height_class , grid_area , classes ))
248+ errors .append (
249+ "Using %r, view %r does not specify %r for grid item %r (%r)"
250+ % (theme_name , view .key , height_class , grid_area , classes )
251+ )
229252 width_class = f'g-col-lg-{ right - left } '
230253 if width_class not in classes :
231- errors .append ("Using %r, view %r does not specify %r for grid item %r (%r)" % (theme_name , view .key , width_class , grid_area , classes ))
254+ errors .append (
255+ "Using %r, view %r does not specify %r for grid item %r (%r)"
256+ % (theme_name , view .key , width_class , grid_area , classes )
257+ )
232258 non_grid_width_class = f'col-lg-{ right - left } '
233259 if non_grid_width_class not in classes :
234- errors .append ("Using %r, view %r does not specify %r for grid item %r (%r)" % (theme_name , view .key , non_grid_width_class , grid_area , classes ))
235- padding_classes = list (filter (lambda klass : klass .startswith ('pb' ) or klass .startswith ('pt' ), classes ))
260+ errors .append (
261+ "Using %r, view %r does not specify %r for grid item %r (%r)"
262+ % (theme_name , view .key , non_grid_width_class , grid_area , classes )
263+ )
264+ padding_classes = list (filter (lambda klass : klass .startswith (('pb' , 'pt' )), classes ))
236265 if padding_classes :
237- errors .append ("Using %r, view %r specifies unnecessary padding classes on grid item %r" % (theme_name , view .key , padding_classes ))
266+ errors .append (
267+ "Using %r, view %r specifies unnecessary padding classes on grid item %r"
268+ % (theme_name , view .key , padding_classes )
269+ )
238270 if row_count != max_row - 1 :
239- errors .append ("Using %r, view %r defines %r as row count while %r is reached" % (theme_name , view .key , row_count , max_row ))
271+ errors .append (
272+ "Using %r, view %r defines %r as row count while %r is reached"
273+ % (theme_name , view .key , row_count , max_row )
274+ )
275+
240276 for el in html_tree .xpath ('//*[@data-row-count]' ):
241277 classes = el .attrib ['class' ].split ()
242278 if 'o_grid_mode' not in classes :
243- errors .append ("Using %r, view %r defines a row count on a non-grid mode row" % (theme_name , view .key ))
244- except Exception :
245- _logger .error ("Using %r, view %r cannot be rendered" , theme_name , view .key )
246- errors .append ("Using %r, view %r cannot be rendered" % (theme_name , view .key ))
279+ errors .append (
280+ "Using %r, view %r defines a row count on a non-grid mode row"
281+ % (theme_name , view .key )
282+ )
283+ except Exception as e : # noqa: BLE001
284+ _logger .error ("Using %r, view %r cannot be rendered (%r)" , theme_name , view .key , e )
285+ errors .append ("Using %r, view %r cannot be rendered (%r)" % (theme_name , view .key , e ))
247286 return len (views )
248287
249288 view_count += check ('no theme' , self .env .ref ('website.default_website' ))
@@ -258,8 +297,8 @@ def check(theme_name, website):
258297 for known_classes in CONFLICTUAL_CLASSES_RE .values ():
259298 classes_inventory .difference_update (known_classes )
260299 for known_classes_re in CONFLICTUAL_CLASSES_RE :
261- classes_inventory = [ cl for cl in filter (lambda cl : not known_classes_re .findall (cl ), classes_inventory )]
262- _logger .info ("Unknown classes encountered: %r" , sorted (list ( classes_inventory ) ))
300+ classes_inventory = list ( filter (lambda cl : not known_classes_re .findall (cl ), classes_inventory ))
301+ _logger .info ("Unknown classes encountered: %r" , sorted (classes_inventory ))
263302 self .assertFalse (errors , "No error should have been collected" )
264303
265304 def test_attribute_separator (self ):
@@ -273,7 +312,7 @@ def test_attribute_separator(self):
273312 errors = []
274313 view_count = 0
275314
276- for module_name in ['website' , * map ( lambda website : website .theme_id .name , self .env ['website' ].get_test_themes_websites ())]:
315+ for module_name in ['website' , * ( website .theme_id .name for website in self .env ['website' ].get_test_themes_websites ())]:
277316 views = View .search ([
278317 '|' , '|' ,
279318 ('key' , 'like' , escape_psql (f'{ module_name } .s_' )),
@@ -293,7 +332,10 @@ def test_attribute_separator(self):
293332 current_separator = el .attrib .get ('separator' , ',' )
294333 expected_separator = ATTRIBUTE_SEPARATORS [attribute_name ]
295334 if current_separator != expected_separator :
296- errors .append ("Using %r, view %r uses separator %r to modify attribute %r" % (module_name , view .key , current_separator , attribute_name ))
335+ errors .append (
336+ "Using %r, view %r uses separator %r to modify attribute %r"
337+ % (module_name , view .key , current_separator , attribute_name )
338+ )
297339 view_count += len (views )
298340
299341 _logger .info ("Tested %s views" , view_count )
0 commit comments