qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/8] iotests/257: add Pattern class


From: Max Reitz
Subject: Re: [Qemu-devel] [PATCH 1/8] iotests/257: add Pattern class
Date: Wed, 10 Jul 2019 18:26:14 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0

On 10.07.19 03:05, John Snow wrote:
> Just kidding, this is easier to manage with a full class instead of a
> namedtuple.
> 
> Signed-off-by: John Snow <address@hidden>
> ---
>  tests/qemu-iotests/257 | 58 +++++++++++++++++++++++-------------------
>  1 file changed, 32 insertions(+), 26 deletions(-)
> 
> diff --git a/tests/qemu-iotests/257 b/tests/qemu-iotests/257
> index 75a651c7c3..f576a35a5c 100755
> --- a/tests/qemu-iotests/257
> +++ b/tests/qemu-iotests/257
> @@ -19,7 +19,6 @@
>  #
>  # owner=address@hidden
>  
> -from collections import namedtuple
>  import math
>  import os
>  
> @@ -29,10 +28,18 @@ from iotests import log, qemu_img
>  SIZE = 64 * 1024 * 1024
>  GRANULARITY = 64 * 1024
>  
> -Pattern = namedtuple('Pattern', ['byte', 'offset', 'size'])
> -def mkpattern(byte, offset, size=GRANULARITY):
> -    """Constructor for Pattern() with default size"""
> -    return Pattern(byte, offset, size)
> +
> +class Pattern:
> +    def __init__(self, byte, offset, size=GRANULARITY):
> +        self.byte = byte
> +        self.offset = offset
> +        self.size = size
> +
> +    def bits(self, granularity):
> +        lower = math.floor(self.offset / granularity)
> +        upper = math.floor((self.offset + self.size - 1) / granularity)
> +        return set(range(lower, upper + 1))

By the way, this doesn’t work with Python2 (pre-existing in your other
series).  It complains that these are floats.

Now I don’t know whether you care but there is the fact that the
expressions would be shorter if they were of the form x // y instead of
math.floor(x / y).

Max

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]