Skip to content

Commit

Permalink
add test to check default buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
rmmancom committed Jun 17, 2024
1 parent 14408ba commit 46551c6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Lib/test/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ def testBlksize(self):
blksize = getattr(fst, 'st_blksize', blksize)
self.assertEqual(self.f._blksize, blksize)

def testDefaultBufferSize(self):
# a larger block size can have preference over the default buffer size,
# so we have to verify the block size and skip the test.
blksize = getattr(self.f, '_blksize', 0)

if blksize <= io.DEFAULT_BUFFER_SIZE:
# ensure the default buffer size is used.
self.f.write(bytes([0] * 1e6))
self.f.seek(0)
data = self.peek()
self.assertEquals(len(data), io.DEFAULT_BUFFER_SIZE)
data = self.read1()
self.assertEquals(len(data), io.DEFAULT_BUFFER_SIZE)
else:
self.skipTest("device block size greater than io.DEFAULT_BUFFER_SIZE")

# verify readinto
def testReadintoByteArray(self):
self.f.write(bytes([1, 2, 0, 255]))
Expand Down

0 comments on commit 46551c6

Please sign in to comment.