Skip to content

Commit

Permalink
Adapt read position after tell and flush
Browse files Browse the repository at this point in the history
- hopefully fixes #300
  • Loading branch information
mrbean-bremen committed Jan 16, 2018
1 parent 4a3ae48 commit 35d02b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4323,9 +4323,9 @@ def flush(self):
self.file_object.contents)
contents = old_contents + contents[self._flush_pos:]
self._set_stream_contents(contents)
self.update_flush_pos()
else:
self._io.flush()
self.update_flush_pos()
self.file_object.set_contents(contents, self._encoding)
self._file_epoch = self.file_object.epoch

Expand Down Expand Up @@ -4364,6 +4364,9 @@ def tell(self):
self._check_open_file()
if self._flushes_after_tell():
self.flush()
if self._read_seek:
self._read_seek = self._flush_pos
self._read_whence = 0

if not self._append:
return self._io.tell()
Expand Down
4 changes: 2 additions & 2 deletions tests/fake_os_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ def check_append_mode_tell_after_truncate(self, tell_result):
f1.write('abcde')
f0.seek(2)
f0.truncate()
# self.assertEqual(tell_result, f1.tell())
self.assertEqual(tell_result, f1.tell())
with self.open(file_path, mode='rb') as f:
self.assertEqual(b'\0\0abcde', f.read())

Expand All @@ -945,7 +945,7 @@ def test_append_mode_tell_linux_windows(self):
self.check_append_mode_tell_after_truncate(tell_result)

def test_append_mode_tell_macos(self):
self.check_linux_and_windows()
self.check_macos_only()
self.check_append_mode_tell_after_truncate(7)

def test_rename_dir(self):
Expand Down

0 comments on commit 35d02b1

Please sign in to comment.