-
-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grass.gunittest: Fix parsing exclusion from config file on Windows #4324
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wenzeslaus
reviewed
Sep 16, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using pathlib is definitively better!
wenzeslaus
approved these changes
Sep 16, 2024
wenzeslaus
requested changes
Sep 16, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really meant to request changes, not approve.
wenzeslaus
requested changes
Sep 16, 2024
wenzeslaus
approved these changes
Sep 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Refactored the function fnmatch_exclude_with_base in grass.gunittest.loader in order to work across platforms, including Windows.
I tried multiple approaches and researched a bit, and the first really working solution was the custom
fnmatch_ex
function that pytest uses, since pathlib'sPath.match()
doesn't work properly and doesn't behave likePath.glob()
concerning**
s.https://github.com/pytest-dev/pytest/blob/9515dfa58a144f3644fd29b256113d723c9c1955/src/_pytest/pathlib.py#L414-L447
However, after inlining more and more of that
fnmatch_ex
function, comparing how it behaves with our inputs (Windows and Linux) and what branches are taken, we don't use a mix of absolute and relative paths, and we never supported**
, and we never only supplied a name without separator. So, since on Windows the workingfnmatch_ex
needs a pattern with backslashes\
for the path and the pattern, and on Linux it needs forward slash on both; since pathlib's Path representation already normalizes a./
of a relative path; and since pathlib's Path/PurePath classes works properly with*
and**
, especially when that variable is converted to a string at the end, I could simply replace all our logic by creating Path instances for the full name and pattern, and call thefnmatch
with the string representations of it. I usedPurePath
instead of a concretePath
, as I didn't need to actually manipulate files, and the subclasses can be instantiated on any OS if further tests would need to run cross-platform.Also included:
files
list variable indiscover_modules
could not exist in all code paths, depending on the inputs. Initialized it with a list containing the same elements asall_files
, without directly assigningall_files
tofiles
.Motivation and context
Fixes #4319
How has this been tested?
Up until my final clean rebase, I was using extra prints inside the function, to not have to wait at the end of the test run to see if the files were properly excluded.
Screenshots (if appropriate)
Types of changes
functionality to not work as before)
Checklist
pre-defined prefixes
of this project.