[pypy-dev] utest conversion tool question

Laura Creighton lac at strakt.com
Wed Jun 30 16:43:25 CEST 2004


I am still dizzy and sick, but I am trying to get something done anyhow.  I have
this question.

If you start with

self.assertEquals(f(x) +
                  g(x) == q(x), 'Message to print when the assertion fails')

you would like things to come back as

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.  But this does not work, as the
following demonstrates:

>>> assert 0 + \
...     1 == 7, 'no it doesnt'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AssertionError: no it doesnt
>>> assert (0 +
...     1 == 7, 'no it doesnt')
>>>

The problem is that once you get into 'backslash pasting' mode, it is hard to
know when you should stop.  I was working on the assumption that if we have something
that works like an expression, but doesn't work when you peal off the parens, i.e.
it is multi-line, then you should paste the parens in.  And this is mostly correct.

But there is this problem.

>>> s='''
... aaa
... bbb
... ccc
... '''
>>> s
'\naaa\nbbb\nccc\n'
>>>
>>> assert '''
... aaa
... bbb
... ccc
... ''' != s
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AssertionError
>>>

thus if I get some code:

self.assertNotEquals('''
aaa
bbb
ccc
''', s)

I should not be pasting in the backslashes.

But

>>> parser.expr(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<string>", line 3
    bbb
      ^
SyntaxError: invalid syntax
>>>

.... suggestions on how to recognise triple-quoted strings?

Apologies if I miss something obvious, my brain isn't really good for much yet.

Laura



More information about the Pypy-dev mailing list