Skip to content

Commit

Permalink
Fix separator mismatch with Linux emulated under Windows
Browse files Browse the repository at this point in the history
- the tempfile module will access the temp path using Windows
  separators under Windows, even if emulating Posix -
  this had to be handled
- fixes #912
  • Loading branch information
mrbean-bremen committed Nov 25, 2023
1 parent 211c0ce commit 95b2de3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The released versions correspond to PyPI releases.

### Fixes
* fixed a problem with patching `_io` under Python 3.12 (see [#910](../../issues/910))
* fixed a problem with accessing the temp path if emulating Linux under Windows
(see [#912](../../issues/912))

## [Version 5.3.1](https://pypi.python.org/pypi/pyfakefs/5.3.0) (2023-11-15)
Mostly a bugfix release.
Expand Down
5 changes: 5 additions & 0 deletions pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,11 @@ def resolve_path(self, file_path: AnyStr, allow_fd: bool = False) -> AnyStr:
if path is None:
# file.open(None) raises TypeError, so mimic that.
raise TypeError("Expected file system path string, received None")
if sys.platform == "win32" and self.os != OSType.WINDOWS:
path = path.replace(
matching_string(path, os.sep),
matching_string(path, self.path_separator),
)
if not path or not self._valid_relative_path(path):
# file.open('') raises OSError, so mimic that, and validate that
# all parts of a relative path exist.
Expand Down
7 changes: 7 additions & 0 deletions pyfakefs/tests/fake_filesystem_unittest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,13 @@ def test_drivelike_path(self):
os.chdir(folder)
self.assertTrue(os.path.exists(str(file_path.relative_to(folder))))

@unittest.skipIf(sys.platform != "win32", "Windows-specific test")
def test_tempfile_access(self):
# regression test for #912
self.fs.os = OSType.LINUX
tmp_file = tempfile.TemporaryFile()
assert tmp_file


@unittest.skipIf(sys.platform != "win32", "Windows-specific behavior")
class TestAbsolutePathOnWindows(fake_filesystem_unittest.TestCase):
Expand Down

0 comments on commit 95b2de3

Please sign in to comment.