From 1abcffc81816257985678f08c61584ed4287f22a Mon Sep 17 00:00:00 2001 From: Kai Sforza Date: Wed, 13 Mar 2024 00:22:10 -0400 Subject: [PATCH] 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. --- tests/test_black.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_black.py b/tests/test_black.py index 96f53d5e5f3..70884152d58 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -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 ( @@ -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" @@ -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