[bmap-tools] [PATCH 06/16] test_api_base: use image name in _copy_image

Artem Bityutskiy dedekind1 at gmail.com
Mon Nov 4 03:05:26 EST 2013


From: Artem Bityutskiy <artem.bityutskiy at intel.com>

This is a minor clean-up which changes the '_copy_image()' so that it expects
the image to be a path and does not allow for file-like objects. This is
cleaner than seeking the file-like object in this function, which changes the
object state.

This change is rather mechanical, and this is actually a preparation for the
upcoming changes, where I am going to make '_copy_image()' and some other
function generic, and then use them in a new test which I am going to add.

Change-Id: I81e7e2d15676794f9d5e0e93ce62e0945b95a6d0
Signed-off-by: Artem Bityutskiy <artem.bityutskiy at intel.com>
---
 tests/test_api_base.py | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/tests/test_api_base.py b/tests/test_api_base.py
index a73f19d..0164542 100644
--- a/tests/test_api_base.py
+++ b/tests/test_api_base.py
@@ -177,11 +177,7 @@ def _copy_image(image, f_dest, f_bmap, image_chksum, image_size):
     Copy image 'image' using bmap 'f_bmap' to the destination file 'f_dest'.
     """
 
-    if hasattr(image, "read"):
-        f_image = image
-        image.seek(0)
-    else:
-        f_image = TransRead.TransRead(image)
+    f_image = TransRead.TransRead(image)
 
     f_dest.seek(0)
     if f_bmap:
@@ -197,8 +193,7 @@ def _copy_image(image, f_dest, f_bmap, image_chksum, image_size):
     f_dest.seek(0)
     assert _calculate_chksum(f_dest) == image_chksum
 
-    if not hasattr(image, "read"):
-        f_image.close()
+    f_image.close()
 
 def _do_test(f_image, image_size, delete=True):
     """
@@ -241,7 +236,7 @@ def _do_test(f_image, image_size, delete=True):
     creator = BmapCreate.BmapCreate(f_image.name, f_bmap1.name)
     creator.generate()
 
-    _copy_image(f_image, f_copy, f_bmap1, image_chksum, image_size)
+    _copy_image(f_image.name, f_copy, f_bmap1, image_chksum, image_size)
 
     # Make sure that holes in the copy are identical to holes in the random
     # sparse file.
@@ -253,7 +248,7 @@ def _do_test(f_image, image_size, delete=True):
 
     creator = BmapCreate.BmapCreate(f_image, f_bmap2)
     creator.generate()
-    _copy_image(f_image, f_copy, f_bmap2, image_chksum, image_size)
+    _copy_image(f_image.name, f_copy, f_bmap2, image_chksum, image_size)
     _compare_holes(f_image, f_copy)
 
     # Make sure the bmap files generated at pass 1 and pass 2 are identical
@@ -278,8 +273,8 @@ def _do_test(f_image, image_size, delete=True):
     # Pass 5: copy without bmap and make sure it is identical to the original
     # file.
 
-    _copy_image(f_image, f_copy, None, image_chksum, image_size)
-    _copy_image(f_image, f_copy, None, image_chksum, None)
+    _copy_image(f_image.name, f_copy, None, image_chksum, image_size)
+    _copy_image(f_image.name, f_copy, None, image_chksum, None)
 
     #
     # Pass 6: test compressed files copying without bmap
-- 
1.8.1.4




More information about the Bmap-tools mailing list