-
Notifications
You must be signed in to change notification settings - Fork 94
Closed
Labels
Description
Describe the bug
There seems to be a bug when a file is re-opened for writing, that disk usage is not calculated correctly, and hence does not throw disk full exceptions at the right place. In the code below, in the first test, the assertion fails. The second test works fine. The third function fails the assertion. I discovered this error in code which re-opens files regularly, and uses random-access read/write mode ('r+'), and seeking within files.
How To Reproduce
class ExampleTestCase(TestCase):
def setUp(self):
self.setUpPyfakefs()
self.fs.set_disk_usage(100)
def test_disk_full_reopened_160(self):
with open('bar.txt', 'w') as f:
f.write('a' * 60)
with open('bar.txt') as f:
self.assertEqual(f.read(), 'a' * 60)
with open('bar.txt', 'w') as f:
with self.assertRaises(OSError):
f.write('b' * 160)
f.flush()
def test_disk_full_reopened_161(self):
with open('bar.txt', 'w') as f:
f.write('a' * 60)
with open('bar.txt') as f:
self.assertEqual(f.read(), 'a' * 60)
with open('bar.txt', 'w') as f:
with self.assertRaises(OSError):
f.write('b' * 161)
f.flush()
def test_disk_full_reopened_rplus_seek(self):
with open('bar.txt', 'w') as f:
f.write('a' * 60)
with open('bar.txt') as f:
self.assertEqual(f.read(), 'a' * 60)
with open('bar.txt', 'r+') as f:
with self.assertRaises(OSError):
f.seek(50)
f.write('b' * 60)
f.flush()
Your environment
Please run the following and paste the output.
Linux-5.15.11-76051511-generic-x86_64-with-glibc2.34
Python 3.9.7 (default, Sep 10 2021, 14:59:43)
[GCC 11.2.0]
pyfakefs 4.5.4