File tree 2 files changed +20
-0
lines changed
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,24 @@ def testBlksize(self):
73
73
blksize = getattr (fst , 'st_blksize' , blksize )
74
74
self .assertEqual (self .f ._blksize , blksize )
75
75
76
+ def testReadWithWritingMode (self ):
77
+ r , w = os .pipe ()
78
+ w = os .fdopen (w , "w" )
79
+ w .write ("hello" )
80
+ w .close ()
81
+ with io .FileIO (r , mode = "w" ) as f :
82
+ with self .assertRaises (_io .UnsupportedOperation ):
83
+ f .read ()
84
+
85
+ def testReadallWithWritingMode (self ):
86
+ r , w = os .pipe ()
87
+ w = os .fdopen (w , "w" )
88
+ w .write ("hello" )
89
+ w .close ()
90
+ with io .FileIO (r , mode = "w" ) as f :
91
+ with self .assertRaises (_io .UnsupportedOperation ):
92
+ f .readall ()
93
+
76
94
# verify readinto
77
95
def testReadintoByteArray (self ):
78
96
self .f .write (bytes ([1 , 2 , 0 , 255 ]))
Original file line number Diff line number Diff line change @@ -699,6 +699,8 @@ _io_FileIO_readall_impl(fileio *self)
699
699
700
700
if (self -> fd < 0 )
701
701
return err_closed ();
702
+ if (!self -> readable )
703
+ return err_mode ("reading" );
702
704
703
705
Py_BEGIN_ALLOW_THREADS
704
706
_Py_BEGIN_SUPPRESS_IPH
You can’t perform that action at this time.
0 commit comments