diff mbox series

[08/10] iotests: use 'with open()' where applicable

Message ID 20210512214642.2803189-9-jsnow@redhat.com
State New
Headers show
Series Python: delint iotests, machine.py and console_socket.py | expand

Commit Message

John Snow May 12, 2021, 9:46 p.m. UTC
More pylint 2.8.x warning hushing: use open's context manager where it's
applicable to do so to avoid a warning.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 tests/qemu-iotests/iotests.py | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

Philippe Mathieu-Daudé May 13, 2021, 9:40 a.m. UTC | #1
On 5/12/21 11:46 PM, John Snow wrote:
> More pylint 2.8.x warning hushing: use open's context manager where it's
> applicable to do so to avoid a warning.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  tests/qemu-iotests/iotests.py | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff mbox series

Patch

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 46deb7f4dd4..5d5ec40429b 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -335,13 +335,12 @@  def compare_images(img1, img2, fmt1=imgfmt, fmt2=imgfmt):
 
 def create_image(name, size):
     '''Create a fully-allocated raw image with sector markers'''
-    file = open(name, 'wb')
-    i = 0
-    while i < size:
-        sector = struct.pack('>l504xl', i // 512, i // 512)
-        file.write(sector)
-        i = i + 512
-    file.close()
+    with open(name, 'wb') as outfile:
+        i = 0
+        while i < size:
+            sector = struct.pack('>l504xl', i // 512, i // 512)
+            outfile.write(sector)
+            i = i + 512
 
 def image_size(img):
     '''Return image's virtual size'''