Skip to content

Commit

Permalink
Handle open with TMPFILE flag
Browse files Browse the repository at this point in the history
- added basic test for TemporaryFile
- fixes #509
- back-ported from master
  • Loading branch information
mrbean-bremen committed Mar 2, 2020
1 parent ad23e51 commit 4c3fb60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 7 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ _Note:_ pyfakefs 4.0 is planned for release at the end of 2019 or the beginning
of 2020. As pyfakefs 4.0 is a major release, we are giving you advance notice of
the proposed changes so you can be ready.

* pyfakefs 4.0 drops support for Python 2.7. If you still need
Python 2.7, you can continue to use the latest pyfakefs 3.x version.
## [Version 3.7.2](https://pypi.python.org/pypi/pyfakefs/3.7.2)

This version backports some fixes from master.

#### Fixes
* Fixed handling of `os.TMPFILE` flag under Linux
(see [#509](../../issues/509))

## [Version 3.7.1](https://pypi.python.org/pypi/pyfakefs/3.7.1)

Expand Down
4 changes: 3 additions & 1 deletion pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -3726,8 +3726,10 @@ def open(self, path, flags, mode=None, dir_fd=None):
else:
mode = 0o777 & ~self._umask()

has_tmpfile_flag = (hasattr(os, 'O_TMPFILE') and
flags & getattr(os, 'O_TMPFILE'))
open_modes = _OpenModes(
must_exist=not flags & os.O_CREAT,
must_exist=not flags & os.O_CREAT and not has_tmpfile_flag,
can_read=not flags & os.O_WRONLY,
can_write=flags & (os.O_RDWR | os.O_WRONLY),
truncate=flags & os.O_TRUNC,
Expand Down
6 changes: 6 additions & 0 deletions pyfakefs/tests/fake_tempfile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def test_temporary_directory(self):
self.assertEqual(self.fs.get_object(tmpdir).st_mode,
stat.S_IFDIR | 0o700)

def test_temporary_file(self):
with tempfile.TemporaryFile() as f:
f.write(b'test')
f.seek(0)
self.assertEqual(b'test', f.read())


if __name__ == '__main__':
unittest.main()

0 comments on commit 4c3fb60

Please sign in to comment.