@@ -1250,6 +1250,42 @@ def test_read_binary__spec(
12501250 assert type (response5 ) is bytes
12511251 assert len (response5 ) == 0
12521252
1253+ response6 = os_ops .read_binary (filename , 0 , 1 )
1254+ assert type (response6 ) is bytes
1255+ assert len (response6 ) == 1
1256+ assert response6 == response0 [:1 ]
1257+
1258+ r = os_ops .read_binary (filename , 10 , 7 )
1259+ assert type (r ) is bytes
1260+ assert len (r ) == 7
1261+ assert r == response0 [10 :17 ]
1262+
1263+ r = os_ops .read_binary (filename , 10 , len (response0 ))
1264+ assert type (r ) is bytes
1265+ assert len (r ) == len (response0 ) - 10
1266+ assert r == response0 [10 :]
1267+
1268+ r = os_ops .read_binary (filename , 10 , 2 * len (response0 ))
1269+ assert type (r ) is bytes
1270+ assert len (r ) == len (response0 ) - 10
1271+ assert r == response0 [10 :]
1272+
1273+ r = os_ops .read_binary (filename , len (response0 ) - 1 , 2 * len (response0 ))
1274+ assert type (r ) is bytes
1275+ assert len (r ) == 1
1276+ assert r == response0 [- 1 :]
1277+ assert r [0 ] == response0 [- 1 ]
1278+
1279+ r = os_ops .read_binary (filename , len (response0 ), 1 )
1280+ assert type (r ) is bytes
1281+ assert len (r ) == 0
1282+ assert r == b''
1283+
1284+ r = os_ops .read_binary (filename , len (response0 ) + 1 , 1 )
1285+ assert type (r ) is bytes
1286+ assert len (r ) == 0
1287+ assert r == b''
1288+
12531289 os_ops .remove_file (filename )
12541290 return
12551291
@@ -1278,6 +1314,31 @@ def test_read_binary__spec__negative_offset(
12781314 os_ops .remove_file (filename )
12791315 return
12801316
1317+ def test_read_binary__spec__negative_size (
1318+ self ,
1319+ os_ops_descr : OsOpsDescr ,
1320+ name_with_surprize : tagNameWithSurprize ,
1321+ ):
1322+ """
1323+ Test OsOperations::read_binary with negative size.
1324+ """
1325+ assert type (os_ops_descr ) is OsOpsDescr
1326+ assert isinstance (os_ops_descr .os_ops , OsOperations )
1327+ assert type (name_with_surprize ) is __class__ .tagNameWithSurprize
1328+
1329+ os_ops = os_ops_descr .os_ops
1330+ assert isinstance (os_ops , OsOperations )
1331+
1332+ filename = os_ops .mkstemp (name_with_surprize .value )
1333+
1334+ with pytest .raises (
1335+ ValueError ,
1336+ match = re .escape ("Negative 'size' is not supported." )):
1337+ os_ops .read_binary (filename , 0 , size = - 1 )
1338+
1339+ os_ops .remove_file (filename )
1340+ return
1341+
12811342 def test_get_file_size (
12821343 self ,
12831344 os_ops_descr : OsOpsDescr ,
0 commit comments