Skip to content

Use regex where we ignore case on windows#4252

Merged
JelleZijlstra merged 1 commit intopsf:mainfrom
KaiSforza:kai/winpaths
Mar 13, 2024
Merged

Use regex where we ignore case on windows#4252
JelleZijlstra merged 1 commit intopsf:mainfrom
KaiSforza:kai/winpaths

Conversation

@KaiSforza
Copy link
Contributor

@KaiSforza KaiSforza commented Feb 26, 2024

Description

I was just about to start testing things, and was running into failed tests on main. Both test_invalid_gitignore and test_invalid_nested_gitignore both threw errors because of the case-sensitivity of "s" in "STRING" with gitignore being c:\\... and the output having C:\\....

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 upper or lower-case portions of the path. In this change we use the regex re.IGNORECASE flag to get it to match properly. We do not do this when the gitignore path is not a pathlib.WindowsPath object.

Checklist - did you ...

  • Add an entry in CHANGES.md if necessary? - not necessary
  • Add / update tests if necessary? - these are the tests 😅
  • Add new / update outdated documentation? - don't think any documentation is needed

Updated test output

Running pytest with args: ['-p', 'vscode_pytest', '--rootdir', 'c:\\Users\\kai\\git\\black', 'c:\\Users\\kai\\git\\black\\tests\\test_black.py::TestFileCollection::test_invalid_nested_gitignore', 'c:\\Users\\kai\\git\\black\\tests\\test_black.py::TestFileCollection::test_invalid_gitignore']
============================= test session starts =============================
platform win32 -- Python 3.11.4, pytest-8.0.2, pluggy-1.4.0
rootdir: c:\Users\kai\git\black
configfile: pyproject.toml
plugins: cov-4.1.0, xdist-3.5.0
collected 2 items

tests\test_black.py ..                                                   [100%]

============================== 2 passed in 0.14s ==============================
Finished running tests!

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.
@KaiSforza
Copy link
Contributor Author

I don't think this change will require a change in CHANGES.md.

@JelleZijlstra JelleZijlstra added the ci: skip news Pull requests that don't need a changelog entry. label Mar 13, 2024
@JelleZijlstra JelleZijlstra merged commit 1abcffc into psf:main Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: skip news Pull requests that don't need a changelog entry.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants