Skip to content

Commit

Permalink
Use regex where we ignore case on windows (#4252)
Browse files Browse the repository at this point in the history
On windows the path `FoObAR` is the same as `foobar`, so the output
of `black` on a windows machine could output the path to `.gitignore`
with an upper or lower-case drive letter.
  • Loading branch information
KaiSforza authored Mar 13, 2024
1 parent 719e674 commit 1abcffc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from contextlib import contextmanager, redirect_stderr
from dataclasses import replace
from io import BytesIO
from pathlib import Path
from pathlib import Path, WindowsPath
from platform import system
from tempfile import TemporaryDirectory
from typing import (
Expand Down Expand Up @@ -2460,7 +2460,11 @@ def test_invalid_gitignore(self) -> None:
assert result.stderr_bytes is not None

gitignore = path / ".gitignore"
assert f"Could not parse {gitignore}" in result.stderr_bytes.decode()
assert re.search(
f"Could not parse {gitignore}".replace("\\", "\\\\"),
result.stderr_bytes.decode(),
re.IGNORECASE if isinstance(gitignore, WindowsPath) else 0,
)

def test_invalid_nested_gitignore(self) -> None:
path = THIS_DIR / "data" / "invalid_nested_gitignore_tests"
Expand All @@ -2472,7 +2476,11 @@ def test_invalid_nested_gitignore(self) -> None:
assert result.stderr_bytes is not None

gitignore = path / "a" / ".gitignore"
assert f"Could not parse {gitignore}" in result.stderr_bytes.decode()
assert re.search(
f"Could not parse {gitignore}".replace("\\", "\\\\"),
result.stderr_bytes.decode(),
re.IGNORECASE if isinstance(gitignore, WindowsPath) else 0,
)

def test_gitignore_that_ignores_subfolders(self) -> None:
# If gitignore with */* is in root
Expand Down

0 comments on commit 1abcffc

Please sign in to comment.