@@ -2422,27 +2422,51 @@ def test_extend_exclude(self) -> None:
2422
2422
2423
2423
@pytest .mark .incompatible_with_mypyc
2424
2424
def test_symlinks (self ) -> None :
2425
- path = MagicMock ()
2426
2425
root = THIS_DIR .resolve ()
2427
2426
include = re .compile (black .DEFAULT_INCLUDES )
2428
2427
exclude = re .compile (black .DEFAULT_EXCLUDES )
2429
2428
report = black .Report ()
2430
2429
gitignore = PathSpec .from_lines ("gitwildmatch" , [])
2431
2430
2432
2431
regular = MagicMock ()
2433
- outside_root_symlink = MagicMock ()
2434
- ignored_symlink = MagicMock ()
2435
-
2436
- path .iterdir .return_value = [regular , outside_root_symlink , ignored_symlink ]
2437
-
2438
2432
regular .absolute .return_value = root / "regular.py"
2439
2433
regular .resolve .return_value = root / "regular.py"
2440
2434
regular .is_dir .return_value = False
2435
+ regular .is_file .return_value = True
2441
2436
2437
+ outside_root_symlink = MagicMock ()
2442
2438
outside_root_symlink .absolute .return_value = root / "symlink.py"
2443
2439
outside_root_symlink .resolve .return_value = Path ("/nowhere" )
2440
+ outside_root_symlink .is_dir .return_value = False
2441
+ outside_root_symlink .is_file .return_value = True
2444
2442
2443
+ ignored_symlink = MagicMock ()
2445
2444
ignored_symlink .absolute .return_value = root / ".mypy_cache" / "symlink.py"
2445
+ ignored_symlink .is_dir .return_value = False
2446
+ ignored_symlink .is_file .return_value = True
2447
+
2448
+ # A symlink that has an excluded name, but points to an included name
2449
+ symlink_excluded_name = MagicMock ()
2450
+ symlink_excluded_name .absolute .return_value = root / "excluded_name"
2451
+ symlink_excluded_name .resolve .return_value = root / "included_name.py"
2452
+ symlink_excluded_name .is_dir .return_value = False
2453
+ symlink_excluded_name .is_file .return_value = True
2454
+
2455
+ # A symlink that has an included name, but points to an excluded name
2456
+ symlink_included_name = MagicMock ()
2457
+ symlink_included_name .absolute .return_value = root / "included_name.py"
2458
+ symlink_included_name .resolve .return_value = root / "excluded_name"
2459
+ symlink_included_name .is_dir .return_value = False
2460
+ symlink_included_name .is_file .return_value = True
2461
+
2462
+ path = MagicMock ()
2463
+ path .iterdir .return_value = [
2464
+ regular ,
2465
+ outside_root_symlink ,
2466
+ ignored_symlink ,
2467
+ symlink_excluded_name ,
2468
+ symlink_included_name ,
2469
+ ]
2446
2470
2447
2471
files = list (
2448
2472
black .gen_python_files (
@@ -2458,7 +2482,7 @@ def test_symlinks(self) -> None:
2458
2482
quiet = False ,
2459
2483
)
2460
2484
)
2461
- assert files == [regular ]
2485
+ assert files == [regular , symlink_included_name ]
2462
2486
2463
2487
path .iterdir .assert_called_once ()
2464
2488
outside_root_symlink .resolve .assert_called_once ()
0 commit comments