Message ID | 20210512214642.2803189-9-jsnow@redhat.com |
---|---|
State | New |
Headers | show |
Series | Python: delint iotests, machine.py and console_socket.py | expand |
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 --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'''
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(-)