[Libguestfs] [PATCH nbdkit 2/2] tests: python: Test new v2 pread API.

Richard W.M. Jones rjones at redhat.com
Mon Nov 25 13:17:47 UTC 2019


---
 tests/test-python-plugin.py | 12 +++---------
 tests/test_python.py        | 18 ++----------------
 2 files changed, 5 insertions(+), 25 deletions(-)

diff --git a/tests/test-python-plugin.py b/tests/test-python-plugin.py
index d7335bd..8e90bc2 100644
--- a/tests/test-python-plugin.py
+++ b/tests/test-python-plugin.py
@@ -95,16 +95,10 @@ def can_cache (h):
     elif cache == "native":
         return nbdkit.CACHE_NATIVE
 
-def pread (h, count, offset, flags):
+def pread (h, buf, offset, flags):
     assert flags == 0
-    pread_result = cfg.get ('pread_result', "bytearray")
-    b = h['disk'][offset:offset+count]
-    if pread_result == "bytearray":
-        return b
-    elif pread_result == "bytes":
-        return bytes (b)
-    elif pread_result == "memoryview":
-        return memoryview (b)
+    end = offset + len(buf)
+    buf[:] = h['disk'][offset:end]
 
 def pwrite (h, buf, offset, flags):
     expect_fua = cfg.get ('pwrite_expect_fua', False)
diff --git a/tests/test_python.py b/tests/test_python.py
index b2c60f0..6b9f297 100755
--- a/tests/test_python.py
+++ b/tests/test_python.py
@@ -155,26 +155,12 @@ class Test (unittest.TestCase):
 
     # Not yet implemented: can_extents.
 
-    def test_pread_bytearray (self):
-        """Test pread returning bytearray."""
+    def test_pread (self):
+        """Test pread."""
         self.connect ({"size": 512})
         buf = self.h.pread (512, 0)
         assert buf == bytearray (512)
 
-    def test_pread_bytes (self):
-        """Test pread returning bytes."""
-        self.connect ({"size": 512,
-                       "pread_result": "bytes"})
-        buf = self.h.pread (512, 0)
-        assert buf == bytearray (512)
-
-    def test_pread_memoryview (self):
-        """Test pread returning memoryview."""
-        self.connect ({"size": 512,
-                       "pread_result": "memoryview"})
-        buf = self.h.pread (512, 0)
-        assert buf == bytearray (512)
-
     # Test pwrite + flags.
     def test_pwrite (self):
         self.connect ({"size": 512})
-- 
2.23.0




More information about the Libguestfs mailing list