Repository navigation
Fix path splitting functions for the simulated file system - #1350
Open
wanjiang263 wants to merge 2 commits into
Open
wanjiang263 wants to merge 2 commits into
wanjiang263 wants to merge 2 commits into
Conversation
`FakePathModule` did not override `basename`, `splitext` and `commonpath`, so these were forwarded to the host `os.path` module. Under Windows simulation on a POSIX host this kept POSIX semantics and therefore did not treat a backslash as a path separator, while other functions like `split`, `dirname` and `normpath` were already file-system-aware. Add overrides that dispatch to `ntpath` or `posixpath` depending on the simulated file system, using the same module dispatch already used by the pathlib flavours, and register the functions in `dir()` so that separately imported functions are patched as well. Fixes pytest-dev#1348
for more information, see https://pre-commit.ci
This branch has not been deployed
This file contains hidden or 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
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.
Summary
Fixes #1348.
FakePathModuleoverrides theos.pathfunctions that depend on the simulatedfile system, but
basename,splitextandcommonpathwere not among them.They fell through
__getattr__to_OS_PATH_COPY, a copy of the hostos.path, so under Windows simulation on a POSIX host they applied POSIXseparator rules.
This adds the three functions, dispatching to
ntpathorposixpathbased onfilesystem.is_windows_fs— the patternfake_pathlib.pyalready uses. Resultsare exactly what the matching stdlib module produces on every Python version,
rather than a reimplementation of e.g.
ntpath._splitext, which has changedacross versions.
On a POSIX host simulating POSIX the behaviour is unchanged: the helper returns
posixpath, the same module__getattr__reached before.Test plan
python -bb -m pyfakefs.tests.all_tests— 2417 tests, same 5 pre-existingpyreadline3doctest errors as onmainFakePathModuleTest. Verified on a Windows host: the three*_posixtests fail before this change and pass after. The three*_windowstests cover the reported direction, which only reproduces on aPOSIX host (CI).