From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:50971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gydNY-000495-NA for qemu-devel@nongnu.org; Tue, 26 Feb 2019 09:06:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gydNV-0007mx-Gs for qemu-devel@nongnu.org; Tue, 26 Feb 2019 09:06:39 -0500 References: <1550834773-873512-1-git-send-email-andrey.shinkevich@virtuozzo.com> <20190225202630.GA4925@habkost.net> From: Eric Blake Message-ID: Date: Tue, 26 Feb 2019 08:06:10 -0600 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v2] iotests: handle TypeError for Python3 in test 242 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andrey Shinkevich , Nir Soffer , Eduardo Habkost Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , Denis Lunev , qemu-block , philmd@redhat.com, QEMU Developers , Max Reitz , Cleber Rosa On 2/26/19 4:39 AM, Andrey Shinkevich wrote: >> +++ b/tests/qemu-iotests/242 >> @@ -64,10 +64,12 @@ def write_to_disk(offset, size): >> =C2=A0def toggle_flag(offset): >> =C2=A0 =C2=A0 =C2=A0with open(disk, "r+b") as f: >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0f.seek(offset, 0) >> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 c =3D f.read(1) >> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 toggled =3D chr(ord(c) ^ bitmap_flag_= unknown) >> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 # The casts to bytearray() below are = only necessary >> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 # for Python 2 compatibility >> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 c =3D bytearray(f.read(1))[0] >> >> >> This is simpler and makes the intent of the code more clear: >> >> =C2=A0 =C2=A0 flag, =3D struct.unpack("B", f.read(1)) >> >> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 toggled =3D c ^ bitmap_flag_unknown >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0f.seek(-1, 1) >> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 f.write(toggled) >> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 f.write(bytearray([toggled])) >> >> >> For consistency, we can use struct.pack here: >> >> =C2=A0 =C2=A0 f.write(struct.pack("B", toggled)) >> >> Nir >> >=20 > Thank you all. I am OK with this approach. > Will wait for Eric's response. That looks better. Peter hasn't applied my pull request yet, so you have time to submit a formal v3 (making it easier for me to 'git am' it rather than reconstruct from this email), and then I will update my pull request to use this improved version. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org