@@ -257,3 +257,84 @@ def test_package_name_with_slash(default_config: PyreverseConfig) -> None:
257
257
writer .write ([obj ])
258
258
259
259
assert os .path .exists ("test_package_name_with_slash_.dot" )
260
+
261
+
262
+ def test_should_show_node_no_depth_limit (default_config : PyreverseConfig ) -> None :
263
+ """Test that nodes are shown when no depth limit is set."""
264
+ writer = DiagramWriter (default_config )
265
+ writer .max_depth = None
266
+
267
+ assert writer .should_show_node ("pkg" )
268
+ assert writer .should_show_node ("pkg.subpkg" )
269
+ assert writer .should_show_node ("pkg.subpkg.module" )
270
+ assert writer .should_show_node ("pkg.subpkg.module.submodule" )
271
+
272
+
273
+ @pytest .mark .parametrize ("max_depth" , range (5 ))
274
+ def test_should_show_node_with_depth_limit (
275
+ default_config : PyreverseConfig , max_depth : int
276
+ ) -> None :
277
+ """Test that nodes are filtered correctly when depth limit is set.
278
+
279
+ Depth counting is zero-based, determined by number of dots in path:
280
+ - pkg -> depth 0 (0 dots)
281
+ - pkg.subpkg -> depth 1 (1 dot)
282
+ - pkg.subpkg.module -> depth 2 (2 dots)
283
+ - pkg.subpkg.module.submodule -> depth 3 (3 dots)
284
+ """
285
+ writer = DiagramWriter (default_config )
286
+ print ("max_depth:" , max_depth )
287
+ writer .max_depth = max_depth
288
+
289
+ # Test cases for different depths
290
+ test_cases = [
291
+ "pkg" ,
292
+ "pkg.subpkg" ,
293
+ "pkg.subpkg.module" ,
294
+ "pkg.subpkg.module.submodule" ,
295
+ ]
296
+
297
+ # Test if nodes are shown based on their depth and max_depth setting
298
+ for i , path in enumerate (test_cases ):
299
+ should_show = i <= max_depth
300
+ print (
301
+ f"Path { path } (depth { i } ) with max_depth={ max_depth } "
302
+ f"{ 'should show' if should_show else 'should not show' } :"
303
+ f"{ writer .should_show_node (path , is_class = True )} "
304
+ )
305
+ assert writer .should_show_node (path ) == should_show
306
+
307
+
308
+ @pytest .mark .parametrize ("max_depth" , range (5 ))
309
+ def test_should_show_node_classes (
310
+ default_config : PyreverseConfig , max_depth : int
311
+ ) -> None :
312
+ """Test class visibility based on their containing module depth.
313
+
314
+ Classes are filtered based on their containing module's depth:
315
+ - MyClass -> depth 0 (no module)
316
+ - pkg.MyClass -> depth 0 (module has no dots)
317
+ - pkg.subpkg.MyClass -> depth 1 (module has 1 dot)
318
+ - pkg.subpkg.mod.MyClass -> depth 2 (module has 2 dots)
319
+ """
320
+ writer = DiagramWriter (default_config )
321
+ print ("max_depth:" , max_depth )
322
+ writer .max_depth = max_depth
323
+
324
+ # Test cases for different depths
325
+ test_cases = [
326
+ "MyClass" ,
327
+ "pkg.MyClass" ,
328
+ "pkg.subpkg.MyClass" ,
329
+ "pkg.subpkg.mod.MyClass" ,
330
+ ]
331
+
332
+ # Test if nodes are shown based on their depth and max_depth setting
333
+ for i , path in enumerate (test_cases ):
334
+ should_show = i - 1 <= max_depth # Subtract 1 to account for the class name
335
+ print (
336
+ f"Path { path } (depth { i } ) with max_depth={ max_depth } "
337
+ f"{ 'should show' if should_show else 'should not show' } :"
338
+ f"{ writer .should_show_node (path , is_class = True )} "
339
+ )
340
+ assert writer .should_show_node (path , is_class = True ) == should_show
0 commit comments