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

Dylan Baker baker.dylan.c at gmail.com
Thu Apr 10 13:38:41 PDT 2014


On Wednesday, April 09, 2014 23:01:24 Ilia Mirkin wrote:
> On Wed, Apr 9, 2014 at 10:56 PM, Dylan Baker 
<baker.dylan.c at gmail.com> wrote:
> > 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]))


so what about something like this:
exception = sys.exc_info()
result['exception'] = "{}{}".format(*exception[:2])
result['traceback'] = "".join(traceback.format_tb(exception[2]))

This should make things easier to read and reduces our function calls.

> >> 
> >> 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)
> 
> None of these strike me as particularly better. Just leave it as you
> had it. Forget I ever said anything :)
> 
> > I really don't like the C style string formaters; they're hard to read and
> > each format has a couple of deprecated aliases.
> 
> The nice thing about them is that they're the C-style string formats
> that everyone knows and loves (or hates, but definitely knows).
> Everything that's not that requires thought and guesswork until you
> get really familiar with it.
> 
> >> > +                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 --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140410/f7e1bd4a/attachment-0001.html>
-------------- 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/20140410/f7e1bd4a/attachment-0001.sig>


More information about the Piglit mailing list