Skip to content

Commit

Permalink
Test root gitignore behavior on multiple sources
Browse files Browse the repository at this point in the history
The test creates a fake context and collects the files from two
sources. Both sources are directories in the root path, where a
gitignore file ignores a filename that is present in both subdirs.

Before the fix introduced in the previous commit, this test was
expected to fail: a file that should be ignores was still visible for
Black. Now, the test is passed.

Signed-off-by: Antonio Ossa Guerra <aaossa@uc.cl>
  • Loading branch information
aaossa committed Oct 20, 2022
1 parent 4b6f4e3 commit 0f1c9e9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/data/gitignore_used_on_multiple_sources/.gitignore
@@ -0,0 +1 @@
a.py
Empty file.
Empty file.
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions tests/test_black.py
Expand Up @@ -1956,6 +1956,17 @@ def test_gitignore_used_as_default(self) -> None:
ctx.obj["root"] = base
assert_collected_sources(src, expected, ctx=ctx, extend_exclude=r"/exclude/")

def test_gitignore_used_on_multiple_sources(self) -> None:
root = Path(DATA_DIR / "gitignore_used_on_multiple_sources")
expected = [
root / "dir1" / "b.py",
root / "dir2" / "b.py",
]
ctx = FakeContext()
ctx.obj["root"] = root
src = [root / "dir1", root / "dir2"]
assert_collected_sources(src, expected, ctx=ctx)

@patch("black.find_project_root", lambda *args: (THIS_DIR.resolve(), None))
def test_exclude_for_issue_1572(self) -> None:
# Exclude shouldn't touch files that were explicitly given to Black through the
Expand Down

0 comments on commit 0f1c9e9

Please sign in to comment.