@@ -1531,11 +1531,25 @@ def test_no_extraneous_read(self):
1531
1531
1532
1532
def test_read_on_closed (self ):
1533
1533
# Issue #23796
1534
- b = io .BufferedReader (io .BytesIO (b"12" ))
1534
+ b = self .BufferedReader (self .BytesIO (b"12" ))
1535
1535
b .read (1 )
1536
1536
b .close ()
1537
- self .assertRaises (ValueError , b .peek )
1538
- self .assertRaises (ValueError , b .read1 , 1 )
1537
+ with self .subTest ('peek' ):
1538
+ self .assertRaises (ValueError , b .peek )
1539
+ with self .subTest ('read1' ):
1540
+ self .assertRaises (ValueError , b .read1 , 1 )
1541
+ with self .subTest ('read' ):
1542
+ self .assertRaises (ValueError , b .read )
1543
+ with self .subTest ('readinto' ):
1544
+ self .assertRaises (ValueError , b .readinto , bytearray ())
1545
+ with self .subTest ('readinto1' ):
1546
+ self .assertRaises (ValueError , b .readinto1 , bytearray ())
1547
+ with self .subTest ('flush' ):
1548
+ self .assertRaises (ValueError , b .flush )
1549
+ with self .subTest ('truncate' ):
1550
+ self .assertRaises (ValueError , b .truncate )
1551
+ with self .subTest ('seek' ):
1552
+ self .assertRaises (ValueError , b .seek , 0 )
1539
1553
1540
1554
def test_truncate_on_read_only (self ):
1541
1555
rawio = self .MockFileIO (b"abc" )
@@ -1593,18 +1607,18 @@ def test_garbage_collection(self):
1593
1607
def test_args_error (self ):
1594
1608
# Issue #17275
1595
1609
with self .assertRaisesRegex (TypeError , "BufferedReader" ):
1596
- self .tp (io .BytesIO (), 1024 , 1024 , 1024 )
1610
+ self .tp (self .BytesIO (), 1024 , 1024 , 1024 )
1597
1611
1598
1612
def test_bad_readinto_value (self ):
1599
- rawio = io . BufferedReader ( io .BytesIO (b"12" ))
1613
+ rawio = self . tp ( self .BytesIO (b"12" ))
1600
1614
rawio .readinto = lambda buf : - 1
1601
1615
bufio = self .tp (rawio )
1602
1616
with self .assertRaises (OSError ) as cm :
1603
1617
bufio .readline ()
1604
1618
self .assertIsNone (cm .exception .__cause__ )
1605
1619
1606
1620
def test_bad_readinto_type (self ):
1607
- rawio = io . BufferedReader ( io .BytesIO (b"12" ))
1621
+ rawio = self . tp ( self .BytesIO (b"12" ))
1608
1622
rawio .readinto = lambda buf : b''
1609
1623
bufio = self .tp (rawio )
1610
1624
with self .assertRaises (OSError ) as cm :
@@ -1747,7 +1761,7 @@ def test_write_non_blocking(self):
1747
1761
self .assertTrue (s .startswith (b"01234567A" ), s )
1748
1762
1749
1763
def test_write_and_rewind (self ):
1750
- raw = io .BytesIO ()
1764
+ raw = self .BytesIO ()
1751
1765
bufio = self .tp (raw , 4 )
1752
1766
self .assertEqual (bufio .write (b"abcdef" ), 6 )
1753
1767
self .assertEqual (bufio .tell (), 6 )
@@ -1957,7 +1971,7 @@ def test_garbage_collection(self):
1957
1971
def test_args_error (self ):
1958
1972
# Issue #17275
1959
1973
with self .assertRaisesRegex (TypeError , "BufferedWriter" ):
1960
- self .tp (io .BytesIO (), 1024 , 1024 , 1024 )
1974
+ self .tp (self .BytesIO (), 1024 , 1024 , 1024 )
1961
1975
1962
1976
1963
1977
class PyBufferedWriterTest (BufferedWriterTest ):
@@ -2433,7 +2447,7 @@ def test_garbage_collection(self):
2433
2447
def test_args_error (self ):
2434
2448
# Issue #17275
2435
2449
with self .assertRaisesRegex (TypeError , "BufferedRandom" ):
2436
- self .tp (io .BytesIO (), 1024 , 1024 , 1024 )
2450
+ self .tp (self .BytesIO (), 1024 , 1024 , 1024 )
2437
2451
2438
2452
2439
2453
class PyBufferedRandomTest (BufferedRandomTest ):
@@ -3465,7 +3479,7 @@ def test_illegal_encoder(self):
3465
3479
# encode() is invalid shouldn't cause an assertion failure.
3466
3480
rot13 = codecs .lookup ("rot13" )
3467
3481
with support .swap_attr (rot13 , '_is_text_encoding' , True ):
3468
- t = io .TextIOWrapper (io .BytesIO (b'foo' ), encoding = "rot13" )
3482
+ t = self .TextIOWrapper (self .BytesIO (b'foo' ), encoding = "rot13" )
3469
3483
self .assertRaises (TypeError , t .write , 'bar' )
3470
3484
3471
3485
def test_illegal_decoder (self ):
@@ -3571,7 +3585,7 @@ def seekable(self): return True
3571
3585
t = self .TextIOWrapper (F (), encoding = 'utf-8' )
3572
3586
3573
3587
def test_reconfigure_locale (self ):
3574
- wrapper = io .TextIOWrapper (io .BytesIO (b"test" ))
3588
+ wrapper = self .TextIOWrapper (self .BytesIO (b"test" ))
3575
3589
wrapper .reconfigure (encoding = "locale" )
3576
3590
3577
3591
def test_reconfigure_encoding_read (self ):
@@ -3741,7 +3755,7 @@ def test_garbage_collection(self):
3741
3755
# all data to disk.
3742
3756
# The Python version has __del__, so it ends in gc.garbage instead.
3743
3757
with warnings_helper .check_warnings (('' , ResourceWarning )):
3744
- rawio = io .FileIO (os_helper .TESTFN , "wb" )
3758
+ rawio = self .FileIO (os_helper .TESTFN , "wb" )
3745
3759
b = self .BufferedWriter (rawio )
3746
3760
t = self .TextIOWrapper (b , encoding = "ascii" )
3747
3761
t .write ("456def" )
0 commit comments