Skip to content

Commit 3e400cf

Browse files
committed
io_buffered_writer.py: Improve failed flush test.
Try flushing 4 times. The first two times, the underlying IO object fails. The third time, the data is actually flushed. The last time, write is not called as there was no data left. Signed-off-by: Jeff Epler <jepler@gmail.com>
1 parent 162bd02 commit 3e400cf

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

tests/basics/io_buffered_writer.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,24 @@
3131

3232
# Test failing flush()
3333
class MyIO(io.IOBase):
34+
def __init__(self):
35+
self.count = 0
36+
3437
def write(self, buf):
35-
return None
38+
self.count += 1
39+
if self.count < 3:
40+
return None
41+
print("writing", buf)
42+
return len(buf)
43+
3644

3745
buf = io.BufferedWriter(MyIO(), 8)
46+
3847
buf.write(b"foobar")
39-
try:
40-
buf.flush()
41-
print("flushed")
42-
except OSError:
43-
print("OSError")
48+
49+
for _ in range(4):
50+
try:
51+
buf.flush()
52+
print("flushed")
53+
except OSError:
54+
print("OSError")

tests/basics/io_buffered_writer.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ b'foobarfoobar'
55
b'foo'
66
<class 'int'>
77
OSError
8+
OSError
9+
writing bytearray(b'foobar')
10+
flushed
11+
flushed

0 commit comments

Comments
 (0)