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 > --- > 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=jsnow@redhat.com > > -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