From 14c16992b563a77330478bcc6fecdb54df4300b5 Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Tue, 23 Jun 2015 20:04:30 +0530 Subject: Add readinto() API readinto() This method is useful when you have to read a large file over multiple read calls. While read() allocates a buffer every time it's invoked, readinto() copies data to an already allocated buffer passed to it. Change-Id: Ic8a3aa0e544e09e05101c983b329c91864832e4a Signed-off-by: Prashanth Pai --- test/unit/gluster/test_gfapi.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/unit') diff --git a/test/unit/gluster/test_gfapi.py b/test/unit/gluster/test_gfapi.py index 5551235..4be2346 100644 --- a/test/unit/gluster/test_gfapi.py +++ b/test/unit/gluster/test_gfapi.py @@ -192,6 +192,17 @@ class TestFile(unittest.TestCase): with patch("gluster.gfapi.File.fgetsize", _mock_fgetsize): self.fd.read(buflen) + def test_readinto(self): + mock_glfs_read = Mock() + mock_glfs_read.return_value = 5 + + with patch("gluster.gfapi.api.glfs_read", mock_glfs_read): + buf = bytearray(10) + ret = self.fd.readinto(buf) + self.assertEqual(ret, 5) + + self.assertRaises(TypeError, self.fd.readinto, str("hello")) + def test_write_success(self): mock_glfs_write = Mock() mock_glfs_write.return_value = 5 -- cgit