Skip to content

Commit e8ae593

Browse files
committed
Fix content update after flush
- caused missing content if writing over the buffer end - temporarily disable Python 3.14 in CI (current alpha 5 fails some tests)
1 parent 7147769 commit e8ae593

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

.github/workflows/testsuite.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ jobs:
3232
fail-fast: false
3333
matrix:
3434
os: [ubuntu-latest, macOS-latest, windows-latest]
35-
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13", "3.14"]
35+
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
36+
# python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13", "3.14"]
3637
include:
3738
- python-version: "pypy-3.7"
3839
os: ubuntu-22.04

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ The released versions correspond to PyPI releases.
1717
### Changes
1818
* added some preliminary support for Python 3.14
1919

20+
### Fixes
21+
* fixed a problem with flushing if writing over the buffer end
22+
(see [#1120](../../issues/1120))
23+
2024
## [Version 5.7.4](https://pypi.python.org/pypi/pyfakefs/5.7.4) (2025-01-14)
2125
Minor bugfix release.
2226

pyfakefs/fake_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,15 +910,16 @@ def flush(self) -> None:
910910
self._check_open_file()
911911

912912
if self.allow_update:
913-
contents = self._io.getvalue()
914913
if self._append:
914+
contents = self._io.getvalue()
915915
self._sync_io()
916916
old_contents = self.file_object.byte_contents
917917
assert old_contents is not None
918918
contents = old_contents + contents[self._flush_pos :]
919919
self._set_stream_contents(contents)
920920
else:
921921
self._io.flush()
922+
contents = self._io.getvalue()
922923
changed = self.file_object.set_contents(contents, self._encoding)
923924
self.update_flush_pos()
924925
if changed:

pyfakefs/tests/fake_open_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,22 @@ def test_failed_write_does_not_truncate_file(self):
13661366
x = r.read()
13671367
self.assertEqual(b"a" * 50, x)
13681368

1369+
def test_writing_over_buffer_end(self):
1370+
# regression test for #1120
1371+
dir_path = self.make_path("foo")
1372+
self.create_dir(dir_path)
1373+
file_path = self.os.path.join(dir_path, "bar.txt")
1374+
line_end_size = len(self.os.linesep)
1375+
char_count = io.DEFAULT_BUFFER_SIZE // 256 - line_end_size
1376+
for line_count in (255, 256, 257, 511, 512, 513):
1377+
with self.open(file_path, "w") as f:
1378+
for i in range(line_count):
1379+
f.write("x" * char_count + "\n")
1380+
1381+
with self.open(file_path) as f:
1382+
lines = f.readlines()
1383+
self.assertEqual(line_count, len(lines))
1384+
13691385

13701386
class RealBufferingTest(BufferingModeTest):
13711387
def use_real_fs(self):

0 commit comments

Comments
 (0)