From 79256a9fb9b3dd6be195f7ec17540571f7fa42d4 Mon Sep 17 00:00:00 2001 From: Kai Giokas Date: Mon, 26 Feb 2024 16:28:39 -0500 Subject: [PATCH] Use regex where we ignore case on windows 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 41f87cd16f8..7a7caa8ee45 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 ( @@ -2473,7 +2473,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" @@ -2485,7 +2489,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