Skip to content
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

Correctly handle setting cwd to a pathlib.Path #1109

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The released versions correspond to PyPI releases.
### Fixes
* fixed a problem with module and session scoped fixtures in Python 3.13
(see [#1101](../../issues/1101))
* fixed handling of `cwd` if set to a `pathlib.Path` (see [#1108](../../issues/1108))

## [Version 5.7.3](https://pypi.python.org/pypi/pyfakefs/5.7.3) (2024-12-15)
Fixes a regression in version 5.7.3.
Expand Down
5 changes: 4 additions & 1 deletion pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ def cwd(self, value: str) -> None:
"""Set the current working directory of the fake filesystem.
Make sure a new drive or share is auto-mounted under Windows.
"""
self._cwd = value
_cwd = make_string_path(value)
self._cwd = _cwd.replace(
matching_string(_cwd, os.sep), matching_string(_cwd, self.path_separator)
)
self._auto_mount_drive_if_needed(value)

@property
Expand Down
5 changes: 5 additions & 0 deletions pyfakefs/tests/fake_filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import contextlib
import errno
import os
import pathlib
import shutil
import stat
import sys
Expand Down Expand Up @@ -231,6 +232,10 @@ def test_relative_path_forced_to_cwd(self):
self.filesystem.cwd = "/foo"
self.assertEqual("/foo/bar", self.filesystem.absnormpath(path))

def test_cwd_from_pathlib_path(self):
self.filesystem.cwd = pathlib.Path("/foo/bar")
self.assertEqual("/foo/bar", self.filesystem.cwd)

def test_absolute_path_remains_unchanged(self):
path = "foo/bar"
self.assertEqual(self.root_name + path, self.filesystem.absnormpath(path))
Expand Down
Loading