@@ -76,6 +76,15 @@ def expectedFailureIfStdinIsTTY(fun):
76
76
pass
77
77
return fun
78
78
79
+
80
+ def write_all (fd , data ):
81
+ written = os .write (fd , data )
82
+ if written != len (data ):
83
+ # gh-73256, gh-110673: It should never happen, but check just in case
84
+ raise Exception (f"short write: os.write({ fd } , { len (data )} bytes) "
85
+ f"wrote { written } bytes" )
86
+
87
+
79
88
# Marginal testing of pty suite. Cannot do extensive 'do or fail' testing
80
89
# because pty code is not too portable.
81
90
class PtyTest (unittest .TestCase ):
@@ -170,14 +179,14 @@ def test_openpty(self):
170
179
os .set_blocking (master_fd , blocking )
171
180
172
181
debug ("Writing to slave_fd" )
173
- os . write (slave_fd , TEST_STRING_1 )
182
+ write_all (slave_fd , TEST_STRING_1 )
174
183
s1 = _readline (master_fd )
175
184
self .assertEqual (b'I wish to buy a fish license.\n ' ,
176
185
normalize_output (s1 ))
177
186
178
187
debug ("Writing chunked output" )
179
- os . write (slave_fd , TEST_STRING_2 [:5 ])
180
- os . write (slave_fd , TEST_STRING_2 [5 :])
188
+ write_all (slave_fd , TEST_STRING_2 [:5 ])
189
+ write_all (slave_fd , TEST_STRING_2 [5 :])
181
190
s2 = _readline (master_fd )
182
191
self .assertEqual (b'For my pet fish, Eric.\n ' , normalize_output (s2 ))
183
192
@@ -360,8 +369,8 @@ def test__copy_to_each(self):
360
369
masters = [s .fileno () for s in socketpair ]
361
370
362
371
# Feed data. Smaller than PIPEBUF. These writes will not block.
363
- os . write (masters [1 ], b'from master' )
364
- os . write (write_to_stdin_fd , b'from stdin' )
372
+ write_all (masters [1 ], b'from master' )
373
+ write_all (write_to_stdin_fd , b'from stdin' )
365
374
366
375
# Expect three select calls, the last one will cause IndexError
367
376
pty .select = self ._mock_select
0 commit comments