summaryrefslogtreecommitdiffstats
path: root/test/functional
diff options
context:
space:
mode:
authorPrashanth Pai <ppai@redhat.com>2015-06-23 20:04:30 +0530
committerPrashanth Pai <ppai@redhat.com>2016-02-24 11:16:57 +0530
commit14c16992b563a77330478bcc6fecdb54df4300b5 (patch)
treea21195304749786c8564fb4339ac7c3120fbb9d1 /test/functional
parent6df97fd49fa9be6394bd066c6c64fd7c06959a77 (diff)
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 <ppai@redhat.com>
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/libgfapi-python-tests.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py
index 6840d18..3a0b89e 100644
--- a/test/functional/libgfapi-python-tests.py
+++ b/test/functional/libgfapi-python-tests.py
@@ -502,6 +502,24 @@ class FileOpsTest(unittest.TestCase):
self.vol.symlink(file_name, link_name)
self.assertEqual(self.vol.readlink(link_name), file_name)
+ def test_readinto(self):
+ file_name = uuid4().hex
+ with File(self.vol.open(file_name, os.O_WRONLY | os.O_CREAT)) as f:
+ s = ''.join([str(i) for i in xrange(10)])
+ f.write(s)
+ f.fsync()
+
+ buf = bytearray(1)
+ with File(self.vol.open(file_name, os.O_RDONLY)) as f:
+ for i in xrange(10):
+ # Read one character at a time into buf
+ f.readinto(buf)
+ self.assertEqual(len(buf), 1)
+ self.assertEqual(buf, bytearray(str(i)))
+
+ with File(self.vol.open(file_name, os.O_RDONLY)) as f:
+ self.assertRaises(TypeError, f.readinto, str("buf"))
+
class DirOpsTest(unittest.TestCase):