Skip to content

Commit

Permalink
Changed the behavior of getsize() on buffered append to match real OS
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Aug 10, 2017
1 parent 386af15 commit 0a5bb74
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
11 changes: 3 additions & 8 deletions fake_filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3462,7 +3462,7 @@ def testFileSizeAfterWrite(self):
expected_size = original_size + len(added_content)
fh = self.open(file_path, 'a')
fh.write(added_content)
self.assertEqual(expected_size, fh.Size())
self.assertEqual(original_size, fh.Size())
fh.close()
self.assertEqual(expected_size, self.open(file_path, 'r').Size())

Expand All @@ -3473,13 +3473,8 @@ def testLargeFileSizeAfterWrite(self):
self.filesystem.CreateFile(file_path, st_size=original_size)
added_content = 'foo bar'
fh = self.open(file_path, 'a')
# We can't use assertRaises, because the exception is thrown
# in __getattr__, so just saying 'fh.write' causes the exception.
try:
fh.write(added_content)
except fake_filesystem.FakeLargeFileIoException:
return
self.fail('Writing to a large file should not be allowed')
self.assertRaises(fake_filesystem.FakeLargeFileIoException,
lambda: fh.write(added_content))

def testFileSizeUpdatedViaFlush(self):
"""test that file size gets updated via flush()."""
Expand Down
1 change: 0 additions & 1 deletion pyfakefs/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -4255,7 +4255,6 @@ def other_wrapper(*args, **kwargs):
if write_seek != self._io.tell():
self._read_seek = self._io.tell()
self._read_whence = 0
self._file_object.st_size += (self._read_seek - write_seek)
return ret_value

return other_wrapper
Expand Down

0 comments on commit 0a5bb74

Please sign in to comment.