[Piglit] [PATCH 8/9] framework/exectest.py: use grouping parens instead of \ to break strings

Dylan Baker baker.dylan.c at gmail.com
Wed Apr 9 19:56:38 PDT 2014


On Wednesday, April 09, 2014 09:58:47 PM Ilia Mirkin wrote:
> On Wed, Apr 9, 2014 at 9:27 PM, Dylan Baker <baker.dylan.c at gmail.com> wrote:
> > ---
> > 
> >  framework/exectest.py | 16 ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> > 
> > diff --git a/framework/exectest.py b/framework/exectest.py
> > index 72061e0..76f9be8 100644
> > --- a/framework/exectest.py
> > +++ b/framework/exectest.py
> > 
> > @@ -90,15 +90,15 @@ class Test(object):
> >                  if not isinstance(result, TestResult):
> >                      result = TestResult(result)
> >                      result['result'] = 'warn'
> > 
> > -                    result['note'] = 'Result not returned as an instance
> > ' \ -                                     'of TestResult'
> > +                    result['note'] = ('Result not returned as an instance
> > ' +                                      'of TestResult')
> > 
> >              except:
> >                  result = TestResult()
> >                  result['result'] = 'fail'
> > 
> > -                result['exception'] = str(sys.exc_info()[0]) + \
> > -                    str(sys.exc_info()[1])
> > -                result['traceback'] = \
> > -                    "".join(traceback.format_tb(sys.exc_info()[2]))
> > +                result['exception'] = (str(sys.exc_info()[0]) +
> > +                                       str(sys.exc_info()[1]))
> 
> Alternatively, "{}{}".format(*sys.exc_info()[:2])
> 
> [OK, that didn't turn out as pretty as I had hoped -- "".join wants
> strings, and I guess the way-more-readable "%s%s" % foo syntax is
> going out of style :( ]

what about "".join(str(s) for s in sys.exc_info()[:2])?

I don't know if it's any better than str.format() in this case, I think concat 
is the easiest to read, but there are good reasons to not use string 
concatenation (performance isn't good in many python implementations and even 
in CPython only certain types are fast)

I really don't like the C style string formaters; they're hard to read and 
each format has a couple of deprecated aliases.

> 
> > +                result['traceback'] = "".join(
> > +                    traceback.format_tb(sys.exc_info()[2]))
> > 
> >              log.log(path, result['result'])
> >              log.post_log(log_current, result['result'])
> > 
> > @@ -251,8 +251,8 @@ class Test(object):
> >              # Piglit should not report that test as having
> >              # failed.
> > 
> >              if e.errno == errno.ENOENT:
> > -                out = "PIGLIT: {'result': 'skip'}\n" \
> > -                    + "Test executable not found.\n"
> > +                out = ("PIGLIT: {'result': 'skip'}\n"
> > +                       "Test executable not found.\n")
> > 
> >                  err = ""
> >                  returncode = None
> >              
> >              else:
> > --
> > 1.9.1
> > 
> > _______________________________________________
> > Piglit mailing list
> > Piglit at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/piglit
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140409/a122bd6b/attachment.sig>


More information about the Piglit mailing list