-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output incorrectly claims symbolic links presence when formatting from outside a project #3384
Comments
Seems like this can't be tested easily because the exception can't be reproduced in the test suite: black.get_sources(
ctx=ctx,
src=("./dir",),
quiet=False,
verbose=True,
include=DEFAULT_INCLUDE,
exclude=DEFAULT_EXCLUDE,
report=report,
extend_exclude=None,
force_exclude=None,
stdin_filename=None,
) This function call is similar to the call from the CLI, but the test suite fails because This reported bug does not happen in the test, because (as you can see in the patch) the solution uses the absolute path to the target file. |
Here's a working test. Current behavior makes the test fail ( diff --git a/tests/test_black.py b/tests/test_black.py
index dda1055..07aa8b3 100644
--- a/tests/test_black.py
+++ b/tests/test_black.py
@@ -475,6 +475,35 @@ class BlackTestCase(BlackBaseTestCase):
self.assertFormatEqual(contents_spc, fs(contents_spc))
self.assertFormatEqual(contents_spc, fs(contents_tab))
+ @patch("pathlib.Path.is_dir", lambda _: True)
+ def test_false_positive_symlink_output_issue_3384(self) -> None:
+ # Emulate the behavior when using the CLI: black ./child --check --verbose
+ project_root = Path(THIS_DIR / "data" / "nested_gitignore_tests")
+ working_directory = project_root / "root"
+ target_abspath = working_directory / "child"
+ target_contents = (
+ src.relative_to(working_directory) for src in target_abspath.iterdir()
+ )
+ with patch("pathlib.Path.iterdir", return_value=target_contents), patch(
+ "pathlib.Path.cwd", return_value=working_directory
+ ):
+ ctx = FakeContext()
+ ctx.obj["root"] = project_root
+ report = MagicMock(verbose=True)
+ collected = black.get_sources(
+ ctx=ctx,
+ src=("./child",),
+ quiet=False,
+ verbose=True,
+ include=DEFAULT_INCLUDE,
+ exclude=None,
+ report=report,
+ extend_exclude=None,
+ force_exclude=None,
+ stdin_filename=None,
+ )
+ assert report.path_ignored.call_count == 3
+
def test_report_verbose(self) -> None:
report = Report(verbose=True)
out_lines = []
|
Hi, is there any updates on this? |
Describe the bug
When trying to format a project from the outside, the verbose output shows says that there are symbolic links that points outside of the project, but displays the wrong project path. This behavior seem to be triggered when the command is executed from outside a project on a folder.
To Reproduce
Consider the following tree:
When trying to format a folder from
home
, this is the output:Notice that the message
FILEPATH ignored: is a symbolic link that points outside PROJECTPATH
displays a wrong PROJECTPATH (should be/path/to/home/project/
instead of/path/to/home/project/project
).Same happens when using
black ./project/dir
:Expected behavior
Display each path once (and correctly):
Environment
Additional context
This change produces the expected behavior:
I'll try to submit a PR. I'm trying to figure out how to test this.
The text was updated successfully, but these errors were encountered: