[pypy-dev] utest conversion

holger krekel hpk at trillke.net
Tue Jun 15 20:07:00 CEST 2004


[Laura Creighton Tue, Jun 15, 2004 at 07:44:54PM +0200]
> I got the stuff working with compile too!(i.e. don't race out there and
> implement this before I get my checkin).
> 
> Right now the great problem is files that look like this:
> 
> ..........
> ..........
> 	self.assertEquals(x, y)  # check for unmatched ()
> .........
> 
> where the last ')' in the comment is the one that gets split
> and multi-line comments that start self.assertEquals t.ex

i think it makes sense to detect (and possibly preserve) comment-parts before-hand. 

> '''
> Here is something which will confuse things a lot
> 
>      self.assertEquals(x, y) will be converted to assert x == y
> 
> '''

this exact thing should fail the (multiline-) parseability-test IIUC. 

> Also, the compile needs to get a string with the leading indentation
> stripped right off, i.e.
> 
> 	 self.assertEquals(x + f(y, z) +
>                           (z + 1),
>                            42)
> 
> needs to make the strings
> 
> x + f(y, z) + z  + 1
> 
> and 
> 
> 42
> 
> so as not to get a syntax error on the unexpected indentation.

We should be safe with trying-to-compile "(" + part + ")" which basically
lets you ignore indentation. (We only have expressions so adding parenthesis
should be safe). When actually writing out the assert-statement you 
can do something like 

    " ".join(expr.split()) 

to forget about all indentation.  As a bonus it would be nice to 
write out multiple lines if the linewidth gets greater 75 or so. 
Of course parentheses are required around the expression part of
such a multiline assert-statement like 
    
    assert (x + verylongfunctioncall(y, z) + longvariablename  + 1 == 
            some_expected_result) 


cheers and have a good dinner,

    holger



More information about the Pypy-dev mailing list