Skip to content

Commit

Permalink
Fix OSError subtype raised under MacOS on os.chdir with file decscriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Aug 29, 2020
1 parent 9f20c89 commit b390245
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3703,8 +3703,13 @@ def chdir(self, path):
OSError: if user lacks permission to enter the argument directory
or if the target is not a directory.
"""
path = self.filesystem.resolve_path(
path, allow_fd=True)
try:
path = self.filesystem.resolve_path(
path, allow_fd=True)
except OSError as exc:
if self.filesystem.is_macos and exc.errno == errno.EBADF:
raise OSError(errno.ENOTDIR, "Not a directory: " + str(path))
raise
self.filesystem.confirmdir(path)
directory = self.filesystem.resolve(path)
# A full implementation would check permissions all the way
Expand Down
3 changes: 2 additions & 1 deletion pyfakefs/tests/fake_open_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,8 @@ def test_chdir_uses_open_fd_as_path(self):
if self.is_pypy:
# unclear behavior with PyPi
self.skip_real_fs()
self.assert_raises_os_error(errno.EBADF, self.os.chdir, 10)
error = errno.ENOTDIR if self.is_macos else errno.EBADF
self.assert_raises_os_error(error, self.os.chdir, 10)
dir_path = self.make_path('foo', 'bar')
self.create_dir(dir_path)

Expand Down

0 comments on commit b390245

Please sign in to comment.