Skip to content

Commit 1abcffc

Browse files
authored
Use regex where we ignore case on windows (#4252)
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.
1 parent 719e674 commit 1abcffc

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tests/test_black.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from contextlib import contextmanager, redirect_stderr
1515
from dataclasses import replace
1616
from io import BytesIO
17-
from pathlib import Path
17+
from pathlib import Path, WindowsPath
1818
from platform import system
1919
from tempfile import TemporaryDirectory
2020
from typing import (
@@ -2460,7 +2460,11 @@ def test_invalid_gitignore(self) -> None:
24602460
assert result.stderr_bytes is not None
24612461

24622462
gitignore = path / ".gitignore"
2463-
assert f"Could not parse {gitignore}" in result.stderr_bytes.decode()
2463+
assert re.search(
2464+
f"Could not parse {gitignore}".replace("\\", "\\\\"),
2465+
result.stderr_bytes.decode(),
2466+
re.IGNORECASE if isinstance(gitignore, WindowsPath) else 0,
2467+
)
24642468

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

24742478
gitignore = path / "a" / ".gitignore"
2475-
assert f"Could not parse {gitignore}" in result.stderr_bytes.decode()
2479+
assert re.search(
2480+
f"Could not parse {gitignore}".replace("\\", "\\\\"),
2481+
result.stderr_bytes.decode(),
2482+
re.IGNORECASE if isinstance(gitignore, WindowsPath) else 0,
2483+
)
24762484

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

0 commit comments

Comments
 (0)