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

Fix pathlib.Path.mkdir() with unmounted path #891

Merged
merged 1 commit into from
Oct 8, 2023
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The released versions correspond to PyPI releases.
### Fixes
* removed a leftover debug print statement (see [#869](../../issues/869))
* make sure tests work without HOME environment set (see [#870](../../issues/870))
* automount drive or UNC path under Windows if needed for `pathlib.Path.mkdir()`
(see [#890](../../issues/890))

## [Version 5.2.3](https://pypi.python.org/pypi/pyfakefs/5.2.3) (2023-08-18)
Fixes a rare problem on pytest shutdown.
Expand Down
6 changes: 5 additions & 1 deletion pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2642,12 +2642,16 @@ def makedir(self, dir_path: AnyPath, mode: int = helpers.PERM_DEF) -> None:

if self.is_windows_fs:
dir_name = self.absnormpath(dir_name)
parent_dir, _ = self.splitpath(dir_name)
parent_dir, rest = self.splitpath(dir_name)
if parent_dir:
base_dir = self.normpath(parent_dir)
ellipsis = matching_string(parent_dir, self.path_separator + "..")
if parent_dir.endswith(ellipsis) and not self.is_windows_fs:
base_dir, dummy_dotdot, _ = parent_dir.partition(ellipsis)
if self.is_windows_fs and not rest and not self.exists(base_dir):
# under Windows, the parent dir may be a drive or UNC path
# which has to be mounted
self._auto_mount_drive_if_needed(parent_dir)
if not self.exists(base_dir):
self.raise_os_error(errno.ENOENT, base_dir)

Expand Down
12 changes: 12 additions & 0 deletions pyfakefs/tests/fake_pathlib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,18 @@ def test_mkdir_exist_ok(self):
errno.EEXIST, self.path(file_name).mkdir, exist_ok=True
)

@unittest.skipIf(not is_windows, "Windows specific behavior")
def test_mkdir_with_automount_unc_path(self):
self.skip_real_fs()
self.path(r"\\test\unc\foo").mkdir(parents=True)
self.assertTrue(self.path(r"\\test\unc\foo").exists())

@unittest.skipIf(not is_windows, "Windows specific behavior")
def test_mkdir_with_automount_drive(self):
self.skip_real_fs()
self.path(r"d:\foo\bar").mkdir(parents=True)
self.assertTrue(self.path(r"d:\foo\bar").exists())

def test_rmdir(self):
dir_name = self.make_path("foo", "bar")
self.create_dir(dir_name)
Expand Down