@@ -1051,13 +1051,11 @@ class PyBufferedWriterTest(BufferedWriterTest):
10511051
10521052class BufferedRWPairTest (unittest .TestCase ):
10531053
1054- def test_basic (self ):
1055- r = self .MockRawIO (())
1056- w = self .MockRawIO ()
1057- pair = self .tp (r , w )
1054+ def test_constructor (self ):
1055+ pair = self .tp (self .MockRawIO (), self .MockRawIO ())
10581056 self .assertFalse (pair .closed )
10591057
1060- def test_max_buffer_size_deprecation (self ):
1058+ def test_constructor_max_buffer_size_deprecation (self ):
10611059 with support .check_warnings () as w :
10621060 warnings .simplefilter ("always" , DeprecationWarning )
10631061 self .tp (self .MockRawIO (), self .MockRawIO (), 8 , 12 )
@@ -1067,7 +1065,100 @@ def test_max_buffer_size_deprecation(self):
10671065 self .assertEqual (str (warning .message ),
10681066 "max_buffer_size is deprecated" )
10691067
1070- # XXX More Tests
1068+ def test_constructor_with_not_readable (self ):
1069+ class NotReadable (MockRawIO ):
1070+ def readable (self ):
1071+ return False
1072+
1073+ self .assertRaises (IOError , self .tp , NotReadable (), self .MockRawIO ())
1074+
1075+ def test_constructor_with_not_writeable (self ):
1076+ class NotWriteable (MockRawIO ):
1077+ def writable (self ):
1078+ return False
1079+
1080+ self .assertRaises (IOError , self .tp , self .MockRawIO (), NotWriteable ())
1081+
1082+ def test_read (self ):
1083+ pair = self .tp (self .BytesIO (b"abcdef" ), self .MockRawIO ())
1084+
1085+ self .assertEqual (pair .read (3 ), b"abc" )
1086+ self .assertEqual (pair .read (1 ), b"d" )
1087+ self .assertEqual (pair .read (), b"ef" )
1088+
1089+ def test_read1 (self ):
1090+ # .read1() is delegated to the underlying reader object, so this test
1091+ # can be shallow.
1092+ pair = self .tp (self .BytesIO (b"abcdef" ), self .MockRawIO ())
1093+
1094+ self .assertEqual (pair .read1 (3 ), b"abc" )
1095+
1096+ def test_readinto (self ):
1097+ pair = self .tp (self .BytesIO (b"abcdef" ), self .MockRawIO ())
1098+
1099+ data = bytearray (5 )
1100+ self .assertEqual (pair .readinto (data ), 5 )
1101+ self .assertEqual (data , b"abcde" )
1102+
1103+ def test_write (self ):
1104+ w = self .MockRawIO ()
1105+ pair = self .tp (self .MockRawIO (), w )
1106+
1107+ pair .write (b"abc" )
1108+ pair .flush ()
1109+ pair .write (b"def" )
1110+ pair .flush ()
1111+ self .assertEqual (w ._write_stack , [b"abc" , b"def" ])
1112+
1113+ def test_peek (self ):
1114+ pair = self .tp (self .BytesIO (b"abcdef" ), self .MockRawIO ())
1115+
1116+ self .assertTrue (pair .peek (3 ).startswith (b"abc" ))
1117+ self .assertEqual (pair .read (3 ), b"abc" )
1118+
1119+ def test_readable (self ):
1120+ pair = self .tp (self .MockRawIO (), self .MockRawIO ())
1121+ self .assertTrue (pair .readable ())
1122+
1123+ def test_writeable (self ):
1124+ pair = self .tp (self .MockRawIO (), self .MockRawIO ())
1125+ self .assertTrue (pair .writable ())
1126+
1127+ def test_seekable (self ):
1128+ # BufferedRWPairs are never seekable, even if their readers and writers
1129+ # are.
1130+ pair = self .tp (self .MockRawIO (), self .MockRawIO ())
1131+ self .assertFalse (pair .seekable ())
1132+
1133+ # .flush() is delegated to the underlying writer object and has been
1134+ # tested in the test_write method.
1135+
1136+ def test_close_and_closed (self ):
1137+ pair = self .tp (self .MockRawIO (), self .MockRawIO ())
1138+ self .assertFalse (pair .closed )
1139+ pair .close ()
1140+ self .assertTrue (pair .closed )
1141+
1142+ def test_isatty (self ):
1143+ class SelectableIsAtty (MockRawIO ):
1144+ def __init__ (self , isatty ):
1145+ MockRawIO .__init__ (self )
1146+ self ._isatty = isatty
1147+
1148+ def isatty (self ):
1149+ return self ._isatty
1150+
1151+ pair = self .tp (SelectableIsAtty (False ), SelectableIsAtty (False ))
1152+ self .assertFalse (pair .isatty ())
1153+
1154+ pair = self .tp (SelectableIsAtty (True ), SelectableIsAtty (False ))
1155+ self .assertTrue (pair .isatty ())
1156+
1157+ pair = self .tp (SelectableIsAtty (False ), SelectableIsAtty (True ))
1158+ self .assertTrue (pair .isatty ())
1159+
1160+ pair = self .tp (SelectableIsAtty (True ), SelectableIsAtty (True ))
1161+ self .assertTrue (pair .isatty ())
10711162
10721163class CBufferedRWPairTest (BufferedRWPairTest ):
10731164 tp = io .BufferedRWPair
0 commit comments