@@ -2388,6 +2388,27 @@ def test_empty_include(self) -> None:
23882388 # Setting exclude explicitly to an empty string to block .gitignore usage.
23892389 assert_collected_sources (src , expected , include = "" , exclude = "" )
23902390
2391+ def test_include_absolute_path (self ) -> None :
2392+ path = DATA_DIR / "include_exclude_tests"
2393+ src = [path ]
2394+ expected = [
2395+ Path (path / "b/dont_exclude/a.pie" ),
2396+ ]
2397+ assert_collected_sources (
2398+ src , expected , root = path , include = r"^/b/dont_exclude/a\.pie$" , exclude = ""
2399+ )
2400+
2401+ def test_exclude_absolute_path (self ) -> None :
2402+ path = DATA_DIR / "include_exclude_tests"
2403+ src = [path ]
2404+ expected = [
2405+ Path (path / "b/dont_exclude/a.py" ),
2406+ Path (path / "b/.definitely_exclude/a.py" ),
2407+ ]
2408+ assert_collected_sources (
2409+ src , expected , root = path , include = r"\.py$" , exclude = r"^/b/exclude/a\.py$"
2410+ )
2411+
23912412 def test_extend_exclude (self ) -> None :
23922413 path = DATA_DIR / "include_exclude_tests"
23932414 src = [path ]
@@ -2401,27 +2422,51 @@ def test_extend_exclude(self) -> None:
24012422
24022423 @pytest .mark .incompatible_with_mypyc
24032424 def test_symlinks (self ) -> None :
2404- path = MagicMock ()
24052425 root = THIS_DIR .resolve ()
24062426 include = re .compile (black .DEFAULT_INCLUDES )
24072427 exclude = re .compile (black .DEFAULT_EXCLUDES )
24082428 report = black .Report ()
24092429 gitignore = PathSpec .from_lines ("gitwildmatch" , [])
24102430
24112431 regular = MagicMock ()
2412- outside_root_symlink = MagicMock ()
2413- ignored_symlink = MagicMock ()
2414-
2415- path .iterdir .return_value = [regular , outside_root_symlink , ignored_symlink ]
2416-
24172432 regular .absolute .return_value = root / "regular.py"
24182433 regular .resolve .return_value = root / "regular.py"
24192434 regular .is_dir .return_value = False
2435+ regular .is_file .return_value = True
24202436
2437+ outside_root_symlink = MagicMock ()
24212438 outside_root_symlink .absolute .return_value = root / "symlink.py"
24222439 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
24232442
2443+ ignored_symlink = MagicMock ()
24242444 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+ ]
24252470
24262471 files = list (
24272472 black .gen_python_files (
@@ -2437,7 +2482,7 @@ def test_symlinks(self) -> None:
24372482 quiet = False ,
24382483 )
24392484 )
2440- assert files == [regular ]
2485+ assert files == [regular , symlink_included_name ]
24412486
24422487 path .iterdir .assert_called_once ()
24432488 outside_root_symlink .resolve .assert_called_once ()
0 commit comments