[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/10] iotests: use 'with open()' where applicable
From: |
John Snow |
Subject: |
[PATCH 08/10] iotests: use 'with open()' where applicable |
Date: |
Wed, 12 May 2021 17:46:40 -0400 |
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(-)
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'''
--
2.30.2
- Re: [PATCH 03/10] python/machine: use subprocess.run instead of subprocess.Popen, (continued)
- [PATCH 04/10] python/console_socket: Add a pylint ignore, John Snow, 2021/05/12
- [PATCH 07/10] iotests: use subprocess.run where possible, John Snow, 2021/05/12
- [PATCH 06/10] python/machine: disable warning for Popen in _launch(), John Snow, 2021/05/12
- [PATCH 09/10] iotests: silence spurious consider-using-with warnings, John Snow, 2021/05/12
- [PATCH 02/10] python/machine: use subprocess.DEVNULL instead of open(os.path.devnull), John Snow, 2021/05/12
- [PATCH 10/10] iotests: ensure that QemuIoInteractive definitely closes, John Snow, 2021/05/12
- [PATCH 08/10] iotests: use 'with open()' where applicable,
John Snow <=
- Re: [PATCH 00/10] Python: delint iotests, machine.py and console_socket.py, John Snow, 2021/05/17