@@ -99,6 +99,7 @@ class LeafType(Enum):
9999 """This class stores test item path types."""
100100
101101 DIR = auto ()
102+ FILE = auto ()
102103 CODE = auto ()
103104 ROOT = auto ()
104105
@@ -270,28 +271,37 @@ def _build_test_tree(self, session: Session) -> Dict[str, Any]:
270271 children_leafs = current_leaf ['children' ]
271272
272273 leaf_type = LeafType .DIR
273- if i >= len (dir_path ):
274+ if i == len (dir_path ):
275+ leaf_type = LeafType .FILE
276+ if i > len (dir_path ):
274277 leaf_type = LeafType .CODE
275278
276279 if leaf not in children_leafs :
277280 children_leafs [leaf ] = self ._get_leaf (leaf_type , current_leaf , leaf )
278281 current_leaf = children_leafs [leaf ]
279282 return test_tree
280283
284+ def _remove_node (self , test_tree : Dict [str , Any ], max_dir_level , dir_level , recursive ):
285+ parent_leaf = test_tree ['parent' ]
286+ current_item = test_tree ['item' ]
287+ del parent_leaf ['children' ][current_item ]
288+ for item , child_leaf in test_tree ['children' ].items ():
289+ parent_leaf ['children' ][item ] = child_leaf
290+ child_leaf ['parent' ] = parent_leaf
291+ if recursive :
292+ self ._remove_root_dirs (child_leaf , max_dir_level , dir_level + 1 )
293+
281294 def _remove_root_dirs (self , test_tree : Dict [str , Any ], max_dir_level , dir_level = 0 ) -> None :
282295 if test_tree ['type' ] == LeafType .ROOT :
283- for item , child_leaf in test_tree ['children' ].items ( ):
296+ for child_leaf in list ( test_tree ['children' ].values () ):
284297 self ._remove_root_dirs (child_leaf , max_dir_level , 1 )
285- return
298+ return
286299 if test_tree ['type' ] == LeafType .DIR and dir_level <= max_dir_level :
287- new_level = dir_level + 1
288- parent_leaf = test_tree ['parent' ]
289- current_item = test_tree ['item' ]
290- del parent_leaf ['children' ][current_item ]
291- for item , child_leaf in test_tree ['children' ].items ():
292- parent_leaf ['children' ][item ] = child_leaf
293- child_leaf ['parent' ] = parent_leaf
294- self ._remove_root_dirs (child_leaf , max_dir_level , new_level )
300+ self ._remove_node (test_tree , max_dir_level , dir_level , recursive = True )
301+ return
302+ if test_tree ['type' ] == LeafType .FILE and not self ._config .rp_display_suite_test_file :
303+ self ._remove_node (test_tree , max_dir_level , dir_level , recursive = False )
304+ return
295305
296306 def _generate_names (self , test_tree : Dict [str , Any ]) -> None :
297307 if test_tree ['type' ] == LeafType .ROOT :
@@ -300,7 +310,7 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
300310 if test_tree ['type' ] == LeafType .DIR :
301311 test_tree ['name' ] = test_tree ['item' ].basename
302312
303- if test_tree ['type' ] == LeafType .CODE :
313+ if test_tree ['type' ] in [ LeafType .CODE , LeafType . FILE ] :
304314 item = test_tree ['item' ]
305315 if isinstance (item , Module ):
306316 test_tree ['name' ] = os .path .split (str (item .fspath ))[1 ]
@@ -310,11 +320,11 @@ def _generate_names(self, test_tree: Dict[str, Any]) -> None:
310320 for item , child_leaf in test_tree ['children' ].items ():
311321 self ._generate_names (child_leaf )
312322
313- def _merge_leaf_type (self , test_tree , leaf_type , separator ):
323+ def _merge_leaf_types (self , test_tree , leaf_types , separator ):
314324 child_items = list (test_tree ['children' ].items ())
315- if test_tree ['type' ] != leaf_type :
325+ if test_tree ['type' ] not in leaf_types :
316326 for item , child_leaf in child_items :
317- self ._merge_leaf_type (child_leaf , leaf_type , separator )
327+ self ._merge_leaf_types (child_leaf , leaf_types , separator )
318328 elif len (test_tree ['children' ].items ()) > 0 :
319329 parent_leaf = test_tree ['parent' ]
320330 current_item = test_tree ['item' ]
@@ -325,13 +335,13 @@ def _merge_leaf_type(self, test_tree, leaf_type, separator):
325335 child_leaf ['parent' ] = parent_leaf
326336 child_leaf ['name' ] = \
327337 current_name + separator + child_leaf ['name' ]
328- self ._merge_leaf_type (child_leaf , leaf_type , separator )
338+ self ._merge_leaf_types (child_leaf , leaf_types , separator )
329339
330340 def _merge_dirs (self , test_tree : Dict [str , Any ]) -> None :
331- self ._merge_leaf_type (test_tree , LeafType .DIR , self ._config .rp_dir_path_separator )
341+ self ._merge_leaf_types (test_tree , [ LeafType .DIR ] , self ._config .rp_dir_path_separator )
332342
333343 def _merge_code (self , test_tree : Dict [str , Any ]) -> None :
334- self ._merge_leaf_type (test_tree , LeafType .CODE , '::' )
344+ self ._merge_leaf_types (test_tree , [ LeafType .CODE , LeafType . FILE ] , '::' )
335345
336346 def _build_item_paths (self , leaf : Dict [str , Any ], path : List [Dict [str , Any ]]) -> None :
337347 if 'children' in leaf and len (leaf ['children' ]) > 0 :
0 commit comments