@@ -100,6 +100,7 @@ class LeafType(Enum):
100100 """This class stores test item path types."""
101101
102102 DIR = auto ()
103+ FILE = auto ()
103104 CODE = auto ()
104105 ROOT = auto ()
105106
@@ -272,28 +273,37 @@ def _build_test_tree(self, session: Session) -> Dict[str, Any]:
272273 children_leafs = current_leaf ['children' ]
273274
274275 leaf_type = LeafType .DIR
275- if i >= len (dir_path ):
276+ if i == len (dir_path ):
277+ leaf_type = LeafType .FILE
278+ if i > len (dir_path ):
276279 leaf_type = LeafType .CODE
277280
278281 if leaf not in children_leafs :
279282 children_leafs [leaf ] = self ._get_leaf (leaf_type , current_leaf , leaf )
280283 current_leaf = children_leafs [leaf ]
281284 return test_tree
282285
286+ def _remove_node (self , test_tree : Dict [str , Any ], max_dir_level , dir_level , recursive ):
287+ parent_leaf = test_tree ['parent' ]
288+ current_item = test_tree ['item' ]
289+ del parent_leaf ['children' ][current_item ]
290+ for item , child_leaf in test_tree ['children' ].items ():
291+ parent_leaf ['children' ][item ] = child_leaf
292+ child_leaf ['parent' ] = parent_leaf
293+ if recursive :
294+ self ._remove_root_dirs (child_leaf , max_dir_level , dir_level + 1 )
295+
283296 def _remove_root_dirs (self , test_tree : Dict [str , Any ], max_dir_level , dir_level = 0 ) -> None :
284297 if test_tree ['type' ] == LeafType .ROOT :
285- for item , child_leaf in test_tree ['children' ].items ( ):
298+ for child_leaf in list ( test_tree ['children' ].values () ):
286299 self ._remove_root_dirs (child_leaf , max_dir_level , 1 )
287- return
300+ return
288301 if test_tree ['type' ] == LeafType .DIR and dir_level <= max_dir_level :
289- new_level = dir_level + 1
290- parent_leaf = test_tree ['parent' ]
291- current_item = test_tree ['item' ]
292- del parent_leaf ['children' ][current_item ]
293- for item , child_leaf in test_tree ['children' ].items ():
294- parent_leaf ['children' ][item ] = child_leaf
295- child_leaf ['parent' ] = parent_leaf
296- self ._remove_root_dirs (child_leaf , max_dir_level , new_level )
302+ self ._remove_node (test_tree , max_dir_level , dir_level , recursive = True )
303+ return
304+ if test_tree ['type' ] == LeafType .FILE and not self ._config .rp_display_suite_test_file :
305+ self ._remove_node (test_tree , max_dir_level , dir_level , recursive = False )
306+ return
297307
298308 def _generate_names (self , test_tree : Dict [str , Any ]) -> None :
299309 if test_tree ['type' ] == LeafType .ROOT :
@@ -302,7 +312,7 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
302312 if test_tree ['type' ] == LeafType .DIR :
303313 test_tree ['name' ] = test_tree ['item' ].basename
304314
305- if test_tree ['type' ] == LeafType .CODE :
315+ if test_tree ['type' ] in [ LeafType .CODE , LeafType . FILE ] :
306316 item = test_tree ['item' ]
307317 if isinstance (item , Module ):
308318 test_tree ['name' ] = os .path .split (str (item .fspath ))[1 ]
@@ -312,11 +322,11 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
312322 for item , child_leaf in test_tree ['children' ].items ():
313323 self ._generate_names (child_leaf )
314324
315- def _merge_leaf_type (self , test_tree , leaf_type , separator ):
325+ def _merge_leaf_types (self , test_tree , leaf_types , separator ):
316326 child_items = list (test_tree ['children' ].items ())
317- if test_tree ['type' ] != leaf_type :
327+ if test_tree ['type' ] not in leaf_types :
318328 for item , child_leaf in child_items :
319- self ._merge_leaf_type (child_leaf , leaf_type , separator )
329+ self ._merge_leaf_types (child_leaf , leaf_types , separator )
320330 elif len (test_tree ['children' ].items ()) > 0 :
321331 parent_leaf = test_tree ['parent' ]
322332 current_item = test_tree ['item' ]
@@ -327,13 +337,13 @@ def _merge_leaf_type(self, test_tree, leaf_type, separator):
327337 child_leaf ['parent' ] = parent_leaf
328338 child_leaf ['name' ] = \
329339 current_name + separator + child_leaf ['name' ]
330- self ._merge_leaf_type (child_leaf , leaf_type , separator )
340+ self ._merge_leaf_types (child_leaf , leaf_types , separator )
331341
332342 def _merge_dirs (self , test_tree : Dict [str , Any ]) -> None :
333- self ._merge_leaf_type (test_tree , LeafType .DIR , self ._config .rp_dir_path_separator )
343+ self ._merge_leaf_types (test_tree , [ LeafType .DIR ] , self ._config .rp_dir_path_separator )
334344
335345 def _merge_code (self , test_tree : Dict [str , Any ]) -> None :
336- self ._merge_leaf_type (test_tree , LeafType .CODE , '::' )
346+ self ._merge_leaf_types (test_tree , [ LeafType .CODE , LeafType . FILE ] , '::' )
337347
338348 def _build_item_paths (self , leaf : Dict [str , Any ], path : List [Dict [str , Any ]]) -> None :
339349 if 'children' in leaf and len (leaf ['children' ]) > 0 :
0 commit comments