From 0a5bb740ca1915b850981c5b160ce0b697d79450 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Thu, 10 Aug 2017 21:51:53 +0200 Subject: [PATCH] Changed the behavior of getsize() on buffered append to match real OS - fixes #281 --- fake_filesystem_test.py | 11 +++-------- pyfakefs/fake_filesystem.py | 1 - 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/fake_filesystem_test.py b/fake_filesystem_test.py index 78fa9ae3..a5844bd8 100755 --- a/fake_filesystem_test.py +++ b/fake_filesystem_test.py @@ -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()) @@ -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().""" diff --git a/pyfakefs/fake_filesystem.py b/pyfakefs/fake_filesystem.py index f2b3f575..ce3c020b 100644 --- a/pyfakefs/fake_filesystem.py +++ b/pyfakefs/fake_filesystem.py @@ -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