[pypy-dev] utest conversion tool question

Armin Rigo arigo at tunes.org
Wed Jun 30 20:35:14 CEST 2004


Hello Laura,

On Wed, Jun 30, 2004 at 04:43:25PM +0200, Laura Creighton wrote:
> assert f(x) +\
>                  g(x) == q(x), 'Message to print when the assertion fails'
> 
> It is the last, optional message which is the sticky part, otherwise you could
> say, just keep the original parentheses.

There is probably always a way to avoid backslashes.  For the above example it
would be:

  assert (f(x) +
                  g(x) == q(x)), 'Message'

Inserting these parenthesis shouldn't be too hard if you decompose the 
arguments anyway.  Also note that the same rule applies to each of the two 
arguments of the assert statement:

   self.assertEquals(f(x) +
                     g(x) == q(x),
                     'Message')

should, intuitively, get translated to...

  assert (f(x) +
                     g(x) == q(x)), (
                     'Message')

I guess once you know the text of each argument to assert, you can check which 
ones contain a '\n' and add parenthesis in this case.  In the above example if 
the second argument starts right after the original ',' then it should be 

  "\n                     'Message'"

i.e. including a '\n', so it gets parenthesis too.


Armin



More information about the Pypy-dev mailing list