Skip to content

Commit 11e6f55

Browse files
committed
Add more cases to symlink inclusion test
1 parent c1fc2e3 commit 11e6f55

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

tests/test_black.py

+31-7
Original file line numberDiff line numberDiff line change
@@ -2422,27 +2422,51 @@ def test_extend_exclude(self) -> None:
24222422

24232423
@pytest.mark.incompatible_with_mypyc
24242424
def test_symlinks(self) -> None:
2425-
path = MagicMock()
24262425
root = THIS_DIR.resolve()
24272426
include = re.compile(black.DEFAULT_INCLUDES)
24282427
exclude = re.compile(black.DEFAULT_EXCLUDES)
24292428
report = black.Report()
24302429
gitignore = PathSpec.from_lines("gitwildmatch", [])
24312430

24322431
regular = MagicMock()
2433-
outside_root_symlink = MagicMock()
2434-
ignored_symlink = MagicMock()
2435-
2436-
path.iterdir.return_value = [regular, outside_root_symlink, ignored_symlink]
2437-
24382432
regular.absolute.return_value = root / "regular.py"
24392433
regular.resolve.return_value = root / "regular.py"
24402434
regular.is_dir.return_value = False
2435+
regular.is_file.return_value = True
24412436

2437+
outside_root_symlink = MagicMock()
24422438
outside_root_symlink.absolute.return_value = root / "symlink.py"
24432439
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
24442442

2443+
ignored_symlink = MagicMock()
24452444
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+
]
24462470

24472471
files = list(
24482472
black.gen_python_files(
@@ -2458,7 +2482,7 @@ def test_symlinks(self) -> None:
24582482
quiet=False,
24592483
)
24602484
)
2461-
assert files == [regular]
2485+
assert files == [regular, symlink_included_name]
24622486

24632487
path.iterdir.assert_called_once()
24642488
outside_root_symlink.resolve.assert_called_once()

0 commit comments

Comments
 (0)