[Piglit] [PATCH 4/9] framework/exectest.py: remove deprecated builtin use
Ilia Mirkin
imirkin at alum.mit.edu
Wed Apr 9 18:44:28 PDT 2014
On Wed, Apr 9, 2014 at 9:27 PM, Dylan Baker <baker.dylan.c at gmail.com> wrote:
> Upstream python considers map() and filter() deprecated in favor of
> using comprehensions. These comprehensions are easier to read, and can
> act as both a map and a filter at the same time. In this case we are
> using generator comprehensions, which have an additional advantage of
> lower memory consumption.
> ---
> framework/exectest.py | 30 ++++++++++++++----------------
> 1 file changed, 14 insertions(+), 16 deletions(-)
>
> diff --git a/framework/exectest.py b/framework/exectest.py
> index a670ddd..ae397f0 100644
> --- a/framework/exectest.py
> +++ b/framework/exectest.py
> @@ -295,23 +295,21 @@ class PiglitTest(Test):
>
> def interpret_result(self, out, returncode, results):
> outlines = out.split('\n')
> - outpiglit = map(lambda s: s[7:],
> - filter(lambda s: s.startswith('PIGLIT:'), outlines))
> + outpiglit = (s[7:] for s in outlines if s.startswith('PIGLIT:'))
>
> - if len(outpiglit) > 0:
> - try:
> - for piglit in outpiglit:
> - if piglit.startswith('subtest'):
> - if not 'subtest' in results:
> - results['subtest'] = {}
> - results['subtest'].update(eval(piglit[7:]))
> - else:
> - results.update(eval(piglit))
> - out = '\n'.join(filter(lambda s: not s.startswith('PIGLIT:'),
> - outlines))
> - except:
> - results['result'] = 'fail'
> - results['note'] = 'Failed to parse result string'
> + try:
> + for piglit in outpiglit:
> + if piglit.startswith('subtest'):
> + if not 'subtest' in results:
> + results['subtest'] = {}
> + results['subtest'].update(eval(piglit[7:]))
> + else:
> + results.update(eval(piglit))
> + out = '\n'.join(s for s in outlines if not
> + s.startswith('PIGLIT:'))
IMO it's more readable to break the line like
+ out = '\n'.join(s for s in outlines
+ if not s.startswith('PIGLIT:'))
That way the condition is next to the 'if' (and the not). (I presume
it doesn't fit in 80 chars in the first place? Seems like it ought
to...)
> + except:
> + results['result'] = 'fail'
> + results['note'] = 'Failed to parse result string'
>
> if 'result' not in results:
> results['result'] = 'fail'
> --
> 1.9.1
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
More information about the Piglit
mailing list