@@ -1258,6 +1258,10 @@ def fileno(self) -> int:
1258
1258
def read (self , n : int = - 1 ) -> bytes :
1259
1259
return cast (bytes , self ._stream_object .read ())
1260
1260
1261
+ def write (self , contents : bytes ) -> int :
1262
+ self ._stream_object .write (cast (str , contents ))
1263
+ return len (contents )
1264
+
1261
1265
def close (self ) -> None :
1262
1266
"""We do not support closing standard streams."""
1263
1267
@@ -1267,6 +1271,19 @@ def close_fd(self, fd: Optional[int]) -> None:
1267
1271
def is_stream (self ) -> bool :
1268
1272
return True
1269
1273
1274
+ def __enter__ (self ) -> "StandardStreamWrapper" :
1275
+ """To support usage of this standard stream with the 'with' statement."""
1276
+ return self
1277
+
1278
+ def __exit__ (
1279
+ self ,
1280
+ exc_type : Optional [Type [BaseException ]],
1281
+ exc_val : Optional [BaseException ],
1282
+ exc_tb : Optional [TracebackType ],
1283
+ ) -> None :
1284
+ """To support usage of this standard stream with the 'with' statement."""
1285
+ self .close ()
1286
+
1270
1287
1271
1288
class FakeDirWrapper :
1272
1289
"""Wrapper for a FakeDirectory object to be used in open files list."""
@@ -1302,6 +1319,28 @@ def close_fd(self, fd: Optional[int]) -> None:
1302
1319
assert fd is not None
1303
1320
self ._filesystem .close_open_file (fd )
1304
1321
1322
+ def read (self , numBytes : int = - 1 ) -> bytes :
1323
+ """Read from the directory."""
1324
+ return self .file_object .read (numBytes )
1325
+
1326
+ def write (self , contents : bytes ) -> int :
1327
+ """Write to the directory."""
1328
+ self .file_object .write (contents )
1329
+ return len (contents )
1330
+
1331
+ def __enter__ (self ) -> "FakeDirWrapper" :
1332
+ """To support usage of this fake directory with the 'with' statement."""
1333
+ return self
1334
+
1335
+ def __exit__ (
1336
+ self ,
1337
+ exc_type : Optional [Type [BaseException ]],
1338
+ exc_val : Optional [BaseException ],
1339
+ exc_tb : Optional [TracebackType ],
1340
+ ) -> None :
1341
+ """To support usage of this fake directory with the 'with' statement."""
1342
+ self .close ()
1343
+
1305
1344
1306
1345
class FakePipeWrapper :
1307
1346
"""Wrapper for a read or write descriptor of a real pipe object to be
0 commit comments