Skip to content

Commit 5b1b056

Browse files
committed
Adapt error codes to match newer Windows 11 behavior
- for some OSError exceptions, errno has changed
1 parent 8b484cf commit 5b1b056

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The released versions correspond to PyPI releases.
1717

1818
## Fixes
1919
* fixes patching of Debian-specific `tempfile` in Python 3.13 (see [#1214](../../issues/1214))
20-
* adapted some error codes for `OSError` to match Windows 11 behavior
20+
* adapted some error codes for `OSError` to match Windows 11/Windows Server 2025 behavior
2121

2222
## [Version 5.9.3](https://pypi.python.org/pypi/pyfakefs/5.9.3) (2025-08-28)
2323
Fixes a utility method.

pyfakefs/fake_filesystem.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,7 @@ def rename(
20032003
self.raise_os_error(errno.EXDEV, old_path)
20042004
if not S_ISDIR(new_dir_object.st_mode):
20052005
self.raise_os_error(
2006-
errno.EACCES if self.is_windows_fs else errno.ENOTDIR, new_path
2006+
errno.EINVAL if self.is_windows_fs else errno.ENOTDIR, new_path
20072007
)
20082008
if new_dir_object.has_parent_object(old_object):
20092009
self.raise_os_error(errno.EINVAL, new_path)
@@ -2073,7 +2073,7 @@ def _rename_to_existing_path(
20732073
new_object = self._get_object(new_file_path)
20742074
if old_file_path == new_file_path:
20752075
if not S_ISLNK(new_object.st_mode) and ends_with_sep:
2076-
error = errno.EINVAL if self.is_windows_fs else errno.ENOTDIR
2076+
error = errno.ENOTDIR if self.is_windows_fs else errno.ENOTDIR
20772077
self.raise_os_error(error, old_file_path)
20782078
return None # Nothing to do here
20792079

@@ -3113,7 +3113,9 @@ def remove(self, path: AnyStr) -> None:
31133113
self.raise_os_error(error, norm_path)
31143114

31153115
if path.endswith(self.get_path_separator(path)):
3116-
if self.is_macos:
3116+
if self.is_windows_fs:
3117+
error = errno.EACCES
3118+
elif self.is_macos:
31173119
error = errno.EPERM
31183120
else:
31193121
error = errno.ENOTDIR

0 commit comments

Comments
 (0)